From cd74fd521c3e0cc80cd4640d5de059ba14b9c563 Mon Sep 17 00:00:00 2001 From: Aldegheri Alessandro Date: Wed, 29 Mar 2023 17:27:38 +0200 Subject: [PATCH] Pseudocode for semctl, semget and semop functions --- mentos/src/ipc/sem.c | 76 +++++++++++++++++++++++++++++++++++++-- programs/tests/t_semget.c | 4 +-- 2 files changed, 75 insertions(+), 5 deletions(-) diff --git a/mentos/src/ipc/sem.c b/mentos/src/ipc/sem.c index 6f4ff9a..1c1c547 100644 --- a/mentos/src/ipc/sem.c +++ b/mentos/src/ipc/sem.c @@ -17,20 +17,90 @@ //test long sys_semget(key_t key, int nsems, int semflg) { - printf("qui"); + /*PSEUDOCODE (todo)*/ + + + /* + Check if num_sems is a valid value + */ + /* .... */ + + + /* + Compute the IPC id using key. (Hashing Algorithm?) + */ + /* .... */ + + + /* + Check if a semaphore set with the ID already exists (and then check for IPC_EXCL flag) + */ + /* .... */ + + /* + If the semaphore does not exist, create a new semaphore set with the specified number of sems + (allocation, initialization...) + */ + /* .... */ + + /* + Set the semaphore set permissions (default 0666) + */ + /* .... */ + + + /* + Return the new semaphore set ID + */ + /* .... */ + + + + + + //printf("qui"); test //TODO("Not implemented"); return 0; } long sys_semop(int semid, struct sembuf *sops, unsigned nsops) { - TODO("Not implemented"); + /* + Check if semid is a valid semaphore set identifier + */ + /* .... */ + + + /* + Handle the sembuf structure and perform the operation (spinlocks?) + */ + /* .... */ + + /* + Update the semaphores values + */ + /* .... */ + + + //TODO("Not implemented"); return 0; } long sys_semctl(int semid, int semnum, int cmd, unsigned long arg) { - TODO("Not implemented"); + + /* + Check if semid is a valid semaphore identifier + */ + /* .... */ + + /* + Check the cmd parameter (GETVAL, SETVAL...) and perform the operation + */ + /* .... */ + + + //TODO("Not implemented"); return 0; } diff --git a/programs/tests/t_semget.c b/programs/tests/t_semget.c index 00f7899..dab2594 100644 --- a/programs/tests/t_semget.c +++ b/programs/tests/t_semget.c @@ -1,8 +1,8 @@ -//testtt +//test #include int main() { - long i = semget(0,0,0); + long i = semget(0,0,0); //checking if the syscalls are already linked return 0; }