#include <semaphore.h> #include <qlg.h> sem_t * QlgSem_open(const Qlg_Path_Name_T *name, int oflag, ...);
The QlgSem_open() function, like the sem_open() function, opens a named semaphore and returns a semaphore pointer that may be used on subsequent calls to sem_post(), sem_post_np(), sem_wait(), sem_wait_np(), sem_trywait(), sem_getvalue(), and sem_close(). The QlgSem_open() function takes a pointer to a Qlg_Path_Name_T structure, while the sem_open() function takes a pointer to a character string that is in the CCSID of the job.
Limited information on the name parameter is provided in this API. For additional information on the name parameter and a discussion of other parameters, authorities required, return values, and related information, see sem_open()--Open Named Semaphore.
If QlgSem_open() is not successful, errno usually indicates the following error or one of the errors identified in sem_open()--Open Named Semaphore.
Note: All of the related information for sem_open() applies to QlgSem_open(). See Related Information in sem_open().
See Code disclaimer information for information pertaining to code examples.
The following example opens the named semaphore "/mysemaphore" and creates the semaphore with an initial value of 10 if it does not already exist. If the semaphore is created, the permissions are set such that only the current user has access to the semaphore.
#include <semaphore.h> #include <qlg.h> main() { sem_t * my_semaphore; int rc; #define mypath "/mysemaphore" const char US_const[3]= "US"; const char Language_const[4]="ENU"; const char Path_Name_Del_const[2]= "/"; typedef struct pnstruct { Qlg_Path_Name_T qlg_struct; char[100] pn; /* This size must be >= the path */ /* name length or be a pointer */ /* to the path name. */ }; struct pnstruct path; /***************************************************************/ /* Initialize Qlg_Path_Name_T parameters */ /***************************************************************/ memset((void*)path name, 0x00, sizeof(struct pnstruct)); path.qlg_struct.CCSID = 37; memcpy(path.qlg_struct.Country_ID,US_const,2); memcpy(path.qlg_struct.Language_ID,Language_const,3); path.qlg_struct.Path_Type = QLG_CHAR_SINGLE; path.qlg_struct.Path_Length = sizeof(mypath)-1; memcpy(path.qlg_struct.Path_Name_Delimiter,Path_Name_Del_const,1); memcpy(path.pn,mypath,sizeof(mypath)); my_semaphore = QlgSem_open((Qlg_Path_Name_T *)path name, O_CREAT, S_IRUSR | S_IWUSR, 10); }
Top | UNIX-Type APIs | APIs by category |