The Mozilla
Organization
At A Glance
Feedback
Get Involved
Newsgroups
License Terms
Newsbot
Developer Docs
Roadmap
Projects
Ports
Module Owners
Hacking
Get the Source
Build It
Testing
Download
Bugzilla
Bug Writing
Tools
View Source
Tree Status
New Checkins
Submit A Bug
FAQ
Search
[Contents] [Previous] [Next] [Last]

Chapter 12
Atomic Operations

This chapter describes the global functions you use to perform atomic operations. The functions define a portable API that may be reliably used in any environment. Since not all operating environments provide access to such functions, their performance may vary considerably.

Atomic Operations Functions

The API defined for the atomic functions is consistent across all supported platforms. However, the implementation may vary greatly, and hence the performance. On systems that do not provide direct access to atomic operators, NSPR emulates the capabilities by using its own locking mechanisms. For such systems, NSPR performs atomic operations just as efficiently as the client could. Therefore, to preserve portability, it is recommended that clients use the NSPR API for atomic operations.

PR_AtomicIncrement
PR_AtomicDecrement
PR_AtomicSet

PR_AtomicIncrement

Atomically increments a 32-bit value.

Syntax
#include <pratom.h> 
PRInt32 PR_AtomicIncrement(PRInt32 *val);
Parameter
The function has the following parameter:

val
A pointer to the value to increment.

Returns
The function returns a value of the field after it was incremented (i.e., the result)

Description
The referenced variable is incremented by one. The result of the function is the value of the memory after the operation. The writing of the memory is unconditional.

PR_AtomicDecrement

Atomically decrements a 32-bit value.

Syntax
#include <pratom.h> 
PRInt32 PR_AtomicDecrement(PRInt32 *val);
Parameter
The function has the following parameter:

val
A pointer to the value to decrement.

Returns
The function returns a value of the memory after the decrement, (i.e., the result).

Description
PR_AtomicDecrement first decrements the referenced variable by one. The value returned is the referenced variable's final value. The modification to memory is unconditional.

PR_AtomicSet

Atomically sets a 32-bit value and return its previous contents.

Syntax
#include <pratom.h> 
PRInt32 PR_AtomicSet(
    PRInt32 *val,
    PRInt32 newval);
Parameters
The function has the following parameters:

val
A pointer to the value to be set.

newval
The new value to assign to the val parameter.

Returns
The function returns the prior value of the referenced variable.

Description
PR_AtomicSet first reads the value of var, then updates it with the supplied value. The returned value is the value that was read before memory was updated. The memory modification is unconditional--that is, it is not a test and set operation.


[Contents] [Previous] [Next] [Last]

Last Updated: Mon Jul 13 18:15:01 PDT 1998


Copyright © 1998 Netscape Communications Corporation

Copyright © 1998-1999 The Mozilla Organization.
Last modified July 17, 1998.