Querying an Event Semaphore

DosQueryEventSem returns the current post count of a semaphore. The post count is the number of times that the semaphore has been posted (with DosPostEventSem) since the last time the semaphore was reset. A count of 0 indicates that the semaphore is in the reset state; therefore, OS/2 will block any threads that call DosWaitEventSem to wait on the semaphore.

Any thread in the process that created an event semaphore can obtain the post count for the semaphore by calling DosQueryEventSem. Threads in other processes can also call DosQueryEventSem, but they must first gain access to the semaphore by calling DosOpenEventSem.

The following code fragment retrieves the post count for an event semaphore. Assume that the handle of the semaphore has been placed into HEV already.

    #define INCL_DOSSEMAPHORES   /* Semaphore values */
    #include <os2.h>
    #include <stdio.h>

    HEV     hev;       /* Event semaphore handle                          */
    ULONG   ulPostCt;  /* Current post count for the semaphore (returned) */
    APIRET  ulrc;      /* Return code                                     */

    ulrc = DosQueryEventSem(hev,
                            &ulPostCt);

    if (ulrc != 0) {
        printf("DosQueryEventSem error: return code = %ld",
               ulrc);
        return;
    }

If the specified event semaphore does not exist, ERROR_INVALID_HANDLE is returned.


[Back: Waiting for an Event Semaphore]
[Next: Using Mutex Semaphores]