michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * File: prpdce.h michael@0: * Description: This file is the API defined to allow for DCE (aka POSIX) michael@0: * thread emulation in an NSPR environment. It is not the michael@0: * intent that this be a fully supported API. michael@0: */ michael@0: michael@0: #if !defined(PRPDCE_H) michael@0: #define PRPDCE_H michael@0: michael@0: #include "prlock.h" michael@0: #include "prcvar.h" michael@0: #include "prtypes.h" michael@0: #include "prinrval.h" michael@0: michael@0: PR_BEGIN_EXTERN_C michael@0: michael@0: #define _PR_NAKED_CV_LOCK (PRLock*)0xdce1dce1 michael@0: michael@0: /* michael@0: ** Test and acquire a lock. michael@0: ** michael@0: ** If the lock is acquired by the calling thread, the michael@0: ** return value will be PR_SUCCESS. If the lock is michael@0: ** already held, by another thread or this thread, the michael@0: ** result will be PR_FAILURE. michael@0: */ michael@0: NSPR_API(PRStatus) PRP_TryLock(PRLock *lock); michael@0: michael@0: /* michael@0: ** Create a naked condition variable michael@0: ** michael@0: ** A "naked" condition variable is one that is not created bound michael@0: ** to a lock. The CV created with this function is the only type michael@0: ** that may be used in the subsequent "naked" condition variable michael@0: ** operations (see PRP_NakedWait, PRP_NakedNotify, PRP_NakedBroadcast); michael@0: */ michael@0: NSPR_API(PRCondVar*) PRP_NewNakedCondVar(void); michael@0: michael@0: /* michael@0: ** Destroy a naked condition variable michael@0: ** michael@0: ** Destroy the condition variable created by PR_NewNakedCondVar. michael@0: */ michael@0: NSPR_API(void) PRP_DestroyNakedCondVar(PRCondVar *cvar); michael@0: michael@0: /* michael@0: ** Wait on a condition michael@0: ** michael@0: ** Wait on the condition variable 'cvar'. It is asserted that michael@0: ** the lock protecting the condition 'lock' is held by the michael@0: ** calling thread. If more time expires than that declared in michael@0: ** 'timeout' the condition will be notified. Waits can be michael@0: ** interrupted by another thread. michael@0: ** michael@0: ** NB: The CV ('cvar') must be one created using PR_NewNakedCondVar. michael@0: */ michael@0: NSPR_API(PRStatus) PRP_NakedWait( michael@0: PRCondVar *cvar, PRLock *lock, PRIntervalTime timeout); michael@0: michael@0: /* michael@0: ** Notify a thread waiting on a condition michael@0: ** michael@0: ** Notify the condition specified 'cvar'. michael@0: ** michael@0: ** NB: The CV ('cvar') must be one created using PR_NewNakedCondVar. michael@0: */ michael@0: NSPR_API(PRStatus) PRP_NakedNotify(PRCondVar *cvar); michael@0: michael@0: /* michael@0: ** Notify all threads waiting on a condition michael@0: ** michael@0: ** Notify the condition specified 'cvar'. michael@0: ** michael@0: ** NB: The CV ('cvar') must be one created using PR_NewNakedCondVar. michael@0: */ michael@0: NSPR_API(PRStatus) PRP_NakedBroadcast(PRCondVar *cvar); michael@0: michael@0: PR_END_EXTERN_C michael@0: michael@0: #endif /* PRPDCE_H */