prrwlock.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /*
  6. ** File: prrwlock.h
  7. ** Description: API to basic reader-writer lock functions of NSPR.
  8. **
  9. **/
  10. #ifndef prrwlock_h___
  11. #define prrwlock_h___
  12. #include "prtypes.h"
  13. PR_BEGIN_EXTERN_C
  14. /*
  15. * PRRWLock --
  16. *
  17. * The reader writer lock, PRRWLock, is an opaque object to the clients
  18. * of NSPR. All routines operate on a pointer to this opaque entity.
  19. */
  20. typedef struct PRRWLock PRRWLock;
  21. #define PR_RWLOCK_RANK_NONE 0
  22. /***********************************************************************
  23. ** FUNCTION: PR_NewRWLock
  24. ** DESCRIPTION:
  25. ** Returns a pointer to a newly created reader-writer lock object.
  26. ** INPUTS: Lock rank
  27. ** Lock name
  28. ** OUTPUTS: void
  29. ** RETURN: PRRWLock*
  30. ** If the lock cannot be created because of resource constraints, NULL
  31. ** is returned.
  32. **
  33. ***********************************************************************/
  34. NSPR_API(PRRWLock*) PR_NewRWLock(PRUint32 lock_rank, const char *lock_name);
  35. /***********************************************************************
  36. ** FUNCTION: PR_DestroyRWLock
  37. ** DESCRIPTION:
  38. ** Destroys a given RW lock object.
  39. ** INPUTS: PRRWLock *lock - Lock to be freed.
  40. ** OUTPUTS: void
  41. ** RETURN: None
  42. ***********************************************************************/
  43. NSPR_API(void) PR_DestroyRWLock(PRRWLock *lock);
  44. /***********************************************************************
  45. ** FUNCTION: PR_RWLock_Rlock
  46. ** DESCRIPTION:
  47. ** Apply a read lock (non-exclusive) on a RWLock
  48. ** INPUTS: PRRWLock *lock - Lock to be read-locked.
  49. ** OUTPUTS: void
  50. ** RETURN: None
  51. ***********************************************************************/
  52. NSPR_API(void) PR_RWLock_Rlock(PRRWLock *lock);
  53. /***********************************************************************
  54. ** FUNCTION: PR_RWLock_Wlock
  55. ** DESCRIPTION:
  56. ** Apply a write lock (exclusive) on a RWLock
  57. ** INPUTS: PRRWLock *lock - Lock to write-locked.
  58. ** OUTPUTS: void
  59. ** RETURN: None
  60. ***********************************************************************/
  61. NSPR_API(void) PR_RWLock_Wlock(PRRWLock *lock);
  62. /***********************************************************************
  63. ** FUNCTION: PR_RWLock_Unlock
  64. ** DESCRIPTION:
  65. ** Release a RW lock. Unlocking an unlocked lock has undefined results.
  66. ** INPUTS: PRRWLock *lock - Lock to unlocked.
  67. ** OUTPUTS: void
  68. ** RETURN: void
  69. ***********************************************************************/
  70. NSPR_API(void) PR_RWLock_Unlock(PRRWLock *lock);
  71. PR_END_EXTERN_C
  72. #endif /* prrwlock_h___ */