1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
/*
* Copyright (c) 2002-2018 Balabit
* Copyright (c) 2018 Laszlo Budai <laszlo.budai@balabit.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
#ifndef ATOMIC_GSSIZE_H_INCLUDED
#define ATOMIC_GSSIZE_H_INCLUDED
#include "syslog-ng.h"
G_STATIC_ASSERT(sizeof(gssize) == sizeof(gpointer));
typedef struct
{
gssize value;
} atomic_gssize;
static inline gssize
atomic_gssize_add(atomic_gssize *a, gssize add)
{
return g_atomic_pointer_add(&a->value, add);
}
static inline gssize
atomic_gssize_sub(atomic_gssize *a, gssize sub)
{
return g_atomic_pointer_add(&a->value, -1 * sub);
}
static inline gssize
atomic_gssize_inc(atomic_gssize *a)
{
return g_atomic_pointer_add(&a->value, 1);
}
static inline gssize
atomic_gssize_dec(atomic_gssize *a)
{
return g_atomic_pointer_add(&a->value, -1);
}
static inline gssize
atomic_gssize_get(atomic_gssize *a)
{
return (gssize)g_atomic_pointer_get(&a->value);
}
static inline void
atomic_gssize_set(atomic_gssize *a, gssize value)
{
g_atomic_pointer_set(&a->value, value);
}
static inline gsize
atomic_gssize_get_unsigned(atomic_gssize *a)
{
return (gsize)g_atomic_pointer_get(&a->value);
}
static inline gssize
atomic_gssize_racy_get(atomic_gssize *a)
{
return a->value;
}
static inline gsize
atomic_gssize_racy_get_unsigned(atomic_gssize *a)
{
return (gsize)a->value;
}
static inline void
atomic_gssize_racy_set(atomic_gssize *a, gssize value)
{
a->value = value;
}
static inline gsize
atomic_gssize_or(atomic_gssize *a, gsize value)
{
return g_atomic_pointer_or(&a->value, value);
}
static inline gsize
atomic_gssize_xor(atomic_gssize *a, gsize value)
{
return g_atomic_pointer_xor(&a->value, value);
}
static inline gsize
atomic_gssize_and(atomic_gssize *a, gsize value)
{
return g_atomic_pointer_and(&a->value, value);
}
static inline gboolean
atomic_gssize_compare_and_exchange(atomic_gssize *a, gssize oldval, gssize newval)
{
return g_atomic_pointer_compare_and_exchange(&a->value, oldval, newval);
}
static inline gssize
atomic_gssize_set_and_get(atomic_gssize *a, gssize value)
{
gssize oldval = atomic_gssize_get(a);
while (!atomic_gssize_compare_and_exchange(a,
oldval,
value))
{
oldval = atomic_gssize_get(a);
}
return oldval;
}
#endif
|