qbatomic.h - Online Linux Manual PageSection : 3
Updated : 11 May 2016
Source : Version 0.17.1
Note : libqb
NAMEqbatomic.h − Basic atomic integer and pointer operations.
SYNOPSIS
#include <stdint.h>
#include <qb/qbdefs.h>
#include <qb/qbconfig.h>
Defines#define qb_atomic_int_get(atomic) ((int32_t)*(atomic))
#define qb_atomic_int_set(atomic, newval) ((void) (*(atomic) = (newval)))
#define qb_atomic_pointer_get(atomic) ((void*)*(atomic))
#define qb_atomic_pointer_set(atomic, newval) ((void*) (*(atomic) = (newval)))
#define qb_atomic_int_inc(atomic) (qb_atomic_int_add ((atomic), 1))
Atomically increments the integer pointed to by atomic by 1. #define qb_atomic_int_dec_and_test(atomic) (qb_atomic_int_exchange_and_add ((atomic), -1) == 1)
Atomically decrements the integer pointed to by atomic by 1.
Functionsvoid qb_atomic_init (void)
int32_t qb_atomic_int_exchange_and_add (volatile int32_t QB_GNUC_MAY_ALIAS *atomic, int32_t val)
Atomically adds val to the integer pointed to by atomic. void qb_atomic_int_add (volatile int32_t QB_GNUC_MAY_ALIAS *atomic, int32_t val)
Atomically adds val to the integer pointed to by atomic. int32_t qb_atomic_int_compare_and_exchange (volatile int32_t QB_GNUC_MAY_ALIAS *atomic, int32_t oldval, int32_t newval)
Compares oldval with the integer pointed to by atomic and if they are equal, atomically exchanges *atomic with newval. int32_t qb_atomic_pointer_compare_and_exchange (volatile void *QB_GNUC_MAY_ALIAS *atomic, void *oldval, void *newval)
Compares oldval with the pointer pointed to by atomic and if they are equal, atomically exchanges *atomic with newval. int32_t qb_atomic_int_get (volatile int32_t QB_GNUC_MAY_ALIAS *atomic)
Reads the value of the integer pointed to by atomic. void qb_atomic_int_set (volatile int32_t QB_GNUC_MAY_ALIAS *atomic, int32_t newval)
Sets the value of the integer pointed to by atomic. void * qb_atomic_pointer_get (volatile void *QB_GNUC_MAY_ALIAS *atomic)
Reads the value of the pointer pointed to by atomic. void qb_atomic_pointer_set (volatile void *QB_GNUC_MAY_ALIAS *atomic, void *newval)
Sets the value of the pointer pointed to by atomic.
Detailed DescriptionBasic atomic integer and pointer operations. The following functions can be used to atomically access integers and pointers. They are implemented as inline assembler function on most platforms and use slower fall-backs otherwise. Using them can sometimes save you from using a performance-expensive pthread_mutex to protect the integer or pointer. The most important usage is reference counting. Using qb_atomic_int_inc() and qb_atomic_int_dec_and_test() makes reference counting a very fast operation. You must not directly read integers or pointers concurrently accessed by multiple threads, but use the atomic accessor functions instead. That is, always use qb_atomic_int_get() and qb_atomic_pointer_get() for read outs. They provide the neccessary synchonization mechanisms like memory barriers to access memory locations concurrently. If you are using those functions for anything apart from simple reference counting, you should really be aware of the implications of doing that. There are literally thousands of ways to shoot yourself in the foot. So if in doubt, use a pthread_mutex. If you don't know, what memory barriers are, do not use anything but qb_atomic_int_inc() and qb_atomic_int_dec_and_test(). It is not safe to set an integer or pointer just by assigning to it, when it is concurrently accessed by other threads with the following functions. Use qb_atomic_int_compare_and_exchange() or qb_atomic_pointer_compare_and_exchange() respectively.
Define Documentation
#define qb_atomic_int_dec_and_test(atomic) (qb_atomic_int_exchange_and_add ((atomic), -1) == 1)Atomically decrements the integer pointed to by atomic by 1. Parameters: atomic a pointer to an integer Returns: QB_TRUE if the integer pointed to by atomic is 0 after decrementing it
#define qb_atomic_int_get(atomic) ((int32_t)*(atomic))
#define qb_atomic_int_inc(atomic) (qb_atomic_int_add ((atomic), 1))Atomically increments the integer pointed to by atomic by 1. Parameters: atomic a pointer to an integer.
#define qb_atomic_int_set(atomic, newval) ((void) (*(atomic) = (newval)))
#define qb_atomic_pointer_get(atomic) ((void*)*(atomic))
#define qb_atomic_pointer_set(atomic, newval) ((void*) (*(atomic) = (newval)))
Function Documentation
void qb_atomic_init (void)
void qb_atomic_int_add (volatile int32_t QB_GNUC_MAY_ALIAS * atomic, int32_t val)Atomically adds val to the integer pointed to by atomic. Also acts as a memory barrier. Parameters: atomic a pointer to an integer
val the value to add to *atomic
int32_t qb_atomic_int_compare_and_exchange (volatile int32_t QB_GNUC_MAY_ALIAS * atomic, int32_t oldval, int32_t newval)Compares oldval with the integer pointed to by atomic and if they are equal, atomically exchanges *atomic with newval. Also acts as a memory barrier. Parameters: atomic a pointer to an integer
oldval the assumed old value of *atomic
newval the new value of *atomic Returns: QB_TRUE, if *atomic was equal oldval. QB_FALSE otherwise.
int32_t qb_atomic_int_exchange_and_add (volatile int32_t QB_GNUC_MAY_ALIAS * atomic, int32_t val)Atomically adds val to the integer pointed to by atomic. It returns the value of *atomic just before the addition took place. Also acts as a memory barrier. Parameters: atomic a pointer to an integer
val the value to add to *atomic Returns: the value of *atomic before the addition.
int32_t qb_atomic_int_get (volatile int32_t QB_GNUC_MAY_ALIAS * atomic)Reads the value of the integer pointed to by atomic. Also acts as a memory barrier. Parameters: atomic a pointer to an integer Returns: the value of atomic
void qb_atomic_int_set (volatile int32_t QB_GNUC_MAY_ALIAS * atomic, int32_t newval)Sets the value of the integer pointed to by atomic. Also acts as a memory barrier. Parameters: atomic a pointer to an integer
newval the new value
int32_t qb_atomic_pointer_compare_and_exchange (volatile void *QB_GNUC_MAY_ALIAS * atomic, void * oldval, void * newval)Compares oldval with the pointer pointed to by atomic and if they are equal, atomically exchanges *atomic with newval. Also acts as a memory barrier. Parameters: atomic a pointer to a void*
oldval the assumed old value of *atomic
newval the new value of *atomic Returns: QB_TRUE if atomic was equal oldval, else QB_FALSE.
void* qb_atomic_pointer_get (volatile void *QB_GNUC_MAY_ALIAS * atomic)Reads the value of the pointer pointed to by atomic. Also acts as a memory barrier. Parameters: atomic a pointer to a void*. Returns: the value to add to atomic.
void qb_atomic_pointer_set (volatile void *QB_GNUC_MAY_ALIAS * atomic, void * newval)Sets the value of the pointer pointed to by atomic. Also acts as a memory barrier. Parameters: atomic a pointer to a void*
newval the new value
AuthorGenerated automatically by Doxygen for libqb from the source code. 0
Johanes Gumabo
Data Size : 35,107 byte
man-qbatomic.h.3Build : 2024-12-05, 20:55 :
Visitor Screen : x
Visitor Counter ( page / site ) : 6 / 171,184
Visitor ID : :
Visitor IP : 13.58.32.115 :
Visitor Provider : AMAZON-02 :
Provider Position ( lat x lon ) : 39.962500 x -83.006100 : x
Provider Accuracy Radius ( km ) : 1000 :
Provider City : Columbus :
Provider Province : Ohio , : ,
Provider Country : United States :
Provider Continent : North America :
Visitor Recorder : Version :
Visitor Recorder : Library :
Online Linux Manual Page : Version : Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page : Library : lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page : Library : lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base : Version : Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base : Library : lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36
Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.