Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

shm_locking.c

Go to the documentation of this file.
00001 
00008 /* {{{ Initial headers */
00009 /*
00010  * $LastChangedDate: 2003-11-27 01:55:17 +0100 (Thu, 27 Nov 2003) $
00011  * $LastChangedRevision: 5 $
00012  * $LastChangedBy: ckruse $
00013  *
00014  */
00015 /* }}} */
00016 
00017 /* {{{ Includes */
00018 #include "config.h"
00019 #include "defines.h"
00020 
00021 #ifdef CF_SHARED_MEM
00022 
00023 #include <sys/types.h>
00024 
00025 #include <sys/ipc.h>
00026 #include <sys/shm.h>
00027 #include <sys/sem.h>
00028 
00029 #include <unistd.h>
00030 
00031 #include "semaphores.h"
00032 #include "shm_locking.h"
00033 /* }}} */
00034 
00041 int shm_lock_exclusive(int semid) {
00042   /* decrease writer */
00043   if(CF_SEM_UNLOCK(semid,CF_WRITER_SEM) == -1) return -1;
00044 
00045   /* wait until reader number is 0 */
00046   if(CF_SEM_WAITZERO(semid,CF_READER_SEM) == -1) {
00047     CF_SEM_LOCK(semid,CF_WRITER_SEM);
00048     return -1;
00049   }
00050 
00051   /* lock semaphore set */
00052   if(CF_SEM_LOCK(semid,CF_LOCK_SEM) == -1) {
00053     CF_SEM_LOCK(semid,CF_WRITER_SEM);
00054     return -1;
00055   }
00056 
00057   return 0;
00058 }
00059 
00063 int shm_unlock_exclusive(int semid) {
00064   if(CF_SEM_UNLOCK(semid,0) == -1) return -1;
00065 
00066   return CF_SEM_LOCK(semid,2);
00067 }
00068 
00075 int shm_lock_shared(int semid) {
00076   if(CF_SEM_WAITZERO(semid,CF_WRITER_SEM) == -1) return -1;
00077 
00078   return CF_SEM_UNLOCK(semid,CF_READER_SEM);
00079 }
00080 
00084 int shm_unlock_shared(int semid) {
00085   return CF_SEM_LOCK(semid,CF_READER_SEM);
00086 }
00087 
00088 #endif
00089 
00090 /* eof */

Generated on Sun Apr 25 16:37:39 2004 for Classic Forum by doxygen 1.3.5