Panda3D
Loading...
Searching...
No Matches
atomicAdjustGccImpl.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file atomicAdjustGccImpl.h
10 * @author rdb
11 * @date 2014-07-04
12 */
13
14#ifndef ATOMICADJUSTGCCIMPL_H
15#define ATOMICADJUSTGCCIMPL_H
16
17#include "dtoolbase.h"
18#include "selectThreadImpl.h"
19
20#if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))) || (defined(__clang__) && (__clang_major__ >= 3))
21
22/**
23 * Uses GCC built-ins to implement atomic adjustments.
24 */
25class EXPCL_DTOOL_DTOOLBASE AtomicAdjustGccImpl {
26public:
27#if __GCC_ATOMIC_LONG_LOCK_FREE >= __GCC_ATOMIC_INT_LOCK_FREE
28 // If the long can be more lock-free than int, use it instead.
29 typedef __attribute__ ((aligned (__SIZEOF_LONG__))) long Integer;
30#else
31 typedef __attribute__ ((aligned (__SIZEOF_INT__))) int Integer;
32#endif
33 typedef void *UnalignedPointer;
34 typedef __attribute__ ((aligned (__SIZEOF_POINTER__))) UnalignedPointer Pointer;
35
36 INLINE static void inc(TVOLATILE Integer &var);
37 INLINE static bool dec(TVOLATILE Integer &var);
38 INLINE static Integer add(TVOLATILE Integer &var, Integer delta);
39 INLINE static Integer set(TVOLATILE Integer &var, Integer new_value);
40 INLINE static Integer get(const TVOLATILE Integer &var);
41
42 INLINE static Pointer set_ptr(TVOLATILE Pointer &var, Pointer new_value);
43 INLINE static Pointer get_ptr(const TVOLATILE Pointer &var);
44
45 INLINE static Integer compare_and_exchange(TVOLATILE Integer &mem,
46 Integer old_value,
47 Integer new_value);
48
49 INLINE static Pointer compare_and_exchange_ptr(TVOLATILE Pointer &mem,
50 Pointer old_value,
51 Pointer new_value);
52};
53
54#include "atomicAdjustGccImpl.I"
55
56#endif // HAVE_POSIX_THREADS
57
58#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.