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: nsrwlock.h michael@0: ** Description: API to basic reader-writer lock functions of NSS. michael@0: ** These are re-entrant reader writer locks; that is, michael@0: ** If I hold the write lock, I can ask for it and get it again. michael@0: ** If I hold the write lock, I can also ask for and get a read lock. michael@0: ** I can then release the locks in any order (read or write). michael@0: ** I must release each lock type as many times as I acquired it. michael@0: ** Otherwise, these are normal reader/writer locks. michael@0: ** michael@0: ** For deadlock detection, locks should be ranked, and no lock may be aquired michael@0: ** while I hold a lock of higher rank number. michael@0: ** If you don't want that feature, always use NSS_RWLOCK_RANK_NONE. michael@0: ** Lock name is for debugging, and is optional (may be NULL) michael@0: **/ michael@0: michael@0: #ifndef nssrwlk_h___ michael@0: #define nssrwlk_h___ michael@0: michael@0: #include "utilrename.h" michael@0: #include "prtypes.h" michael@0: #include "nssrwlkt.h" michael@0: michael@0: #define NSS_RWLOCK_RANK_NONE 0 michael@0: michael@0: /* SEC_BEGIN_PROTOS */ michael@0: PR_BEGIN_EXTERN_C michael@0: michael@0: /*********************************************************************** michael@0: ** FUNCTION: NSSRWLock_New michael@0: ** DESCRIPTION: michael@0: ** Returns a pointer to a newly created reader-writer lock object. michael@0: ** INPUTS: Lock rank michael@0: ** Lock name michael@0: ** OUTPUTS: void michael@0: ** RETURN: NSSRWLock* michael@0: ** If the lock cannot be created because of resource constraints, NULL michael@0: ** is returned. michael@0: ** michael@0: ***********************************************************************/ michael@0: extern NSSRWLock* NSSRWLock_New(PRUint32 lock_rank, const char *lock_name); michael@0: michael@0: /*********************************************************************** michael@0: ** FUNCTION: NSSRWLock_AtomicCreate michael@0: ** DESCRIPTION: michael@0: ** Given the address of a NULL pointer to a NSSRWLock, michael@0: ** atomically initializes that pointer to a newly created NSSRWLock. michael@0: ** Returns the value placed into that pointer, or NULL. michael@0: ** michael@0: ** INPUTS: address of NSRWLock pointer michael@0: ** Lock rank michael@0: ** Lock name michael@0: ** OUTPUTS: NSSRWLock* michael@0: ** RETURN: NSSRWLock* michael@0: ** If the lock cannot be created because of resource constraints, michael@0: ** the pointer will be left NULL. michael@0: ** michael@0: ***********************************************************************/ michael@0: extern NSSRWLock * michael@0: nssRWLock_AtomicCreate( NSSRWLock ** prwlock, michael@0: PRUint32 lock_rank, michael@0: const char * lock_name); michael@0: michael@0: /*********************************************************************** michael@0: ** FUNCTION: NSSRWLock_Destroy michael@0: ** DESCRIPTION: michael@0: ** Destroys a given RW lock object. michael@0: ** INPUTS: NSSRWLock *lock - Lock to be freed. michael@0: ** OUTPUTS: void michael@0: ** RETURN: None michael@0: ***********************************************************************/ michael@0: extern void NSSRWLock_Destroy(NSSRWLock *lock); michael@0: michael@0: /*********************************************************************** michael@0: ** FUNCTION: NSSRWLock_LockRead michael@0: ** DESCRIPTION: michael@0: ** Apply a read lock (non-exclusive) on a RWLock michael@0: ** INPUTS: NSSRWLock *lock - Lock to be read-locked. michael@0: ** OUTPUTS: void michael@0: ** RETURN: None michael@0: ***********************************************************************/ michael@0: extern void NSSRWLock_LockRead(NSSRWLock *lock); michael@0: michael@0: /*********************************************************************** michael@0: ** FUNCTION: NSSRWLock_LockWrite michael@0: ** DESCRIPTION: michael@0: ** Apply a write lock (exclusive) on a RWLock michael@0: ** INPUTS: NSSRWLock *lock - Lock to write-locked. michael@0: ** OUTPUTS: void michael@0: ** RETURN: None michael@0: ***********************************************************************/ michael@0: extern void NSSRWLock_LockWrite(NSSRWLock *lock); michael@0: michael@0: /*********************************************************************** michael@0: ** FUNCTION: NSSRWLock_UnlockRead michael@0: ** DESCRIPTION: michael@0: ** Release a Read lock. Unlocking an unlocked lock has undefined results. michael@0: ** INPUTS: NSSRWLock *lock - Lock to unlocked. michael@0: ** OUTPUTS: void michael@0: ** RETURN: void michael@0: ***********************************************************************/ michael@0: extern void NSSRWLock_UnlockRead(NSSRWLock *lock); michael@0: michael@0: /*********************************************************************** michael@0: ** FUNCTION: NSSRWLock_UnlockWrite michael@0: ** DESCRIPTION: michael@0: ** Release a Write lock. Unlocking an unlocked lock has undefined results. michael@0: ** INPUTS: NSSRWLock *lock - Lock to unlocked. michael@0: ** OUTPUTS: void michael@0: ** RETURN: void michael@0: ***********************************************************************/ michael@0: extern void NSSRWLock_UnlockWrite(NSSRWLock *lock); michael@0: michael@0: /*********************************************************************** michael@0: ** FUNCTION: NSSRWLock_HaveWriteLock michael@0: ** DESCRIPTION: michael@0: ** Tells caller whether the current thread holds the write lock, or not. michael@0: ** INPUTS: NSSRWLock *lock - Lock to test. michael@0: ** OUTPUTS: void michael@0: ** RETURN: PRBool PR_TRUE IFF the current thread holds the write lock. michael@0: ***********************************************************************/ michael@0: michael@0: extern PRBool NSSRWLock_HaveWriteLock(NSSRWLock *rwlock); michael@0: michael@0: /* SEC_END_PROTOS */ michael@0: PR_END_EXTERN_C michael@0: michael@0: #endif /* nsrwlock_h___ */