diff --git a/threads/collatz.c b/process_chp3/collatz.c similarity index 100% rename from threads/collatz.c rename to process_chp3/collatz.c diff --git a/threads/collatz_shm.c b/process_chp3/collatz_shm.c similarity index 100% rename from threads/collatz_shm.c rename to process_chp3/collatz_shm.c diff --git a/threads/collatz_shm2.c b/process_chp3/collatz_shm2.c similarity index 100% rename from threads/collatz_shm2.c rename to process_chp3/collatz_shm2.c diff --git a/threads/cons.c b/process_chp3/cons.c similarity index 100% rename from threads/cons.c rename to process_chp3/cons.c diff --git a/threads/ex1.c b/process_chp3/ex1.c similarity index 100% rename from threads/ex1.c rename to process_chp3/ex1.c diff --git a/threads/ex12.c b/process_chp3/ex12.c similarity index 100% rename from threads/ex12.c rename to process_chp3/ex12.c diff --git a/threads/ex13.c b/process_chp3/ex13.c similarity index 100% rename from threads/ex13.c rename to process_chp3/ex13.c diff --git a/threads/ex14.c b/process_chp3/ex14.c similarity index 100% rename from threads/ex14.c rename to process_chp3/ex14.c diff --git a/threads/ex17.c b/process_chp3/ex17.c similarity index 100% rename from threads/ex17.c rename to process_chp3/ex17.c diff --git a/threads/ex19.c b/process_chp3/ex19.c similarity index 100% rename from threads/ex19.c rename to process_chp3/ex19.c diff --git a/threads/pid_manager.c b/process_chp3/pid_manager.c similarity index 100% rename from threads/pid_manager.c rename to process_chp3/pid_manager.c diff --git a/threads/pid_manager.h b/process_chp3/pid_manager.h similarity index 100% rename from threads/pid_manager.h rename to process_chp3/pid_manager.h diff --git a/threads/prod.c b/process_chp3/prod.c similarity index 100% rename from threads/prod.c rename to process_chp3/prod.c diff --git a/threads/bitmap.c b/threads/bitmap.c deleted file mode 100644 index c738724..0000000 --- a/threads/bitmap.c +++ /dev/null @@ -1,85 +0,0 @@ -#include "bitmap.h" -#include -#include - -#ifdef bitmap_64 -#define bitmap_type unsigned long long int -#define bitmap_shift 6 -#define bitmap_mask 63 -#define bitmap_wordlength 64 -#define bitmap_fmt "%016llx" -#else // assumed to be 32 bits -#define bitmap_type unsigned int -#define bitmap_shift 5 -#define bitmap_mask 31 -#define bitmap_wordlength 32 -#define bitmap_fmt "%08x" -#endif - -// get the types right -#define bitmap_one (bitmap_type)1 - -// we expect 0 <= n and n < b->bits, but it is not verified - -// arch a 8 bit -// bitmap shift 3 -// wordlength 8 - -// n = 10 -> 00001010 -// 00000001 -> word = 1 -// -// n = 12 -> 00001100 -// mask = 7 -> 00000111 -// 00000100 = 4 -// 00000001 -> word = 1 -// -// n = 32 -> 00100000 -// mask = 7 -> 00000111 -// 00000000 -// 00000100 -> word = 4 -// -// n = 127 -> 01111111 -// mask = 7 -> 00000111 -// position = 7 -> 00000111 -// - -void bitmap_set(bitmap *b, int n) { - int word = n >> bitmap_shift; // n / bitmap_wordlength - int position = n & bitmap_mask; // n % bitmap_wordlength - b->array[word] |= bitmap_one << position; -} - -void bitmap_clear(bitmap *b, int n) { - int word = n >> bitmap_shift; // n / bitmap_wordlength - int position = n & bitmap_mask; // n % bitmap_wordlength - b->array[word] &= ~(bitmap_one << position); -} - -int bitmap_read(bitmap *b, int n) { - int word = n >> bitmap_shift; // n / bitmap_wordlength - int position = n & bitmap_mask; // n % bitmap_wordlength - return (b->array[word] >> position) & 1; -} - -bitmap *bitmap_allocate(int bits) { - // error-checking should be better :-) - bitmap *b = malloc(sizeof(bitmap)); - b->bits = bits; - b->words = (bits + bitmap_wordlength - 1) / bitmap_wordlength; - // divide, but round up for the ceiling - b->array = calloc(b->words, sizeof(bitmap_type)); - return b; -} - -void bitmap_deallocate(bitmap *b) { - // error-checking should be better :-) - free(b->array); - free(b); -} - -void bitmap_print(bitmap *b) { - for (int i = 0; i < b->words; i++) { - printf(" " bitmap_fmt, b->array[i]); - } - printf("\n"); -} diff --git a/threads/bitmap.h b/threads/bitmap.h deleted file mode 100644 index 7b4d45d..0000000 --- a/threads/bitmap.h +++ /dev/null @@ -1,22 +0,0 @@ -// use dynamic allocation with these functions -// compile with -Dbitmap_64 to force 64-bit words -// compile with -O [dash capital o] for more efficient machine code - -#ifdef bitmap_64 -#define bitmap_type unsigned long long int -#else // assumed to be 32 bits -#define bitmap_type unsigned int -#endif - -typedef struct { - int bits; // number of bits in the array - int words; // number of words in the array - bitmap_type *array; -} bitmap; - -void bitmap_set(bitmap *b, int n); // n is a bit index -void bitmap_clear(bitmap *b, int n); -int bitmap_read(bitmap *b, int n); -bitmap *bitmap_allocate(int bits); -void bitmap_deallocate(bitmap *b); -void bitmap_print(bitmap *b); diff --git a/threads/test.c b/threads/test.c deleted file mode 100644 index 8ec4683..0000000 --- a/threads/test.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main(void) { - int n; - printf("%d\n", n); - return 0; -} diff --git a/threads/ex417.c b/threads_chp4/ex417.c similarity index 100% rename from threads/ex417.c rename to threads_chp4/ex417.c diff --git a/threads/ex421.c b/threads_chp4/ex421.c similarity index 100% rename from threads/ex421.c rename to threads_chp4/ex421.c diff --git a/threads/ex424.c b/threads_chp4/ex424.c similarity index 100% rename from threads/ex424.c rename to threads_chp4/ex424.c diff --git a/threads/ex426.c b/threads_chp4/ex426.c similarity index 100% rename from threads/ex426.c rename to threads_chp4/ex426.c diff --git a/threads/pid_manager_thread_chp4.c b/threads_chp4/pid_manager.c similarity index 100% rename from threads/pid_manager_thread_chp4.c rename to threads_chp4/pid_manager.c diff --git a/threads_chp4/pid_manager.h b/threads_chp4/pid_manager.h new file mode 100644 index 0000000..e116507 --- /dev/null +++ b/threads_chp4/pid_manager.h @@ -0,0 +1,16 @@ +#if !defined(__PID_MANGER_H__) +#define __PID_MANGER_H__ +#define _GNU_SOURCE + +// Crea e inizializza una struttura per rappresentare i pid; +// restituisce -1 in caso di insuccesso e 1 in caso di successo. +int allocate_map(void); + +// Alloca e restituisce un pid, restituisce -1 se non รจ possibile +// assegnare un PID (tutti i pid sono in uso). +int allocate_pid(void); + +// Rilascia un pid +void release_pid(int pid); + +#endif diff --git a/threads/project2.c b/threads_chp4/project2.c similarity index 100% rename from threads/project2.c rename to threads_chp4/project2.c