1QBATOMIC.H(3)              libqb Programmer's Manual             QBATOMIC.H(3)
2
3
4

NAME

6       qbatomic.h
7

SYNOPSIS

9       #include <qb/qbatomic.h>
10

DESCRIPTION

12       Basic atomic integer and pointer operations
13
14       The  following  functions can be used to atomically access integers and
15       pointers. They are implemented as inline  assembler  function  on  most
16       platforms and use slower fall-backs otherwise. Using them can sometimes
17       save you from using a performance-expensive  pthread_mutex  to  protect
18       the integer or pointer.
19
20       The    most    important    usage    is   reference   counting.   Using
21       qb_atomic_int_inc() and  qb_atomic_int_dec_and_test()  makes  reference
22       counting a very fast operation.
23
24       You  must  not directly read integers or pointers concurrently accessed
25       by multiple threads, but use the  atomic  accessor  functions  instead.
26       That is, always use qb_atomic_int_get() and qb_atomic_pointer_get() for
27       read outs. They provide the necessary synchronization  mechanisms  like
28       memory barriers to access memory locations concurrently.
29
30       If  you are using those functions for anything apart from simple refer‐
31       ence counting, you should really be aware of the implications of  doing
32       that.  There  are  literally thousands of ways to shoot yourself in the
33       foot. So if in doubt, use a pthread_mutex. If you don't know, what mem‐
34       ory  barriers  are,  do  not  use  anything but qb_atomic_int_inc() and
35       qb_atomic_int_dec_and_test().
36
37       It is not safe to set an integer or pointer just by  assigning  to  it,
38       when  it  is  concurrently accessed by other threads with the following
39       functions.      Use       qb_atomic_int_compare_and_exchange()       or
40       qb_atomic_pointer_compare_and_exchange() respectively.
41

SEE ALSO

43       qb_atomic_int_set(3), qb_atomic_int_compare_and_exchange(3),
44       qb_atomic_int_get(3), qb_atomic_int_add(3), qb_atomic_init(3),
45       qb_atomic_pointer_get(3), qb_atomic_int_exchange_and_add(3),
46       qb_atomic_pointer_compare_and_exchange(3), qb_atomic_pointer_set(3)
47
49       Copyright (C) 2010-2020 Red Hat, Inc. All rights reserved.
50
51
52
53LIBQB                             2020-07-30                     QBATOMIC.H(3)
Impressum