Back to index

lightning-sunbird  0.9+nobinonly
pripcsem.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1999-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039  * File: pripcsem.h
00040  *
00041  * Description: named semaphores for interprocess
00042  * synchronization
00043  *
00044  * Unrelated processes obtain access to a shared semaphore
00045  * by specifying its name.
00046  *
00047  * Our goal is to support named semaphores on at least
00048  * Unix and Win32 platforms.  The implementation will use
00049  * one of the three native semaphore APIs: POSIX, System V,
00050  * and Win32.
00051  *
00052  * Because POSIX named semaphores have kernel persistence,
00053  * we are forced to have a delete function in this API.
00054  */
00055 
00056 #ifndef pripcsem_h___
00057 #define pripcsem_h___
00058 
00059 #include "prtypes.h"
00060 #include "prio.h"
00061 
00062 PR_BEGIN_EXTERN_C
00063 
00064 /*
00065  * PRSem is an opaque structure that represents a named
00066  * semaphore.
00067  */
00068 typedef struct PRSem PRSem;
00069 
00070 /*
00071  * PR_OpenSemaphore --
00072  *
00073  * Create or open a named semaphore with the specified name.
00074  * A handle to the semaphore is returned.
00075  *
00076  * If the named semaphore doesn't exist and the PR_SEM_CREATE
00077  * flag is specified, the named semaphore is created.  The
00078  * created semaphore needs to be removed from the system with
00079  * a PR_DeleteSemaphore call.
00080  *
00081  * If PR_SEM_CREATE is specified, the third argument is the
00082  * access permission bits of the new semaphore (same
00083  * interpretation as the mode argument to PR_Open) and the
00084  * fourth argument is the initial value of the new semaphore.
00085  * If PR_SEM_CREATE is not specified, the third and fourth
00086  * arguments are ignored.
00087  */
00088 
00089 #define PR_SEM_CREATE 0x1  /* create if not exist */
00090 #define PR_SEM_EXCL   0x2  /* fail if already exists */
00091 
00092 NSPR_API(PRSem *) PR_OpenSemaphore(
00093     const char *name, PRIntn flags, PRIntn mode, PRUintn value);
00094 
00095 /*
00096  * PR_WaitSemaphore --
00097  *
00098  * If the value of the semaphore is > 0, decrement the value and return.
00099  * If the value is 0, sleep until the value becomes > 0, then decrement
00100  * the value and return.
00101  *
00102  * The "test and decrement" operation is performed atomically.
00103  */
00104 
00105 NSPR_API(PRStatus) PR_WaitSemaphore(PRSem *sem);
00106 
00107 /*
00108  * PR_PostSemaphore --
00109  *
00110  * Increment the value of the named semaphore by 1.
00111  */
00112 
00113 NSPR_API(PRStatus) PR_PostSemaphore(PRSem *sem);
00114 
00115 /*
00116  * PR_CloseSemaphore --
00117  *
00118  * Close a named semaphore handle.
00119  */
00120 
00121 NSPR_API(PRStatus) PR_CloseSemaphore(PRSem *sem);
00122 
00123 /*
00124  * PR_DeleteSemaphore --
00125  *
00126  * Remove a named semaphore from the system.
00127  */
00128 
00129 NSPR_API(PRStatus) PR_DeleteSemaphore(const char *name);
00130 
00131 PR_END_EXTERN_C
00132 
00133 #endif /* pripcsem_h___ */