Panda3D
 All Classes Functions Variables Enumerations
atomicAdjust.h
1 // Filename: atomicAdjust.h
2 // Created by: drose (09Aug02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef ATOMICADJUST_H
16 #define ATOMICADJUST_H
17 
18 #include "dtoolbase.h"
19 #include "selectThreadImpl.h"
20 
21 #if defined(CPPPARSER)
22 
23 struct AtomicAdjust {
24  typedef long Integer;
25  typedef void *UnalignedPointer;
26  typedef UnalignedPointer Pointer;
27 };
28 
29 #elif defined(THREAD_DUMMY_IMPL) || defined(THREAD_SIMPLE_IMPL)
30 
31 #include "atomicAdjustDummyImpl.h"
33 
34 #elif (defined(__i386__) || defined(_M_IX86)) && !defined(__APPLE__)
35 // For an i386 architecture, we'll always use the i386 implementation.
36 // It should be safe for any OS, and it might be a bit faster than
37 // any OS-provided calls.
38 
39 #include "atomicAdjustI386Impl.h"
40 typedef AtomicAdjustI386Impl AtomicAdjust;
41 
42 // These symbols are defined if the compare_and_exchange() methods are
43 // implemented natively, without recourse to external locks. If these
44 // are not defined, users may elect to implement an operation with
45 // some other method than compare_and_exchange(), which might be
46 // faster.
47 #define HAVE_ATOMIC_COMPARE_AND_EXCHANGE 1
48 #define HAVE_ATOMIC_COMPARE_AND_EXCHANGE_PTR 1
49 
50 #elif (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))) || (defined(__clang__) && (__clang_major__ >= 3))
51 // GCC 4.7 and above has built-in __atomic functions for atomic operations.
52 // Clang 3.0 and above also supports them.
53 
54 #include "atomicAdjustGccImpl.h"
55 typedef AtomicAdjustGccImpl AtomicAdjust;
56 
57 #if (__GCC_ATOMIC_INT_LOCK_FREE + __GCC_ATOMIC_INT_LOCK_FREE) > 0
58 #define HAVE_ATOMIC_COMPARE_AND_EXCHANGE 1
59 #endif
60 #if __GCC_ATOMIC_POINTER_LOCK_FREE > 0
61 #define HAVE_ATOMIC_COMPARE_AND_EXCHANGE_PTR 1
62 #endif
63 
64 #elif defined(THREAD_WIN32_IMPL)
65 
66 #include "atomicAdjustWin32Impl.h"
67 typedef AtomicAdjustWin32Impl AtomicAdjust;
68 
69 #define HAVE_ATOMIC_COMPARE_AND_EXCHANGE 1
70 #define HAVE_ATOMIC_COMPARE_AND_EXCHANGE_PTR 1
71 
72 #elif defined(THREAD_LINUX_IMPL)
73 
74 #error Linux native threads are currently implemented only for i386; use Posix threads instead.
75 
76 #elif defined(THREAD_POSIX_IMPL)
77 
78 #include "atomicAdjustPosixImpl.h"
79 typedef AtomicAdjustPosixImpl AtomicAdjust;
80 
81 #endif
82 
83 #endif
A trivial implementation for atomic adjustments for systems that don't require multiprogramming, and therefore don't require special atomic operations.