1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/include/pripcsem.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * File: pripcsem.h 1.11 + * 1.12 + * Description: named semaphores for interprocess 1.13 + * synchronization 1.14 + * 1.15 + * Unrelated processes obtain access to a shared semaphore 1.16 + * by specifying its name. 1.17 + * 1.18 + * Our goal is to support named semaphores on at least 1.19 + * Unix and Win32 platforms. The implementation will use 1.20 + * one of the three native semaphore APIs: POSIX, System V, 1.21 + * and Win32. 1.22 + * 1.23 + * Because POSIX named semaphores have kernel persistence, 1.24 + * we are forced to have a delete function in this API. 1.25 + */ 1.26 + 1.27 +#ifndef pripcsem_h___ 1.28 +#define pripcsem_h___ 1.29 + 1.30 +#include "prtypes.h" 1.31 +#include "prio.h" 1.32 + 1.33 +PR_BEGIN_EXTERN_C 1.34 + 1.35 +/* 1.36 + * PRSem is an opaque structure that represents a named 1.37 + * semaphore. 1.38 + */ 1.39 +typedef struct PRSem PRSem; 1.40 + 1.41 +/* 1.42 + * PR_OpenSemaphore -- 1.43 + * 1.44 + * Create or open a named semaphore with the specified name. 1.45 + * A handle to the semaphore is returned. 1.46 + * 1.47 + * If the named semaphore doesn't exist and the PR_SEM_CREATE 1.48 + * flag is specified, the named semaphore is created. The 1.49 + * created semaphore needs to be removed from the system with 1.50 + * a PR_DeleteSemaphore call. 1.51 + * 1.52 + * If PR_SEM_CREATE is specified, the third argument is the 1.53 + * access permission bits of the new semaphore (same 1.54 + * interpretation as the mode argument to PR_Open) and the 1.55 + * fourth argument is the initial value of the new semaphore. 1.56 + * If PR_SEM_CREATE is not specified, the third and fourth 1.57 + * arguments are ignored. 1.58 + */ 1.59 + 1.60 +#define PR_SEM_CREATE 0x1 /* create if not exist */ 1.61 +#define PR_SEM_EXCL 0x2 /* fail if already exists */ 1.62 + 1.63 +NSPR_API(PRSem *) PR_OpenSemaphore( 1.64 + const char *name, PRIntn flags, PRIntn mode, PRUintn value); 1.65 + 1.66 +/* 1.67 + * PR_WaitSemaphore -- 1.68 + * 1.69 + * If the value of the semaphore is > 0, decrement the value and return. 1.70 + * If the value is 0, sleep until the value becomes > 0, then decrement 1.71 + * the value and return. 1.72 + * 1.73 + * The "test and decrement" operation is performed atomically. 1.74 + */ 1.75 + 1.76 +NSPR_API(PRStatus) PR_WaitSemaphore(PRSem *sem); 1.77 + 1.78 +/* 1.79 + * PR_PostSemaphore -- 1.80 + * 1.81 + * Increment the value of the named semaphore by 1. 1.82 + */ 1.83 + 1.84 +NSPR_API(PRStatus) PR_PostSemaphore(PRSem *sem); 1.85 + 1.86 +/* 1.87 + * PR_CloseSemaphore -- 1.88 + * 1.89 + * Close a named semaphore handle. 1.90 + */ 1.91 + 1.92 +NSPR_API(PRStatus) PR_CloseSemaphore(PRSem *sem); 1.93 + 1.94 +/* 1.95 + * PR_DeleteSemaphore -- 1.96 + * 1.97 + * Remove a named semaphore from the system. 1.98 + */ 1.99 + 1.100 +NSPR_API(PRStatus) PR_DeleteSemaphore(const char *name); 1.101 + 1.102 +PR_END_EXTERN_C 1.103 + 1.104 +#endif /* pripcsem_h___ */