pratom.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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) 1998-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. /* GLOBAL FUNCTIONS:
  38. ** DESCRIPTION:
  39. ** PR Atomic operations
  40. */
  41. #ifndef pratom_h___
  42. #define pratom_h___
  43. #include "prtypes.h"
  44. #include "prlock.h"
  45. PR_BEGIN_EXTERN_C
  46. /*
  47. ** FUNCTION: PR_AtomicIncrement
  48. ** DESCRIPTION:
  49. ** Atomically increment a 32 bit value.
  50. ** INPUTS:
  51. ** val: a pointer to the value to increment
  52. ** RETURN:
  53. ** the returned value is the result of the increment
  54. */
  55. NSPR_API(PRInt32) PR_AtomicIncrement(PRInt32 *val);
  56. /*
  57. ** FUNCTION: PR_AtomicDecrement
  58. ** DESCRIPTION:
  59. ** Atomically decrement a 32 bit value.
  60. ** INPUTS:
  61. ** val: a pointer to the value to decrement
  62. ** RETURN:
  63. ** the returned value is the result of the decrement
  64. */
  65. NSPR_API(PRInt32) PR_AtomicDecrement(PRInt32 *val);
  66. /*
  67. ** FUNCTION: PR_AtomicSet
  68. ** DESCRIPTION:
  69. ** Atomically set a 32 bit value.
  70. ** INPUTS:
  71. ** val: A pointer to a 32 bit value to be set
  72. ** newval: The newvalue to assign to val
  73. ** RETURN:
  74. ** Returns the prior value
  75. */
  76. NSPR_API(PRInt32) PR_AtomicSet(PRInt32 *val, PRInt32 newval);
  77. /*
  78. ** FUNCTION: PR_AtomicAdd
  79. ** DESCRIPTION:
  80. ** Atomically add a 32 bit value.
  81. ** INPUTS:
  82. ** ptr: a pointer to the value to increment
  83. ** val: value to be added
  84. ** RETURN:
  85. ** the returned value is the result of the addition
  86. */
  87. NSPR_API(PRInt32) PR_AtomicAdd(PRInt32 *ptr, PRInt32 val);
  88. /*
  89. ** LIFO linked-list (stack)
  90. */
  91. typedef struct PRStackElemStr PRStackElem;
  92. struct PRStackElemStr {
  93. PRStackElem *prstk_elem_next; /* next pointer MUST be at offset 0;
  94. assembly language code relies on this */
  95. };
  96. typedef struct PRStackStr PRStack;
  97. /*
  98. ** FUNCTION: PR_CreateStack
  99. ** DESCRIPTION:
  100. ** Create a stack, a LIFO linked list
  101. ** INPUTS:
  102. ** stack_name: a pointer to string containing the name of the stack
  103. ** RETURN:
  104. ** A pointer to the created stack, if successful, else NULL.
  105. */
  106. NSPR_API(PRStack *) PR_CreateStack(const char *stack_name);
  107. /*
  108. ** FUNCTION: PR_StackPush
  109. ** DESCRIPTION:
  110. ** Push an element on the top of the stack
  111. ** INPUTS:
  112. ** stack: pointer to the stack
  113. ** stack_elem: pointer to the stack element
  114. ** RETURN:
  115. ** None
  116. */
  117. NSPR_API(void) PR_StackPush(PRStack *stack, PRStackElem *stack_elem);
  118. /*
  119. ** FUNCTION: PR_StackPop
  120. ** DESCRIPTION:
  121. ** Remove the element on the top of the stack
  122. ** INPUTS:
  123. ** stack: pointer to the stack
  124. ** RETURN:
  125. ** A pointer to the stack element removed from the top of the stack,
  126. ** if non-empty,
  127. ** else NULL
  128. */
  129. NSPR_API(PRStackElem *) PR_StackPop(PRStack *stack);
  130. /*
  131. ** FUNCTION: PR_DestroyStack
  132. ** DESCRIPTION:
  133. ** Destroy the stack
  134. ** INPUTS:
  135. ** stack: pointer to the stack
  136. ** RETURN:
  137. ** PR_SUCCESS - if successfully deleted
  138. ** PR_FAILURE - if the stack is not empty
  139. ** PR_GetError will return
  140. ** PR_INVALID_STATE_ERROR - stack is not empty
  141. */
  142. NSPR_API(PRStatus) PR_DestroyStack(PRStack *stack);
  143. PR_END_EXTERN_C
  144. #endif /* pratom_h___ */