Back to index

lightning-sunbird  0.9+nobinonly
pratom.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /* GLOBAL FUNCTIONS:
00039 ** DESCRIPTION:
00040 **     PR Atomic operations
00041 */
00042 
00043 #ifndef pratom_h___
00044 #define pratom_h___
00045 
00046 #include "prtypes.h"
00047 #include "prlock.h"
00048 
00049 PR_BEGIN_EXTERN_C
00050 
00051 /*
00052 ** FUNCTION: PR_AtomicIncrement
00053 ** DESCRIPTION:
00054 **    Atomically increment a 32 bit value.
00055 ** INPUTS:
00056 **    val:  a pointer to the value to increment
00057 ** RETURN:
00058 **    the returned value is the result of the increment
00059 */
00060 NSPR_API(PRInt32)    PR_AtomicIncrement(PRInt32 *val);
00061 
00062 /*
00063 ** FUNCTION: PR_AtomicDecrement
00064 ** DESCRIPTION:
00065 **    Atomically decrement a 32 bit value.
00066 ** INPUTS:
00067 **    val:  a pointer to the value to decrement
00068 ** RETURN:
00069 **    the returned value is the result of the decrement
00070 */
00071 NSPR_API(PRInt32)    PR_AtomicDecrement(PRInt32 *val);
00072 
00073 /*
00074 ** FUNCTION: PR_AtomicSet
00075 ** DESCRIPTION:
00076 **    Atomically set a 32 bit value.
00077 ** INPUTS:
00078 **    val: A pointer to a 32 bit value to be set
00079 **    newval: The newvalue to assign to val
00080 ** RETURN:
00081 **    Returns the prior value
00082 */
00083 NSPR_API(PRInt32) PR_AtomicSet(PRInt32 *val, PRInt32 newval);
00084 
00085 /*
00086 ** FUNCTION: PR_AtomicAdd
00087 ** DESCRIPTION:
00088 **    Atomically add a 32 bit value.
00089 ** INPUTS:
00090 **    ptr:  a pointer to the value to increment
00091 **       val:  value to be added
00092 ** RETURN:
00093 **    the returned value is the result of the addition
00094 */
00095 NSPR_API(PRInt32)    PR_AtomicAdd(PRInt32 *ptr, PRInt32 val);
00096 
00097 /*
00098 ** LIFO linked-list (stack)
00099 */
00100 typedef struct PRStackElemStr PRStackElem;
00101 
00102 struct PRStackElemStr {
00103     PRStackElem      *prstk_elem_next;    /* next pointer MUST be at offset 0;
00104                                                                  assembly language code relies on this */
00105 };
00106 
00107 typedef struct PRStackStr PRStack;
00108 
00109 /*
00110 ** FUNCTION: PR_CreateStack
00111 ** DESCRIPTION:
00112 **    Create a stack, a LIFO linked list
00113 ** INPUTS:
00114 **    stack_name:  a pointer to string containing the name of the stack
00115 ** RETURN:
00116 **    A pointer to the created stack, if successful, else NULL.
00117 */
00118 NSPR_API(PRStack *)  PR_CreateStack(const char *stack_name);
00119 
00120 /*
00121 ** FUNCTION: PR_StackPush
00122 ** DESCRIPTION:
00123 **    Push an element on the top of the stack
00124 ** INPUTS:
00125 **    stack:         pointer to the stack
00126 **    stack_elem:    pointer to the stack element
00127 ** RETURN:
00128 **    None
00129 */
00130 NSPR_API(void)                     PR_StackPush(PRStack *stack, PRStackElem *stack_elem);
00131 
00132 /*
00133 ** FUNCTION: PR_StackPop
00134 ** DESCRIPTION:
00135 **    Remove the element on the top of the stack
00136 ** INPUTS:
00137 **    stack:         pointer to the stack
00138 ** RETURN:
00139 **    A pointer to the stack element removed from the top of the stack,
00140 **       if non-empty,
00141 **    else NULL
00142 */
00143 NSPR_API(PRStackElem *)     PR_StackPop(PRStack *stack);
00144 
00145 /*
00146 ** FUNCTION: PR_DestroyStack
00147 ** DESCRIPTION:
00148 **    Destroy the stack
00149 ** INPUTS:
00150 **    stack:         pointer to the stack
00151 ** RETURN:
00152 **    PR_SUCCESS - if successfully deleted
00153 **       PR_FAILURE - if the stack is not empty
00154 **                                 PR_GetError will return
00155 **                                        PR_INVALID_STATE_ERROR - stack is not empty
00156 */
00157 NSPR_API(PRStatus)          PR_DestroyStack(PRStack *stack);
00158 
00159 PR_END_EXTERN_C
00160 
00161 #endif /* pratom_h___ */