security/nss/lib/util/nssrwlk.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 /*
     6 ** File:		nsrwlock.h
     7 ** Description:	API to basic reader-writer lock functions of NSS.
     8 **	These are re-entrant reader writer locks; that is,
     9 **	If I hold the write lock, I can ask for it and get it again.
    10 **	If I hold the write lock, I can also ask for and get a read lock.
    11 **      I can then release the locks in any order (read or write).
    12 **	I must release each lock type as many times as I acquired it.
    13 **	Otherwise, these are normal reader/writer locks.
    14 **
    15 ** For deadlock detection, locks should be ranked, and no lock may be aquired
    16 ** while I hold a lock of higher rank number.
    17 ** If you don't want that feature, always use NSS_RWLOCK_RANK_NONE.
    18 ** Lock name is for debugging, and is optional (may be NULL)
    19 **/
    21 #ifndef nssrwlk_h___
    22 #define nssrwlk_h___
    24 #include "utilrename.h"
    25 #include "prtypes.h"
    26 #include "nssrwlkt.h"
    28 #define	NSS_RWLOCK_RANK_NONE	0
    30 /* SEC_BEGIN_PROTOS */
    31 PR_BEGIN_EXTERN_C
    33 /***********************************************************************
    34 ** FUNCTION:    NSSRWLock_New
    35 ** DESCRIPTION:
    36 **  Returns a pointer to a newly created reader-writer lock object.
    37 ** INPUTS:      Lock rank
    38 **		Lock name
    39 ** OUTPUTS:     void
    40 ** RETURN:      NSSRWLock*
    41 **   If the lock cannot be created because of resource constraints, NULL
    42 **   is returned.
    43 **  
    44 ***********************************************************************/
    45 extern NSSRWLock* NSSRWLock_New(PRUint32 lock_rank, const char *lock_name);
    47 /***********************************************************************
    48 ** FUNCTION:    NSSRWLock_AtomicCreate
    49 ** DESCRIPTION:
    50 **  Given the address of a NULL pointer to a NSSRWLock, 
    51 **  atomically initializes that pointer to a newly created NSSRWLock.
    52 **  Returns the value placed into that pointer, or NULL.
    53 **
    54 ** INPUTS:      address of NSRWLock pointer
    55 **              Lock rank
    56 **		Lock name
    57 ** OUTPUTS:     NSSRWLock*
    58 ** RETURN:      NSSRWLock*
    59 **   If the lock cannot be created because of resource constraints, 
    60 **   the pointer will be left NULL.
    61 **  
    62 ***********************************************************************/
    63 extern NSSRWLock *
    64 nssRWLock_AtomicCreate( NSSRWLock  ** prwlock, 
    65 			PRUint32      lock_rank, 
    66 			const char *  lock_name);
    68 /***********************************************************************
    69 ** FUNCTION:    NSSRWLock_Destroy
    70 ** DESCRIPTION:
    71 **  Destroys a given RW lock object.
    72 ** INPUTS:      NSSRWLock *lock - Lock to be freed.
    73 ** OUTPUTS:     void
    74 ** RETURN:      None
    75 ***********************************************************************/
    76 extern void NSSRWLock_Destroy(NSSRWLock *lock);
    78 /***********************************************************************
    79 ** FUNCTION:    NSSRWLock_LockRead
    80 ** DESCRIPTION:
    81 **  Apply a read lock (non-exclusive) on a RWLock
    82 ** INPUTS:      NSSRWLock *lock - Lock to be read-locked.
    83 ** OUTPUTS:     void
    84 ** RETURN:      None
    85 ***********************************************************************/
    86 extern void NSSRWLock_LockRead(NSSRWLock *lock);
    88 /***********************************************************************
    89 ** FUNCTION:    NSSRWLock_LockWrite
    90 ** DESCRIPTION:
    91 **  Apply a write lock (exclusive) on a RWLock
    92 ** INPUTS:      NSSRWLock *lock - Lock to write-locked.
    93 ** OUTPUTS:     void
    94 ** RETURN:      None
    95 ***********************************************************************/
    96 extern void NSSRWLock_LockWrite(NSSRWLock *lock);
    98 /***********************************************************************
    99 ** FUNCTION:    NSSRWLock_UnlockRead
   100 ** DESCRIPTION:
   101 **  Release a Read lock. Unlocking an unlocked lock has undefined results.
   102 ** INPUTS:      NSSRWLock *lock - Lock to unlocked.
   103 ** OUTPUTS:     void
   104 ** RETURN:      void
   105 ***********************************************************************/
   106 extern void NSSRWLock_UnlockRead(NSSRWLock *lock);
   108 /***********************************************************************
   109 ** FUNCTION:    NSSRWLock_UnlockWrite
   110 ** DESCRIPTION:
   111 **  Release a Write lock. Unlocking an unlocked lock has undefined results.
   112 ** INPUTS:      NSSRWLock *lock - Lock to unlocked.
   113 ** OUTPUTS:     void
   114 ** RETURN:      void
   115 ***********************************************************************/
   116 extern void NSSRWLock_UnlockWrite(NSSRWLock *lock);
   118 /***********************************************************************
   119 ** FUNCTION:    NSSRWLock_HaveWriteLock
   120 ** DESCRIPTION:
   121 **  Tells caller whether the current thread holds the write lock, or not.
   122 ** INPUTS:      NSSRWLock *lock - Lock to test.
   123 ** OUTPUTS:     void
   124 ** RETURN:      PRBool	PR_TRUE IFF the current thread holds the write lock.
   125 ***********************************************************************/
   127 extern PRBool NSSRWLock_HaveWriteLock(NSSRWLock *rwlock);
   129 /* SEC_END_PROTOS */
   130 PR_END_EXTERN_C
   132 #endif /* nsrwlock_h___ */

mercurial