Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Examples  

my_sem.h

Go to the documentation of this file.
00001 /*! \file my_sem.h
00002     Header file for sem.c.
00003  */
00004 
00005 
00006 #ifdef __cplusplus
00007 extern "C" {
00008 #endif
00009 
00010 #ifndef SEMAPHORES_HD
00011 
00012   #include <sys/types.h>
00013   #include <sys/ipc.h>
00014   #include <sys/sem.h>
00015 
00016   /* =========================================================================== */
00017   /* WARNING                                                                     */
00018   /*                                                                             */
00019   /* Under new version of Linux, the union 'semun' is NOT defined by default.    */
00020   /* See the file '/usr/include/bits/sem.h' for details: if the macro            */
00021   /* _SEM_SEMUN_UNDEFINED is defined, that you must define 'semun' yourself.     */
00022   /*                                                                             */
00023   /* Under Solaris, you must define the union 'semun'. Please look at the man    */
00024   /* page for semctl().                                                          */
00025   /* =========================================================================== */
00026 
00027   #ifdef LINUX
00028     #ifdef _SEM_SEMUN_UNDEFINED
00029       union semun
00030       {
00031         int val;                          
00032         struct semid_ds *buf;             
00033         unsigned short int *array;     
00034         struct seminfo *__buf;    
00035       };
00036     #endif
00037   #endif
00038 
00039   #ifdef SUN
00040     union semun
00041     {
00042       int             val;
00043       struct semid_ds *buf;
00044       ushort_t        *array;
00045     };
00046   #endif 
00047 
00048 
00049   /*! \brief This macro represents the default semaphore's premission (applied at creation time). This means that we grant
00050              all access rights (Read/Write/Execute) to the process' user. In binary, 0x1C0, is 111 000 000.
00051    */
00052   #define SEM_PERMISSION 0x000001C0
00053 
00054   /* ========================================================= */
00055   /* Return value for create_semaphore_set()                   */
00056   /* ========================================================= */
00057 
00058   /*! \brief Return value for the function create_semaphore_set(). The function was successful. */
00059   #define CREATE_SEMAPHORE_OK              0
00060 
00061   /*! \brief Return value for the function create_semaphore_set(). An error occured while creating the set of semaphores. */
00062   #define CREATE_SEMAPHORE_CREATE_ERROR   -1
00063 
00064   /*! \brief Return value for the function create_semaphore_set().  An error occured while setting the semaphores' values. */
00065   #define CREATE_SEMAPHORE_SET_VAL_ERROR  -2
00066 
00067   /* ========================================================= */
00068   /* return value for get_semaphore_set()                      */
00069   /* ========================================================= */
00070 
00071   /*! \brief Return value for the function get_semaphore_set(). The function was successful. */
00072   #define GET_SEM_OK                      0
00073 
00074   /*! \brief Return value for the function get_semaphore_set(). The process already got the set of semaphores. */
00075   #define GET_SEM_ALREADY_GET             -1
00076 
00077   /*! \brief Return value for the function get_semaphore_set(). An error occured while getting the set of semaphores. */
00078   #define GET_SEM_ERROR                   -2                   
00079 
00080   /* ========================================================= */
00081   /* Return value for set_semaphore_values()                   */
00082   /* ========================================================= */
00083 
00084   /*! \brief Return value for the function set_semaphore_values(). The function was successful. */
00085   #define SET_SEM_VALUES_OK                0
00086 
00087   /*! \brief Return value for the function set_semaphore_values(). The semaphore set was not created (or get). */
00088   #define SET_SEM_VALUES_SEM_NOT_CREATED  -1
00089 
00090   /*! \brief Return value for the function set_semaphore_values(). An error occured while setting the semaphores' values. */
00091   #define SET_SEM_VALUES_SET_ERROR        -2
00092 
00093   /* ========================================================= */
00094   /* API's description                                         */
00095   /* ========================================================= */
00096 
00097   void change_sem_access_permission(int new_permission);
00098   int create_semaphore_set (key_t ipc_key, int number_of_sem);
00099   int set_semaphore_values (int *values);
00100   int set_semaphore_value (int value, int sem_number);
00101   int take_sem (int sem_idx);
00102   int release_sem (int sem_idx);
00103   int destroy_semaphore_set();
00104   int get_semaphore_set();
00105 
00106 #endif
00107 
00108 #ifdef __cplusplus
00109 }
00110 #endif
00111 

Generated on Thu Apr 3 16:23:43 2003 for Common_C_libraries by doxygen1.3-rc1