X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=listati%2FMutex.c;h=2855c75989ea526e1cb3c0c0d7f1f666d7f92023;hp=3d0c4c0f709f1461f7cb04879993fd813b40c074;hb=d47f15496fa85c8ec22edcde608f2665ec5b95ae;hpb=b324b7a09e071b2f84a1849d109d4d14f27f44cd diff --git a/listati/Mutex.c b/listati/Mutex.c index 3d0c4c0..2855c75 100644 --- a/listati/Mutex.c +++ b/listati/Mutex.c @@ -1,13 +1,13 @@ /* Function MutexCreate: create a mutex/semaphore */ int MutexCreate(key_t ipc_key) { - const union semun semunion={1}; /* semaphore union structure */ + const union semun semunion={1}; /* semaphore union structure */ int sem_id, ret; - sem_id = semget(ipc_key, 1, IPC_CREAT|0666); /* get semaphore ID */ - if (sem_id == -1) { /* if error return code */ + sem_id = semget(ipc_key, 1, IPC_CREAT|0666); /* get semaphore ID */ + if (sem_id == -1) { /* if error return code */ return sem_id; } - ret = semctl(sem_id, 0, SETVAL, semunion); /* init semaphore */ + ret = semctl(sem_id, 0, SETVAL, semunion); /* init semaphore */ if (ret == -1) { return ret; } @@ -24,14 +24,14 @@ int MutexRead(int sem_id) return semctl(sem_id, 0, GETVAL); } /* Define sembuf structures to lock and unlock the semaphore */ -struct sembuf sem_lock={ /* to lock semaphore */ - 0, /* semaphore number (only one so 0) */ - -1, /* operation (-1 to use resource) */ - SEM_UNDO}; /* flag (set for undo at exit) */ -struct sembuf sem_ulock={ /* to unlock semaphore */ - 0, /* semaphore number (only one so 0) */ - 1, /* operation (1 to release resource) */ - SEM_UNDO}; /* flag (in this case 0) */ +struct sembuf sem_lock={ /* to lock semaphore */ + 0, /* semaphore number (only one so 0) */ + -1, /* operation (-1 to use resource) */ + SEM_UNDO}; /* flag (set for undo at exit) */ +struct sembuf sem_ulock={ /* to unlock semaphore */ + 0, /* semaphore number (only one so 0) */ + 1, /* operation (1 to release resource) */ + SEM_UNDO}; /* flag (in this case 0) */ /* Function MutexLock: to lock a mutex/semaphore */ int MutexLock(int sem_id) {