andre@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: /* andre@0: * File: pripcsem.h andre@0: * andre@0: * Description: named semaphores for interprocess andre@0: * synchronization andre@0: * andre@0: * Unrelated processes obtain access to a shared semaphore andre@0: * by specifying its name. andre@0: * andre@0: * Our goal is to support named semaphores on at least andre@0: * Unix and Win32 platforms. The implementation will use andre@0: * one of the three native semaphore APIs: POSIX, System V, andre@0: * and Win32. andre@0: * andre@0: * Because POSIX named semaphores have kernel persistence, andre@0: * we are forced to have a delete function in this API. andre@0: */ andre@0: andre@0: #ifndef pripcsem_h___ andre@0: #define pripcsem_h___ andre@0: andre@0: #include "prtypes.h" andre@0: #include "prio.h" andre@0: andre@0: PR_BEGIN_EXTERN_C andre@0: andre@0: /* andre@0: * PRSem is an opaque structure that represents a named andre@0: * semaphore. andre@0: */ andre@0: typedef struct PRSem PRSem; andre@0: andre@0: /* andre@0: * PR_OpenSemaphore -- andre@0: * andre@0: * Create or open a named semaphore with the specified name. andre@0: * A handle to the semaphore is returned. andre@0: * andre@0: * If the named semaphore doesn't exist and the PR_SEM_CREATE andre@0: * flag is specified, the named semaphore is created. The andre@0: * created semaphore needs to be removed from the system with andre@0: * a PR_DeleteSemaphore call. andre@0: * andre@0: * If PR_SEM_CREATE is specified, the third argument is the andre@0: * access permission bits of the new semaphore (same andre@0: * interpretation as the mode argument to PR_Open) and the andre@0: * fourth argument is the initial value of the new semaphore. andre@0: * If PR_SEM_CREATE is not specified, the third and fourth andre@0: * arguments are ignored. andre@0: */ andre@0: andre@0: #define PR_SEM_CREATE 0x1 /* create if not exist */ andre@0: #define PR_SEM_EXCL 0x2 /* fail if already exists */ andre@0: andre@0: NSPR_API(PRSem *) PR_OpenSemaphore( andre@0: const char *name, PRIntn flags, PRIntn mode, PRUintn value); andre@0: andre@0: /* andre@0: * PR_WaitSemaphore -- andre@0: * andre@0: * If the value of the semaphore is > 0, decrement the value and return. andre@0: * If the value is 0, sleep until the value becomes > 0, then decrement andre@0: * the value and return. andre@0: * andre@0: * The "test and decrement" operation is performed atomically. andre@0: */ andre@0: andre@0: NSPR_API(PRStatus) PR_WaitSemaphore(PRSem *sem); andre@0: andre@0: /* andre@0: * PR_PostSemaphore -- andre@0: * andre@0: * Increment the value of the named semaphore by 1. andre@0: */ andre@0: andre@0: NSPR_API(PRStatus) PR_PostSemaphore(PRSem *sem); andre@0: andre@0: /* andre@0: * PR_CloseSemaphore -- andre@0: * andre@0: * Close a named semaphore handle. andre@0: */ andre@0: andre@0: NSPR_API(PRStatus) PR_CloseSemaphore(PRSem *sem); andre@0: andre@0: /* andre@0: * PR_DeleteSemaphore -- andre@0: * andre@0: * Remove a named semaphore from the system. andre@0: */ andre@0: andre@0: NSPR_API(PRStatus) PR_DeleteSemaphore(const char *name); andre@0: andre@0: PR_END_EXTERN_C andre@0: andre@0: #endif /* pripcsem_h___ */