"Fossies" - the Fresh Open Source Software Archive

Member "bonnie++-1.04/semaphore.h" (3 Jul 2009, 1137 Bytes) of package /linux/privat/bonnie++_1.04.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "semaphore.h" see the Fossies "Dox" file reference documentation.

    1 #ifndef SEMAPHORE_H
    2 #define SEMAPHORE_H
    3 
    4 #include <sys/ipc.h>
    5 #include <sys/sem.h>
    6 
    7 #ifndef SEMUN_IN_SEM_H
    8 union semun
    9 {
   10   int val;                    /* value for SETVAL */
   11   struct semid_ds *buf;       /* buffer for IPC_STAT, IPC_SET */
   12   unsigned short int *array;  /* array for GETALL, SETALL */
   13   struct seminfo *__buf;      /* buffer for IPC_INFO */
   14 };
   15 #endif
   16 
   17 class Semaphore
   18 {
   19 public:
   20 
   21   // numSems is the number of semaphores to be in the set
   22   // semKey is the ID number for the semaphore set
   23   // val is the initial value for the semaphores, no values will be assigned
   24   // if the default (0) is specified.
   25   Semaphore(int semKey, int numSems = 1, int val = 0);
   26 
   27   // clear the semaphores and return an error code.
   28   int clear_sem();
   29 
   30   // create the semaphores
   31   // count is the initial value assigned to each semaphore
   32   int create(int count);
   33 
   34   // get the handle to a semaphore set previously created
   35   int get_semid();
   36 
   37   int decrement_and_wait(int nr_sem);
   38   int get_mutex();
   39   int put_mutex();
   40 
   41 private:
   42   union semun m_arg;
   43   int m_semid;
   44   int m_semflg;
   45   bool m_semopen;
   46   int m_semKey;
   47   int m_numSems;
   48 };
   49 
   50 #endif
   51