qbatomic.h | qbatomic.h | |||
---|---|---|---|---|
skipping to change at line 28 | skipping to change at line 28 | |||
*/ | */ | |||
/* | /* | |||
* Copied from the glib code base (glib/gatomic.h) and namespaced | * Copied from the glib code base (glib/gatomic.h) and namespaced | |||
* for libqb. | * for libqb. | |||
*/ | */ | |||
#ifndef QB_ATOMIC_DEFINED | #ifndef QB_ATOMIC_DEFINED | |||
#define QB_ATOMIC_DEFINED | #define QB_ATOMIC_DEFINED | |||
/* *INDENT-OFF* */ | ||||
#ifdef __cplusplus | ||||
extern "C" { | ||||
#endif | ||||
/* *INDENT-ON* */ | ||||
#include <stdint.h> | #include <stdint.h> | |||
#include <qb/qbdefs.h> | #include <qb/qbdefs.h> | |||
#include <qb/qbconfig.h> | ||||
/** | /** | |||
* @file | * @file | |||
* Basic atomic integer and pointer operations | * Basic atomic integer and pointer operations | |||
* | * | |||
* The following functions can be used to atomically access integers and | * The following functions can be used to atomically access integers and | |||
* pointers. They are implemented as inline assembler function on most | * pointers. They are implemented as inline assembler function on most | |||
* platforms and use slower fall-backs otherwise. Using them can sometimes | * platforms and use slower fall-backs otherwise. Using them can sometimes | |||
* save you from using a performance-expensive pthread_mutex to protect the | * save you from using a performance-expensive pthread_mutex to protect the | |||
* integer or pointer. | * integer or pointer. | |||
skipping to change at line 64 | skipping to change at line 71 | |||
* in the foot. So if in doubt, use a pthread_mutex. If you don't know, wha t | * in the foot. So if in doubt, use a pthread_mutex. If you don't know, wha t | |||
* memory barriers are, do not use anything but qb_atomic_int_inc() and | * memory barriers are, do not use anything but qb_atomic_int_inc() and | |||
* qb_atomic_int_dec_and_test(). | * qb_atomic_int_dec_and_test(). | |||
* | * | |||
* It is not safe to set an integer or pointer just by assigning | * 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 follow ing | * to it, when it is concurrently accessed by other threads with the follow ing | |||
* functions. Use qb_atomic_int_compare_and_exchange() or | * functions. Use qb_atomic_int_compare_and_exchange() or | |||
* qb_atomic_pointer_compare_and_exchange() respectively. | * qb_atomic_pointer_compare_and_exchange() respectively. | |||
*/ | */ | |||
/* *INDENT-OFF* */ | ||||
#ifdef __cplusplus | ||||
extern "C" { | ||||
#endif | ||||
/* *INDENT-ON* */ | ||||
void qb_atomic_init(void); | void qb_atomic_init(void); | |||
/** | /** | |||
* Atomically adds val to the integer pointed to by atomic. | * Atomically adds val to the integer pointed to by atomic. | |||
* It returns the value of *atomic just before the addition | * It returns the value of *atomic just before the addition | |||
* took place. Also acts as a memory barrier. | * took place. Also acts as a memory barrier. | |||
* | * | |||
* @param atomic a pointer to an integer | * @param atomic a pointer to an integer | |||
* @param val the value to add to *atomic | * @param val the value to add to *atomic | |||
* @return the value of *atomic before the addition. | * @return the value of *atomic before the addition. | |||
skipping to change at line 166 | skipping to change at line 167 | |||
* @param newval the new value | * @param newval the new value | |||
* | * | |||
*/ | */ | |||
void qb_atomic_pointer_set(volatile void* QB_GNUC_MAY_ALIAS * atomic, | void qb_atomic_pointer_set(volatile void* QB_GNUC_MAY_ALIAS * atomic, | |||
void* newval); | void* newval); | |||
#ifndef QB_ATOMIC_OP_MEMORY_BARRIER_NEEDED | #ifndef QB_ATOMIC_OP_MEMORY_BARRIER_NEEDED | |||
#define qb_atomic_int_get(atomic) ((int32_t)*(atomic)) | #define qb_atomic_int_get(atomic) ((int32_t)*(atomic)) | |||
#define qb_atomic_int_set(atomic, newval) ((void) (*(atomic) = (newval ))) | #define qb_atomic_int_set(atomic, newval) ((void) (*(atomic) = (newval ))) | |||
#define qb_atomic_pointer_get(atomic) ((void*)*(atomic)) | #define qb_atomic_pointer_get(atomic) ((void*)*(atomic)) | |||
#define qb_atomic_pointer_set(atomic, newval) ((void) (*(atomic) = (newval ))) | #define qb_atomic_pointer_set(atomic, newval) ((void*) (*(atomic) = (newva l))) | |||
#else | #else | |||
#define qb_atomic_int_get(atomic) \ | #define qb_atomic_int_get(atomic) \ | |||
((void) sizeof (char* [sizeof (*(atomic)) == sizeof (int32_t) ? 1 : -1]), \ | ((void) sizeof (char* [sizeof (*(atomic)) == sizeof (int32_t) ? 1 : -1]), \ | |||
(qb_atomic_int_get) ((volatile int32_t QB_GNUC_MAY_ALIAS *) (volatile voi d *) (atomic))) | (qb_atomic_int_get) ((volatile int32_t QB_GNUC_MAY_ALIAS *) (volatile voi d *) (atomic))) | |||
#define qb_atomic_int_set(atomic, newval) \ | #define qb_atomic_int_set(atomic, newval) \ | |||
((void) sizeof (char* [sizeof (*(atomic)) == sizeof (int32_t) ? 1 : -1]), \ | ((void) sizeof (char* [sizeof (*(atomic)) == sizeof (int32_t) ? 1 : -1]), \ | |||
(qb_atomic_int_set) ((volatile int32_t QB_GNUC_MAY_ALIAS *) (volatile voi d *) (atomic), (newval))) | (qb_atomic_int_set) ((volatile int32_t QB_GNUC_MAY_ALIAS *) (volatile voi d *) (atomic), (newval))) | |||
#define qb_atomic_pointer_get(atomic) \ | #define qb_atomic_pointer_get(atomic) \ | |||
((void) sizeof (char* [sizeof (*(atomic)) == sizeof (void*) ? 1 : -1]), \ | ((void) sizeof (char* [sizeof (*(atomic)) == sizeof (void*) ? 1 : -1]), \ | |||
(qb_atomic_pointer_get) ((volatile void QB_GNUC_MAY_ALIAS *) (volatile vo id *) (atomic))) | (qb_atomic_pointer_get) ((volatile void* QB_GNUC_MAY_ALIAS *) (volatile v oid *) (atomic))) | |||
#define qb_atomic_pointer_set(atomic, newval) \ | #define qb_atomic_pointer_set(atomic, newval) \ | |||
((void) sizeof (char* [sizeof (*(atomic)) == sizeof (void*) ? 1 : -1]), \ | ((void) sizeof (char* [sizeof (*(atomic)) == sizeof (void*) ? 1 : -1]), \ | |||
(qb_atomic_pointer_set) ((volatile void QB_GNUC_MAY_ALIAS *) (volatile vo id *) (atomic), (newval))) | (qb_atomic_pointer_set) ((volatile void* QB_GNUC_MAY_ALIAS *) (volatile v oid *) (atomic), (newval))) | |||
#endif /* QB_ATOMIC_OP_MEMORY_BARRIER_NEEDED */ | #endif /* QB_ATOMIC_OP_MEMORY_BARRIER_NEEDED */ | |||
/** | /** | |||
* Atomically increments the integer pointed to by atomic by 1. | * Atomically increments the integer pointed to by atomic by 1. | |||
* | * | |||
* @param atomic a pointer to an integer. | * @param atomic a pointer to an integer. | |||
*/ | */ | |||
#define qb_atomic_int_inc(atomic) (qb_atomic_int_add ((atomic), 1)) | #define qb_atomic_int_inc(atomic) (qb_atomic_int_add ((atomic), 1)) | |||
/** | /** | |||
End of changes. 6 change blocks. | ||||
9 lines changed or deleted | 10 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |