DosOpenMuxWaitSem

From EDM2
Jump to: navigation, search

DosOpenMuxWaitSem gains access to a shared MuxWait semaphore.

Syntax

rc = DosOpenMuxWaitSem( pszSemaphoreName,
                        phmuxSemaphore );

Parameters

PSZ pszSemaphoreName (input)
This is a pointer to NULL terminated string containing the name of the shared MuxWait semaphore to access. If this value is NULL then the semaphore to access is specified in phmuxSemaphore.
PHMUX phmuxSemaphore (input/output)
For input, this value is a pointer to the MuxWait semaphore handle that should be openned if pszSemaphoreName is NULL. If :pszSemaphoreName is not NULL then this value must be NULL on input. For output, this is a pointer to the MuxWait semaphore handle (HMUX) to the openned semaphore.

Returns

APIRET rc

The following values can be returned:

0 NO_ERROR Semaphore

opened successfully

6 ERROR_INVALID_HANDLE Error, The value in phmuxSemaphore does not point to a valid

semaphore

8 ERROR_NOT_ENOUGH_MEMORY Error, The system memory limit has been exceeded
87 ERROR_INVALID_PARAMETER Error, One or more parameters is not recognized, See parameters above,

Both pszSemaphoreName and phmuxSemaphore may be NULL

105 ERROR_SEM_OWNER_DIED Error, The owner of the semaphore has died without freeing the

semaphore

123 ERROR_INVALID_NAME Error, The name pointed to by pszSemaphoreName has been rejected

by the file system

187 ERROR_SEM_NOT_FOUND Error, There is no semaphore with the name in

pszSemaphoreName

291 ERROR_TOO_MANY_OPENS Error, The usage count for the semaphore in question has exceeded the

system limit of 65535

Gotchas

The process that created the MuxWait semaphore does not need to call this. The process wishing to use this function must first have gained access to all semaphores in the muxwait list of the MuxWait semaphore to which access is intended or ERROR_INVALID_HANDLE will be returned.

Sample Code

#define INCL_DOSSEMAPHORES
#include <os2.h>
#include <string.h>

int main(){
  UCHAR  SemName[15];
  PHMUX  phmuxMySemaphore = NULL; /* pointer to semaphore handle */
  APIRET rc;

  /* a shared MuxWait semaphore is successfully created in another process */
  /* its name happens to be \SEM32\MySem */

  strcpy(SemName,"\\SEM32\\MySem");

  rc = DosOpenMuxWaitSem(SemName, phmuxMySemaphore);
  if (rc != 0) {
     /* We got an error to take care of. */
  }
}

See Also