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