andre@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: /* andre@0: ** File: prlock.h andre@0: ** Description: API to basic locking functions of NSPR. andre@0: ** andre@0: ** andre@0: ** NSPR provides basic locking mechanisms for thread synchronization. Locks andre@0: ** are lightweight resource contention controls that prevent multiple threads andre@0: ** from accessing something (code/data) simultaneously. andre@0: **/ andre@0: andre@0: #ifndef prlock_h___ andre@0: #define prlock_h___ andre@0: andre@0: #include "prtypes.h" andre@0: andre@0: PR_BEGIN_EXTERN_C andre@0: andre@0: /**********************************************************************/ andre@0: /************************* TYPES AND CONSTANTS ************************/ andre@0: /**********************************************************************/ andre@0: andre@0: /* andre@0: * PRLock -- andre@0: * andre@0: * NSPR represents the lock as an opaque entity to the client of the andre@0: * API. All routines operate on a pointer to this opaque entity. andre@0: */ andre@0: andre@0: typedef struct PRLock PRLock; andre@0: andre@0: /**********************************************************************/ andre@0: /****************************** FUNCTIONS *****************************/ andre@0: /**********************************************************************/ andre@0: andre@0: /*********************************************************************** andre@0: ** FUNCTION: PR_NewLock andre@0: ** DESCRIPTION: andre@0: ** Returns a pointer to a newly created opaque lock object. andre@0: ** INPUTS: void andre@0: ** OUTPUTS: void andre@0: ** RETURN: PRLock* andre@0: ** If the lock can not be created because of resource constraints, NULL andre@0: ** is returned. andre@0: ** andre@0: ***********************************************************************/ andre@0: NSPR_API(PRLock*) PR_NewLock(void); andre@0: andre@0: /*********************************************************************** andre@0: ** FUNCTION: PR_DestroyLock andre@0: ** DESCRIPTION: andre@0: ** Destroys a given opaque lock object. andre@0: ** INPUTS: PRLock *lock andre@0: ** Lock to be freed. andre@0: ** OUTPUTS: void andre@0: ** RETURN: None andre@0: ***********************************************************************/ andre@0: NSPR_API(void) PR_DestroyLock(PRLock *lock); andre@0: andre@0: /*********************************************************************** andre@0: ** FUNCTION: PR_Lock andre@0: ** DESCRIPTION: andre@0: ** Lock a lock. andre@0: ** INPUTS: PRLock *lock andre@0: ** Lock to locked. andre@0: ** OUTPUTS: void andre@0: ** RETURN: None andre@0: ***********************************************************************/ andre@0: NSPR_API(void) PR_Lock(PRLock *lock); andre@0: andre@0: /*********************************************************************** andre@0: ** FUNCTION: PR_Unlock andre@0: ** DESCRIPTION: andre@0: ** Unlock a lock. Unlocking an unlocked lock has undefined results. andre@0: ** INPUTS: PRLock *lock andre@0: ** Lock to unlocked. andre@0: ** OUTPUTS: void andre@0: ** RETURN: PR_STATUS andre@0: ** Returns PR_FAILURE if the caller does not own the lock. andre@0: ***********************************************************************/ andre@0: NSPR_API(PRStatus) PR_Unlock(PRLock *lock); andre@0: andre@0: /*********************************************************************** andre@0: ** MACRO: PR_ASSERT_CURRENT_THREAD_OWNS_LOCK andre@0: ** DESCRIPTION: andre@0: ** If the current thread owns |lock|, this assertion is guaranteed to andre@0: ** succeed. Otherwise, the behavior of this function is undefined. andre@0: ** INPUTS: PRLock *lock andre@0: ** Lock to assert ownership of. andre@0: ** OUTPUTS: void andre@0: ** RETURN: None andre@0: ***********************************************************************/ andre@0: #if defined(DEBUG) || defined(FORCE_PR_ASSERT) andre@0: #define PR_ASSERT_CURRENT_THREAD_OWNS_LOCK(/* PrLock* */ lock) \ andre@0: PR_AssertCurrentThreadOwnsLock(lock) andre@0: #else andre@0: #define PR_ASSERT_CURRENT_THREAD_OWNS_LOCK(/* PrLock* */ lock) andre@0: #endif andre@0: andre@0: /* Don't call this function directly. */ andre@0: NSPR_API(void) PR_AssertCurrentThreadOwnsLock(PRLock *lock); andre@0: andre@0: PR_END_EXTERN_C andre@0: andre@0: #endif /* prlock_h___ */