15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * The contents of this file are subject to the Mozilla Public
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * License Version 1.1 (the "License"); you may not use this file
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * except in compliance with the License. You may obtain a copy of
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * the License at http://www.mozilla.org/MPL/
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Software distributed under the License is distributed on an "AS
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * implied. See the License for the specific language governing
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * rights and limitations under the License.
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * The Original Code is the Netscape Portable Runtime (NSPR).
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * The Initial Developer of the Original Code is Netscape
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Communications Corporation.  Portions created by Netscape are
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copyright (C) 1998-2000 Netscape Communications Corporation.  All
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Rights Reserved.
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Contributor(s):
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Alternatively, the contents of this file may be used under the
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * terms of the GNU General Public License Version 2 or later (the
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * "GPL"), in which case the provisions of the GPL are applicable
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * instead of those above.  If you wish to allow use of your
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * version of this file only under the terms of the GPL and not to
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * allow others to use your version of this file under the MPL,
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * indicate your decision by deleting the provisions above and
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * replace them with the notice and other provisions required by
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * the GPL.  If you do not delete the provisions above, a recipient
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * may use your version of this file under either the MPL or the
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * GPL.
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * File:		prpdce.h
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Description:	This file is the API defined to allow for DCE (aka POSIX)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *				thread emulation in an NSPR environment. It is not the
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *				intent that this be a fully supported API.
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(PRPDCE_H)
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define PRPDCE_H
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "prlock.h"
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "prcvar.h"
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "prtypes.h"
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "prinrval.h"
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PR_BEGIN_EXTERN_C
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define _PR_NAKED_CV_LOCK (PRLock*)0xdce1dce1
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Test and acquire a lock.
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)**
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** If the lock is acquired by the calling thread, the
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** return value will be PR_SUCCESS. If the lock is
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** already held, by another thread or this thread, the
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** result will be PR_FAILURE.
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRStatus) PRP_TryLock(PRLock *lock);
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Create a naked condition variable
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)**
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** A "naked" condition variable is one that is not created bound
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** to a lock. The CV created with this function is the only type
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** that may be used in the subsequent "naked" condition variable
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** operations (see PRP_NakedWait, PRP_NakedNotify, PRP_NakedBroadcast);
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRCondVar*) PRP_NewNakedCondVar(void);
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Destroy a naked condition variable
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)**
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Destroy the condition variable created by PR_NewNakedCondVar.
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(void) PRP_DestroyNakedCondVar(PRCondVar *cvar);
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Wait on a condition
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)**
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Wait on the condition variable 'cvar'. It is asserted that
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** the lock protecting the condition 'lock' is held by the
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** calling thread. If more time expires than that declared in
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** 'timeout' the condition will be notified. Waits can be
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** interrupted by another thread.
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)**
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** NB: The CV ('cvar') must be one created using PR_NewNakedCondVar.
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRStatus) PRP_NakedWait(
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	PRCondVar *cvar, PRLock *lock, PRIntervalTime timeout);
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Notify a thread waiting on a condition
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)**
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Notify the condition specified 'cvar'.
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)**
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** NB: The CV ('cvar') must be one created using PR_NewNakedCondVar.
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRStatus) PRP_NakedNotify(PRCondVar *cvar);
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Notify all threads waiting on a condition
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)**
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** Notify the condition specified 'cvar'.
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)**
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)** NB: The CV ('cvar') must be one created using PR_NewNakedCondVar.
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)*/
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)NSPR_API(PRStatus) PRP_NakedBroadcast(PRCondVar *cvar);
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)PR_END_EXTERN_C
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif /* PRPDCE_H */
116