pripcsem.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is the Netscape Portable Runtime (NSPR).
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1999-2000
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. /*
  38. * File: pripcsem.h
  39. *
  40. * Description: named semaphores for interprocess
  41. * synchronization
  42. *
  43. * Unrelated processes obtain access to a shared semaphore
  44. * by specifying its name.
  45. *
  46. * Our goal is to support named semaphores on at least
  47. * Unix and Win32 platforms. The implementation will use
  48. * one of the three native semaphore APIs: POSIX, System V,
  49. * and Win32.
  50. *
  51. * Because POSIX named semaphores have kernel persistence,
  52. * we are forced to have a delete function in this API.
  53. */
  54. #ifndef pripcsem_h___
  55. #define pripcsem_h___
  56. #include "prtypes.h"
  57. #include "prio.h"
  58. PR_BEGIN_EXTERN_C
  59. /*
  60. * PRSem is an opaque structure that represents a named
  61. * semaphore.
  62. */
  63. typedef struct PRSem PRSem;
  64. /*
  65. * PR_OpenSemaphore --
  66. *
  67. * Create or open a named semaphore with the specified name.
  68. * A handle to the semaphore is returned.
  69. *
  70. * If the named semaphore doesn't exist and the PR_SEM_CREATE
  71. * flag is specified, the named semaphore is created. The
  72. * created semaphore needs to be removed from the system with
  73. * a PR_DeleteSemaphore call.
  74. *
  75. * If PR_SEM_CREATE is specified, the third argument is the
  76. * access permission bits of the new semaphore (same
  77. * interpretation as the mode argument to PR_Open) and the
  78. * fourth argument is the initial value of the new semaphore.
  79. * If PR_SEM_CREATE is not specified, the third and fourth
  80. * arguments are ignored.
  81. */
  82. #define PR_SEM_CREATE 0x1 /* create if not exist */
  83. #define PR_SEM_EXCL 0x2 /* fail if already exists */
  84. NSPR_API(PRSem *) PR_OpenSemaphore(
  85. const char *name, PRIntn flags, PRIntn mode, PRUintn value);
  86. /*
  87. * PR_WaitSemaphore --
  88. *
  89. * If the value of the semaphore is > 0, decrement the value and return.
  90. * If the value is 0, sleep until the value becomes > 0, then decrement
  91. * the value and return.
  92. *
  93. * The "test and decrement" operation is performed atomically.
  94. */
  95. NSPR_API(PRStatus) PR_WaitSemaphore(PRSem *sem);
  96. /*
  97. * PR_PostSemaphore --
  98. *
  99. * Increment the value of the named semaphore by 1.
  100. */
  101. NSPR_API(PRStatus) PR_PostSemaphore(PRSem *sem);
  102. /*
  103. * PR_CloseSemaphore --
  104. *
  105. * Close a named semaphore handle.
  106. */
  107. NSPR_API(PRStatus) PR_CloseSemaphore(PRSem *sem);
  108. /*
  109. * PR_DeleteSemaphore --
  110. *
  111. * Remove a named semaphore from the system.
  112. */
  113. NSPR_API(PRStatus) PR_DeleteSemaphore(const char *name);
  114. PR_END_EXTERN_C
  115. #endif /* pripcsem_h___ */