-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.h
More file actions
32 lines (22 loc) · 999 Bytes
/
array.h
File metadata and controls
32 lines (22 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef ARRAY_H
#define ARRAY_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <semaphore.h>
#define ARRAY_SIZE 8 // how many hostnames the queu can hold
#define MAX_NAME_LENGTH 24 // largest length of the hostname you can store
typedef struct {
char buffer[ARRAY_SIZE][MAX_NAME_LENGTH]; // storage array for integers
int head; // next index to read
int tail; // next index ro write
pthread_mutex_t mutex; // mutex for the critical sections
sem_t sem_slots; // prdocuer wait, spaces avail
sem_t sem_items; // consumer wait, items avail
} array;
int array_init(array *s); // initialize the array
int array_put (array *s, char *hostname); // place element into the array, block when full
int array_get (array *s, char **hostname); // remove element from the array, block when empty
void array_free(array *s); // free the array's resources
#endif