14.20. Slapi_Counter

Provides 64-bit integers with support for atomic operations, even on 32-bit systems. Slapi_Counter allows plug-ins to use global integers that can be updated by multiple worker threads in a thread-safe manner.
The Slapi_Counter structure is a wrapper around the actual counter value.
A mutex is used on platforms that do not provide 64-bit atomic operations.
Syntax

#include "slapi-plugin.h" 
typedef struct Slapi_Counter {
    PRUint64 value;
#ifndef ATOMIC_64BIT_OPERATIONS
    Slapi_Mutex *mutex;
#endif
} Slapi_Counter;

Associated Functions

Slapi_Counter defines settings for counters. The different functions available to Slapi_Counter structures are listed in Table 14.13, “Functions for Slapi_Counter”.

Table 14.13. Functions for Slapi_Counter

To ... ... Call this function
Create a new counter. slapi_counter_new()
Initialize a new counter. slapi_counter_init()
Increment the counter value and return the new value. slapi_counter_increment()
Decrement the counter and return the new value. slapi_counter_decrement()
Add a certain amount to the counter value. slapi_counter_add()
Subtract a certain amount from the counter value. slapi_counter_subtract()
Set the counter to a new, specified value and returns the updated value. slapi_counter_set_value()
Get the current value of the counter. slapi_counter_get_value()
Destroy an existing counter. slapi_counter_destroy()