Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | * File: pripcsem.h |
michael@0 | 8 | * |
michael@0 | 9 | * Description: named semaphores for interprocess |
michael@0 | 10 | * synchronization |
michael@0 | 11 | * |
michael@0 | 12 | * Unrelated processes obtain access to a shared semaphore |
michael@0 | 13 | * by specifying its name. |
michael@0 | 14 | * |
michael@0 | 15 | * Our goal is to support named semaphores on at least |
michael@0 | 16 | * Unix and Win32 platforms. The implementation will use |
michael@0 | 17 | * one of the three native semaphore APIs: POSIX, System V, |
michael@0 | 18 | * and Win32. |
michael@0 | 19 | * |
michael@0 | 20 | * Because POSIX named semaphores have kernel persistence, |
michael@0 | 21 | * we are forced to have a delete function in this API. |
michael@0 | 22 | */ |
michael@0 | 23 | |
michael@0 | 24 | #ifndef pripcsem_h___ |
michael@0 | 25 | #define pripcsem_h___ |
michael@0 | 26 | |
michael@0 | 27 | #include "prtypes.h" |
michael@0 | 28 | #include "prio.h" |
michael@0 | 29 | |
michael@0 | 30 | PR_BEGIN_EXTERN_C |
michael@0 | 31 | |
michael@0 | 32 | /* |
michael@0 | 33 | * PRSem is an opaque structure that represents a named |
michael@0 | 34 | * semaphore. |
michael@0 | 35 | */ |
michael@0 | 36 | typedef struct PRSem PRSem; |
michael@0 | 37 | |
michael@0 | 38 | /* |
michael@0 | 39 | * PR_OpenSemaphore -- |
michael@0 | 40 | * |
michael@0 | 41 | * Create or open a named semaphore with the specified name. |
michael@0 | 42 | * A handle to the semaphore is returned. |
michael@0 | 43 | * |
michael@0 | 44 | * If the named semaphore doesn't exist and the PR_SEM_CREATE |
michael@0 | 45 | * flag is specified, the named semaphore is created. The |
michael@0 | 46 | * created semaphore needs to be removed from the system with |
michael@0 | 47 | * a PR_DeleteSemaphore call. |
michael@0 | 48 | * |
michael@0 | 49 | * If PR_SEM_CREATE is specified, the third argument is the |
michael@0 | 50 | * access permission bits of the new semaphore (same |
michael@0 | 51 | * interpretation as the mode argument to PR_Open) and the |
michael@0 | 52 | * fourth argument is the initial value of the new semaphore. |
michael@0 | 53 | * If PR_SEM_CREATE is not specified, the third and fourth |
michael@0 | 54 | * arguments are ignored. |
michael@0 | 55 | */ |
michael@0 | 56 | |
michael@0 | 57 | #define PR_SEM_CREATE 0x1 /* create if not exist */ |
michael@0 | 58 | #define PR_SEM_EXCL 0x2 /* fail if already exists */ |
michael@0 | 59 | |
michael@0 | 60 | NSPR_API(PRSem *) PR_OpenSemaphore( |
michael@0 | 61 | const char *name, PRIntn flags, PRIntn mode, PRUintn value); |
michael@0 | 62 | |
michael@0 | 63 | /* |
michael@0 | 64 | * PR_WaitSemaphore -- |
michael@0 | 65 | * |
michael@0 | 66 | * If the value of the semaphore is > 0, decrement the value and return. |
michael@0 | 67 | * If the value is 0, sleep until the value becomes > 0, then decrement |
michael@0 | 68 | * the value and return. |
michael@0 | 69 | * |
michael@0 | 70 | * The "test and decrement" operation is performed atomically. |
michael@0 | 71 | */ |
michael@0 | 72 | |
michael@0 | 73 | NSPR_API(PRStatus) PR_WaitSemaphore(PRSem *sem); |
michael@0 | 74 | |
michael@0 | 75 | /* |
michael@0 | 76 | * PR_PostSemaphore -- |
michael@0 | 77 | * |
michael@0 | 78 | * Increment the value of the named semaphore by 1. |
michael@0 | 79 | */ |
michael@0 | 80 | |
michael@0 | 81 | NSPR_API(PRStatus) PR_PostSemaphore(PRSem *sem); |
michael@0 | 82 | |
michael@0 | 83 | /* |
michael@0 | 84 | * PR_CloseSemaphore -- |
michael@0 | 85 | * |
michael@0 | 86 | * Close a named semaphore handle. |
michael@0 | 87 | */ |
michael@0 | 88 | |
michael@0 | 89 | NSPR_API(PRStatus) PR_CloseSemaphore(PRSem *sem); |
michael@0 | 90 | |
michael@0 | 91 | /* |
michael@0 | 92 | * PR_DeleteSemaphore -- |
michael@0 | 93 | * |
michael@0 | 94 | * Remove a named semaphore from the system. |
michael@0 | 95 | */ |
michael@0 | 96 | |
michael@0 | 97 | NSPR_API(PRStatus) PR_DeleteSemaphore(const char *name); |
michael@0 | 98 | |
michael@0 | 99 | PR_END_EXTERN_C |
michael@0 | 100 | |
michael@0 | 101 | #endif /* pripcsem_h___ */ |