1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 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/
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.
13 * The Original Code is the Netscape Portable Runtime (NSPR).
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
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
38 * Description: named semaphores for interprocess
41 * Unrelated processes obtain access to a shared semaphore
42 * by specifying its name.
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,
49 * Because POSIX named semaphores have kernel persistence,
50 * we are forced to have a delete function in this API.
62 * PRSem is an opaque structure that represents a named
65 typedef struct PRSem PRSem
;
70 * Create or open a named semaphore with the specified name.
71 * A handle to the semaphore is returned.
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.
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.
86 #define PR_SEM_CREATE 0x1 /* create if not exist */
87 #define PR_SEM_EXCL 0x2 /* fail if already exists */
89 NSPR_API(PRSem
*) PR_OpenSemaphore(
90 const char *name
, PRIntn flags
, PRIntn mode
, PRUintn value
);
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.
99 * The "test and decrement" operation is performed atomically.
102 NSPR_API(PRStatus
) PR_WaitSemaphore(PRSem
*sem
);
105 * PR_PostSemaphore --
107 * Increment the value of the named semaphore by 1.
110 NSPR_API(PRStatus
) PR_PostSemaphore(PRSem
*sem
);
113 * PR_CloseSemaphore --
115 * Close a named semaphore handle.
118 NSPR_API(PRStatus
) PR_CloseSemaphore(PRSem
*sem
);
121 * PR_DeleteSemaphore --
123 * Remove a named semaphore from the system.
126 NSPR_API(PRStatus
) PR_DeleteSemaphore(const char *name
);
130 #endif /* pripcsem_h___ */