home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / pratom.h < prev    next >
C/C++ Source or Header  |  1998-11-02  |  4KB  |  152 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /* GLOBAL FUNCTIONS:
  20. ** DESCRIPTION:
  21. **     PR Atomic operations
  22. */
  23.  
  24. #ifndef pratom_h___
  25. #define pratom_h___
  26.  
  27. #include "prtypes.h"
  28. #include "prlock.h"
  29.  
  30. PR_BEGIN_EXTERN_C
  31.  
  32. /*
  33. ** FUNCTION: PR_AtomicIncrement
  34. ** DESCRIPTION:
  35. **    Atomically increment a 32 bit value.
  36. ** INPUTS:
  37. **    val:  a pointer to the value to increment
  38. ** RETURN:
  39. **    the returned value is the result of the increment
  40. */
  41. PR_EXTERN(PRInt32)    PR_AtomicIncrement(PRInt32 *val);
  42.  
  43. /*
  44. ** FUNCTION: PR_AtomicDecrement
  45. ** DESCRIPTION:
  46. **    Atomically decrement a 32 bit value.
  47. ** INPUTS:
  48. **    val:  a pointer to the value to decrement
  49. ** RETURN:
  50. **    the returned value is the result of the decrement
  51. */
  52. PR_EXTERN(PRInt32)    PR_AtomicDecrement(PRInt32 *val);
  53.  
  54. /*
  55. ** FUNCTION: PR_AtomicSet
  56. ** DESCRIPTION:
  57. **    Atomically set a 32 bit value.
  58. ** INPUTS:
  59. **    val: A pointer to a 32 bit value to be set
  60. **    newval: The newvalue to assign to val
  61. ** RETURN:
  62. **    Returns the prior value
  63. */
  64. PR_EXTERN(PRInt32) PR_AtomicSet(PRInt32 *val, PRInt32 newval);
  65.  
  66. /*
  67. ** FUNCTION: PR_AtomicAdd
  68. ** DESCRIPTION:
  69. **    Atomically add a 32 bit value.
  70. ** INPUTS:
  71. **    ptr:  a pointer to the value to increment
  72. **      val:  value to be added
  73. ** RETURN:
  74. **    the returned value is the result of the addition
  75. */
  76. PR_EXTERN(PRInt32)    PR_AtomicAdd(PRInt32 *ptr, PRInt32 val);
  77.  
  78. /*
  79. ** LIFO linked-list (stack)
  80. */
  81. typedef struct PRStackElemStr PRStackElem;
  82.  
  83. struct PRStackElemStr {
  84.     PRStackElem    *prstk_elem_next;    /* next pointer MUST be at offset 0;
  85.                                       assembly language code relies on this */
  86. };
  87.  
  88. typedef struct PRStackStr PRStack;
  89.  
  90. struct PRStackStr {
  91.     PRStackElem    prstk_head;            /* head MUST be at offset 0; assembly
  92.                                         language code relies on this
  93.                                     */
  94.     PRLock        *prstk_lock;
  95.     char        *prstk_name;
  96. };
  97.  
  98.  
  99. /*
  100. ** FUNCTION: PR_CreateStack
  101. ** DESCRIPTION:
  102. **    Create a stack, a LIFO linked list
  103. ** INPUTS:
  104. **    stack_name:  a pointer to string containing the name of the stack
  105. ** RETURN:
  106. **    A pointer to the created stack, if successful, else NULL.
  107. */
  108. PR_EXTERN(PRStack *)    PR_CreateStack(const char *stack_name);
  109.  
  110. /*
  111. ** FUNCTION: PR_StackPush
  112. ** DESCRIPTION:
  113. **    Push an element on the top of the stack
  114. ** INPUTS:
  115. **    stack:        pointer to the stack
  116. **    stack_elem:    pointer to the stack element
  117. ** RETURN:
  118. **    None
  119. */
  120. PR_EXTERN(void)            PR_StackPush(PRStack *stack, PRStackElem *stack_elem);
  121.  
  122. /*
  123. ** FUNCTION: PR_StackPop
  124. ** DESCRIPTION:
  125. **    Remove the element on the top of the stack
  126. ** INPUTS:
  127. **    stack:        pointer to the stack
  128. ** RETURN:
  129. **    A pointer to the stack element removed from the top of the stack,
  130. **      if non-empty,
  131. **    else NULL
  132. */
  133. PR_EXTERN(PRStackElem *)    PR_StackPop(PRStack *stack);
  134.  
  135. /*
  136. ** FUNCTION: PR_DestroyStack
  137. ** DESCRIPTION:
  138. **    Destroy the stack
  139. ** INPUTS:
  140. **    stack:        pointer to the stack
  141. ** RETURN:
  142. **    PR_SUCCESS - if successfully deleted
  143. **      PR_FAILURE - if the stack is not empty
  144. **                    PR_GetError will return
  145. **                        PR_INVALID_STATE_ERROR - stack is not empty
  146. */
  147. PR_EXTERN(PRStatus)        PR_DestroyStack(PRStack *stack);
  148.  
  149. PR_END_EXTERN_C
  150.  
  151. #endif /* pratom_h___ */
  152.