|
|
1.1 root 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) 1998-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: #ifndef prsem_h___
36: #define prsem_h___
37:
38: /*
39: ** API for counting semaphores. Semaphores are counting synchronizing
40: ** variables based on a lock and a condition variable. They are lightweight
41: ** contention control for a given count of resources.
42: */
43: #include "prtypes.h"
44:
45: PR_BEGIN_EXTERN_C
46:
47: typedef struct PRSemaphore PRSemaphore;
48:
49: /*
50: ** Create a new semaphore object.
51: */
52: NSPR_API(PRSemaphore*) PR_NewSem(PRUintn value);
53:
54: /*
55: ** Destroy the given semaphore object.
56: **
57: */
58: NSPR_API(void) PR_DestroySem(PRSemaphore *sem);
59:
60: /*
61: ** Wait on a Semaphore.
62: **
63: ** This routine allows a calling thread to wait or proceed depending upon the
64: ** state of the semahore sem. The thread can proceed only if the counter value
65: ** of the semaphore sem is currently greater than 0. If the value of semaphore
66: ** sem is positive, it is decremented by one and the routine returns immediately
67: ** allowing the calling thread to continue. If the value of semaphore sem is 0,
68: ** the calling thread blocks awaiting the semaphore to be released by another
69: ** thread.
70: **
71: ** This routine can return PR_PENDING_INTERRUPT if the waiting thread
72: ** has been interrupted.
73: */
74: NSPR_API(PRStatus) PR_WaitSem(PRSemaphore *sem);
75:
76: /*
77: ** This routine increments the counter value of the semaphore. If other threads
78: ** are blocked for the semaphore, then the scheduler will determine which ONE
79: ** thread will be unblocked.
80: */
81: NSPR_API(void) PR_PostSem(PRSemaphore *sem);
82:
83: /*
84: ** Returns the value of the semaphore referenced by sem without affecting
85: ** the state of the semaphore. The value represents the semaphore vaule
86: F** at the time of the call, but may not be the actual value when the
87: ** caller inspects it.
88: */
89: NSPR_API(PRUintn) PR_GetValueSem(PRSemaphore *sem);
90:
91: PR_END_EXTERN_C
92:
93: #endif /* prsem_h___ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.