Back to index

lightning-sunbird  0.9+nobinonly
prmon.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) 1998-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 #ifndef prmon_h___
00039 #define prmon_h___
00040 
00041 #include "prtypes.h"
00042 #include "prinrval.h"
00043 
00044 PR_BEGIN_EXTERN_C
00045 
00046 typedef struct PRMonitor PRMonitor;
00047 
00048 /*
00049 ** Create a new monitor. Monitors are re-entrant locks with a single built-in
00050 ** condition variable.
00051 **
00052 ** This may fail if memory is tight or if some operating system resource
00053 ** is low.
00054 */
00055 NSPR_API(PRMonitor*) PR_NewMonitor(void);
00056 
00057 /*
00058 ** Destroy a monitor. The caller is responsible for guaranteeing that the
00059 ** monitor is no longer in use. There must be no thread waiting on the monitor's
00060 ** condition variable and that the lock is not held.
00061 **
00062 */
00063 NSPR_API(void) PR_DestroyMonitor(PRMonitor *mon);
00064 
00065 /*
00066 ** Enter the lock associated with the monitor. If the calling thread currently
00067 ** is in the monitor, the call to enter will silently succeed. In either case,
00068 ** it will increment the entry count by one.
00069 */
00070 NSPR_API(void) PR_EnterMonitor(PRMonitor *mon);
00071 
00072 /*
00073 ** Decrement the entry count associated with the monitor. If the decremented
00074 ** entry count is zero, the monitor is exited. Returns PR_FAILURE if the
00075 ** calling thread has not entered the monitor.
00076 */
00077 NSPR_API(PRStatus) PR_ExitMonitor(PRMonitor *mon);
00078 
00079 /*
00080 ** Wait for a notify on the monitor's condition variable. Sleep for "ticks"
00081 ** amount of time (if "ticks" is PR_INTERVAL_NO_TIMEOUT then the sleep is
00082 ** indefinite).
00083 **
00084 ** While the thread is waiting it exits the monitor (as if it called
00085 ** PR_ExitMonitor as many times as it had called PR_EnterMonitor).  When
00086 ** the wait has finished the thread regains control of the monitors lock
00087 ** with the same entry count as before the wait began.
00088 **
00089 ** The thread waiting on the monitor will be resumed when the monitor is
00090 ** notified (assuming the thread is the next in line to receive the
00091 ** notify) or when the "ticks" timeout elapses.
00092 **
00093 ** Returns PR_FAILURE if the caller has not entered the monitor.
00094 */
00095 NSPR_API(PRStatus) PR_Wait(PRMonitor *mon, PRIntervalTime ticks);
00096 
00097 /*
00098 ** Notify a thread waiting on the monitor's condition variable. If a thread
00099 ** is waiting on the condition variable (using PR_Wait) then it is awakened
00100 ** and attempts to reenter the monitor.
00101 */
00102 NSPR_API(PRStatus) PR_Notify(PRMonitor *mon);
00103 
00104 /*
00105 ** Notify all of the threads waiting on the monitor's condition variable.
00106 ** All of threads waiting on the condition are scheduled to reenter the
00107 ** monitor.
00108 */
00109 NSPR_API(PRStatus) PR_NotifyAll(PRMonitor *mon);
00110 
00111 PR_END_EXTERN_C
00112 
00113 #endif /* prmon_h___ */