PageRenderTime 203ms CodeModel.GetById 101ms app.highlight 2ms RepoModel.GetById 98ms app.codeStats 1ms

/gecko_api/include/pripcsem.h

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