The qDecoder Project

qSem.c File Reference

Semaphore Handling API. More…


Functions

int qSemInit (const char *keyfile, int keyid, int nsems, bool autodestroy)
 Under-development.
int qSemGetId (const char *keyfile, int keyid)
 Under-development.
bool qSemEnter (int semid, int semno)
 Under-development.
bool qSemEnterNowait (int semid, int semno)
 Under-development.
bool qSemEnterForce (int semid, int semno, int maxwaitms, bool *forceflag)
 Under-development.
bool qSemLeave (int semid, int semno)
 Under-development.
bool qSemCheck (int semid, int semno)
 Under-development.
bool qSemFree (int semid)
 Under-development.


Detailed Description

Semaphore Handling API.

Note:
   [daemon main]
   #define MAX_SEMAPHORES (2)
 
   // create semaphores
   int semid = qSemInit("/some/file/for/generating/unique/key", 'q', MAX_SEMAPHORES, true);
   if(semid < 0) {
     printf("ERROR: Can't initialize semaphores.n");
     return -1;
   }
   // fork childs
   (... child forking codes ...)
   // at the end of daemon, free semaphores
   if(semid >= 0) qSemFree(semid);
   [forked child]
   // critical section for resource 0
   qSemEnter(0);
   (... guaranteed as atomic procedure ...)
   qSemLeave(0);
   (... some codes ...)
   // critical section for resource 1
   qSemEnter(1);
   (... guaranteed as atomic procedure ...)
   qSemLeave(1);
   [other program which uses resource 1]
   int semid = qSemGetId("/some/file/for/generating/unique/key", 'q');
   if(semid < 0) {
     printf("ERROR: Can't get semaphore id.n");
     return -1;
   }
   // critical section for resource 1
   qSemEnter(1);
   (... guaranteed as atomic procedure ...)
   qSemLeave(1);

Function Documentation

int qSemInit ( const char *  keyfile,
int  keyid,
int  nsems,
bool  autodestroy 
)

Under-development.

Since:
not released yet

int qSemGetId ( const char *  keyfile,
int  keyid 
)

Under-development.

Since:
not released yet

bool qSemEnter ( int  semid,
int  semno 
)

Under-development.

Since:
not released yet

bool qSemEnterNowait ( int  semid,
int  semno 
)

Under-development.

Since:
not released yet

bool qSemEnterForce ( int  semid,
int  semno,
int  maxwaitms,
bool *  forceflag 
)

Under-development.

Since:
not released yet

bool qSemLeave ( int  semid,
int  semno 
)

Under-development.

Since:
not released yet

bool qSemCheck ( int  semid,
int  semno 
)

Under-development.

Since:
not released yet

bool qSemFree ( int  semid  ) 

Under-development.

Since:
not released yet


[Home] [About] [Examples] [Changes] [Download] [SVN Repository] [Install] [Reference]