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

source code of include/nspr/pripcsem.h