1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* 3 * The contents of this file are subject to the Mozilla Public 4 * License Version 1.1 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of 6 * the License at http://www.mozilla.org/MPL/ 7 * 8 * Software distributed under the License is distributed on an "AS 9 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 10 * implied. See the License for the specific language governing 11 * rights and limitations under the License. 12 * 13 * The Original Code is the Netscape Portable Runtime (NSPR). 14 * 15 * The Initial Developer of the Original Code is Netscape 16 * Communications Corporation. Portions created by Netscape are 17 * Copyright (C) 1999-2000 Netscape Communications Corporation. All 18 * Rights Reserved. 19 * 20 * Contributor(s): 21 * 22 * Alternatively, the contents of this file may be used under the 23 * terms of the GNU General Public License Version 2 or later (the 24 * "GPL"), in which case the provisions of the GPL are applicable 25 * instead of those above. If you wish to allow use of your 26 * version of this file only under the terms of the GPL and not to 27 * allow others to use your version of this file under the MPL, 28 * indicate your decision by deleting the provisions above and 29 * replace them with the notice and other provisions required by 30 * the GPL. If you do not delete the provisions above, a recipient 31 * may use your version of this file under either the MPL or the 32 * GPL. 33 */ 34 35 /* 36 * File: pripcsem.h 37 * 38 * Description: named semaphores for interprocess 39 * synchronization 40 * 41 * Unrelated processes obtain access to a shared semaphore 42 * by specifying its name. 43 * 44 * Our goal is to support named semaphores on at least 45 * Unix and Win32 platforms. The implementation will use 46 * one of the three native semaphore APIs: POSIX, System V, 47 * and Win32. 48 * 49 * Because POSIX named semaphores have kernel persistence, 50 * we are forced to have a delete function in this API. 51 */ 52 53 #ifndef pripcsem_h___ 54 #define pripcsem_h___ 55 56 #include "prtypes.h" 57 #include "prio.h" 58 59 PR_BEGIN_EXTERN_C 60 61 /* 62 * PRSem is an opaque structure that represents a named 63 * semaphore. 64 */ 65 typedef struct PRSem PRSem; 66 67 /* 68 * PR_OpenSemaphore -- 69 * 70 * Create or open a named semaphore with the specified name. 71 * A handle to the semaphore is returned. 72 * 73 * If the named semaphore doesn't exist and the PR_SEM_CREATE 74 * flag is specified, the named semaphore is created. The 75 * created semaphore needs to be removed from the system with 76 * a PR_DeleteSemaphore call. 77 * 78 * If PR_SEM_CREATE is specified, the third argument is the 79 * access permission bits of the new semaphore (same 80 * interpretation as the mode argument to PR_Open) and the 81 * fourth argument is the initial value of the new semaphore. 82 * If PR_SEM_CREATE is not specified, the third and fourth 83 * arguments are ignored. 84 */ 85 86 #define PR_SEM_CREATE 0x1 /* create if not exist */ 87 #define PR_SEM_EXCL 0x2 /* fail if already exists */ 88 89 NSPR_API(PRSem *) PR_OpenSemaphore( 90 const char *name, PRIntn flags, PRIntn mode, PRUintn value); 91 92 /* 93 * PR_WaitSemaphore -- 94 * 95 * If the value of the semaphore is > 0, decrement the value and return. 96 * If the value is 0, sleep until the value becomes > 0, then decrement 97 * the value and return. 98 * 99 * The "test and decrement" operation is performed atomically. 100 */ 101 102 NSPR_API(PRStatus) PR_WaitSemaphore(PRSem *sem); 103 104 /* 105 * PR_PostSemaphore -- 106 * 107 * Increment the value of the named semaphore by 1. 108 */ 109 110 NSPR_API(PRStatus) PR_PostSemaphore(PRSem *sem); 111 112 /* 113 * PR_CloseSemaphore -- 114 * 115 * Close a named semaphore handle. 116 */ 117 118 NSPR_API(PRStatus) PR_CloseSemaphore(PRSem *sem); 119 120 /* 121 * PR_DeleteSemaphore -- 122 * 123 * Remove a named semaphore from the system. 124 */ 125 126 NSPR_API(PRStatus) PR_DeleteSemaphore(const char *name); 127 128 PR_END_EXTERN_C 129 130 #endif /* pripcsem_h___ */ 131