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