diff options
author | Jack Sangdahl <[email protected]> | 2024-04-02 23:09:10 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2024-04-02 23:09:10 -0600 |
commit | 6312e34a350ede7a73906792a8ff5d5efcf2f534 (patch) | |
tree | 205ecc2cd419deb394ebd5698720a4b840905810 /pa4_shared_array/array.h | |
parent | 8dbe92136c33a2254b617e6d5273d5499de5ad90 (diff) | |
download | csci3753-6312e34a350ede7a73906792a8ff5d5efcf2f534.tar.gz csci3753-6312e34a350ede7a73906792a8ff5d5efcf2f534.zip |
pa4
Diffstat (limited to 'pa4_shared_array/array.h')
-rw-r--r-- | pa4_shared_array/array.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/pa4_shared_array/array.h b/pa4_shared_array/array.h new file mode 100644 index 0000000..9d67e1e --- /dev/null +++ b/pa4_shared_array/array.h @@ -0,0 +1,48 @@ +// Jack Sangdahl +// CSCI3753 SP24 +// PA4 Shared Array +#include <semaphore.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define ARRAY_SIZE 8 // number of hostnames in data/ is 618 +#define MAX_NAME_LENGTH 16 // longest string length in data/ + +typedef struct { + char **array; + uint8_t top; + sem_t mutex; + sem_t space; + sem_t items; +} array; + +/** + * @brief initialise the array + * @param s + * @return int + */ +int array_init(array *s); + +/** + * @brief place element into array. block when full + * @param s + * @param hostname + * @return int + */ +int array_put(array *s, char *hostname); + +/** + * @brief remove element from the array. block when empty + * @param s + * @param hostname + * @return int + */ +int array_get(array *s, char **hostname); + +/** + * @brief free array's resources + * @param s + */ +void array_free(array *s); |