summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar archshift2014-09-02 22:40:02 -0700
committerGravatar archshift2014-09-02 22:40:02 -0700
commit4795a64fc8ff59fced28735e627deb7c3b4575ed (patch)
treeb8f6161609efdd649769624b649445923d24935c /src
parentMerge pull request #69 from yuriks/cmake-cleanup (diff)
downloadyuzu-4795a64fc8ff59fced28735e627deb7c3b4575ed.tar.gz
yuzu-4795a64fc8ff59fced28735e627deb7c3b4575ed.tar.xz
yuzu-4795a64fc8ff59fced28735e627deb7c3b4575ed.zip
Removed common/atomic, instead using std::atomic
Diffstat (limited to 'src')
-rw-r--r--src/common/CMakeLists.txt3
-rw-r--r--src/common/atomic.h16
-rw-r--r--src/common/atomic_gcc.h110
-rw-r--r--src/common/atomic_win32.h69
-rw-r--r--src/core/core_timing.cpp8
5 files changed, 4 insertions, 202 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index f8a55c2a7..55a5f9eba 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -23,9 +23,6 @@ set(SRCS
23 ) 23 )
24 24
25set(HEADERS 25set(HEADERS
26 atomic.h
27 atomic_gcc.h
28 atomic_win32.h
29 bit_field.h 26 bit_field.h
30 break_points.h 27 break_points.h
31 chunk_file.h 28 chunk_file.h
diff --git a/src/common/atomic.h b/src/common/atomic.h
deleted file mode 100644
index 941f5ad5e..000000000
--- a/src/common/atomic.h
+++ /dev/null
@@ -1,16 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#ifdef _WIN32
8
9#include "common/atomic_win32.h"
10
11#else
12
13// GCC-compatible compiler assumed!
14#include "common/atomic_gcc.h"
15
16#endif
diff --git a/src/common/atomic_gcc.h b/src/common/atomic_gcc.h
deleted file mode 100644
index 117e342f6..000000000
--- a/src/common/atomic_gcc.h
+++ /dev/null
@@ -1,110 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common.h"
8
9// Atomic operations are performed in a single step by the CPU. It is
10// impossible for other threads to see the operation "half-done."
11//
12// Some atomic operations can be combined with different types of memory
13// barriers called "Acquire semantics" and "Release semantics", defined below.
14//
15// Acquire semantics: Future memory accesses cannot be relocated to before the
16// operation.
17//
18// Release semantics: Past memory accesses cannot be relocated to after the
19// operation.
20//
21// These barriers affect not only the compiler, but also the CPU.
22
23namespace Common
24{
25
26inline void AtomicAdd(volatile u32& target, u32 value) {
27 __sync_add_and_fetch(&target, value);
28}
29
30inline void AtomicAnd(volatile u32& target, u32 value) {
31 __sync_and_and_fetch(&target, value);
32}
33
34inline void AtomicDecrement(volatile u32& target) {
35 __sync_add_and_fetch(&target, -1);
36}
37
38inline void AtomicIncrement(volatile u32& target) {
39 __sync_add_and_fetch(&target, 1);
40}
41
42inline u32 AtomicLoad(volatile u32& src) {
43 return src; // 32-bit reads are always atomic.
44}
45inline u32 AtomicLoadAcquire(volatile u32& src) {
46 //keep the compiler from caching any memory references
47 u32 result = src; // 32-bit reads are always atomic.
48 //__sync_synchronize(); // TODO: May not be necessary.
49 // Compiler instruction only. x86 loads always have acquire semantics.
50 __asm__ __volatile__ ( "":::"memory" );
51 return result;
52}
53
54inline void AtomicOr(volatile u32& target, u32 value) {
55 __sync_or_and_fetch(&target, value);
56}
57
58inline void AtomicStore(volatile u32& dest, u32 value) {
59 dest = value; // 32-bit writes are always atomic.
60}
61inline void AtomicStoreRelease(volatile u32& dest, u32 value) {
62 __sync_lock_test_and_set(&dest, value); // TODO: Wrong! This function is has acquire semantics.
63}
64
65}
66
67// Old code kept here for reference in case we need the parts with __asm__ __volatile__.
68#if 0
69LONG SyncInterlockedIncrement(LONG *Dest)
70{
71#if defined(__GNUC__) && defined (__GNUC_MINOR__) && ((4 < __GNUC__) || (4 == __GNUC__ && 1 <= __GNUC_MINOR__))
72 return __sync_add_and_fetch(Dest, 1);
73#else
74 register int result;
75 __asm__ __volatile__("lock; xadd %0,%1"
76 : "=r" (result), "=m" (*Dest)
77 : "0" (1), "m" (*Dest)
78 : "memory");
79 return result;
80#endif
81}
82
83LONG SyncInterlockedExchangeAdd(LONG *Dest, LONG Val)
84{
85#if defined(__GNUC__) && defined (__GNUC_MINOR__) && ((4 < __GNUC__) || (4 == __GNUC__ && 1 <= __GNUC_MINOR__))
86 return __sync_add_and_fetch(Dest, Val);
87#else
88 register int result;
89 __asm__ __volatile__("lock; xadd %0,%1"
90 : "=r" (result), "=m" (*Dest)
91 : "0" (Val), "m" (*Dest)
92 : "memory");
93 return result;
94#endif
95}
96
97LONG SyncInterlockedExchange(LONG *Dest, LONG Val)
98{
99#if defined(__GNUC__) && defined (__GNUC_MINOR__) && ((4 < __GNUC__) || (4 == __GNUC__ && 1 <= __GNUC_MINOR__))
100 return __sync_lock_test_and_set(Dest, Val);
101#else
102 register int result;
103 __asm__ __volatile__("lock; xchg %0,%1"
104 : "=r" (result), "=m" (*Dest)
105 : "0" (Val), "m" (*Dest)
106 : "memory");
107 return result;
108#endif
109}
110#endif
diff --git a/src/common/atomic_win32.h b/src/common/atomic_win32.h
deleted file mode 100644
index 0808905f0..000000000
--- a/src/common/atomic_win32.h
+++ /dev/null
@@ -1,69 +0,0 @@
1// Copyright 2013 Dolphin Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common.h"
8#include <intrin.h>
9#include <Windows.h>
10
11// Atomic operations are performed in a single step by the CPU. It is
12// impossible for other threads to see the operation "half-done."
13//
14// Some atomic operations can be combined with different types of memory
15// barriers called "Acquire semantics" and "Release semantics", defined below.
16//
17// Acquire semantics: Future memory accesses cannot be relocated to before the
18// operation.
19//
20// Release semantics: Past memory accesses cannot be relocated to after the
21// operation.
22//
23// These barriers affect not only the compiler, but also the CPU.
24//
25// NOTE: Acquire and Release are not differentiated right now. They perform a
26// full memory barrier instead of a "one-way" memory barrier. The newest
27// Windows SDK has Acquire and Release versions of some Interlocked* functions.
28
29namespace Common
30{
31
32inline void AtomicAdd(volatile u32& target, u32 value) {
33 InterlockedExchangeAdd((volatile LONG*)&target, (LONG)value);
34}
35
36inline void AtomicAnd(volatile u32& target, u32 value) {
37 _InterlockedAnd((volatile LONG*)&target, (LONG)value);
38}
39
40inline void AtomicIncrement(volatile u32& target) {
41 InterlockedIncrement((volatile LONG*)&target);
42}
43
44inline void AtomicDecrement(volatile u32& target) {
45 InterlockedDecrement((volatile LONG*)&target);
46}
47
48inline u32 AtomicLoad(volatile u32& src) {
49 return src; // 32-bit reads are always atomic.
50}
51inline u32 AtomicLoadAcquire(volatile u32& src) {
52 u32 result = src; // 32-bit reads are always atomic.
53 _ReadBarrier(); // Compiler instruction only. x86 loads always have acquire semantics.
54 return result;
55}
56
57inline void AtomicOr(volatile u32& target, u32 value) {
58 _InterlockedOr((volatile LONG*)&target, (LONG)value);
59}
60
61inline void AtomicStore(volatile u32& dest, u32 value) {
62 dest = value; // 32-bit writes are always atomic.
63}
64inline void AtomicStoreRelease(volatile u32& dest, u32 value) {
65 _WriteBarrier(); // Compiler instruction only. x86 stores always have release semantics.
66 dest = value; // 32-bit writes are always atomic.
67}
68
69}
diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp
index a4fc0aaa4..c30e36732 100644
--- a/src/core/core_timing.cpp
+++ b/src/core/core_timing.cpp
@@ -4,10 +4,10 @@
4 4
5#include <vector> 5#include <vector>
6#include <cstdio> 6#include <cstdio>
7#include <atomic>
7 8
8#include "common/msg_handler.h" 9#include "common/msg_handler.h"
9#include "common/std_mutex.h" 10#include "common/std_mutex.h"
10#include "common/atomic.h"
11#include "common/chunk_file.h" 11#include "common/chunk_file.h"
12 12
13#include "core/core_timing.h" 13#include "core/core_timing.h"
@@ -54,7 +54,7 @@ Event *eventPool = 0;
54Event *eventTsPool = 0; 54Event *eventTsPool = 0;
55int allocatedTsEvents = 0; 55int allocatedTsEvents = 0;
56// Optimization to skip MoveEvents when possible. 56// Optimization to skip MoveEvents when possible.
57volatile u32 hasTsEvents = false; 57std::atomic<u32> hasTsEvents;
58 58
59// Downcount has been moved to currentMIPS, to save a couple of clocks in every ARM JIT block 59// Downcount has been moved to currentMIPS, to save a couple of clocks in every ARM JIT block
60// as we can already reach that structure through a register. 60// as we can already reach that structure through a register.
@@ -202,7 +202,7 @@ void ScheduleEvent_Threadsafe(s64 cyclesIntoFuture, int event_type, u64 userdata
202 tsLast->next = ne; 202 tsLast->next = ne;
203 tsLast = ne; 203 tsLast = ne;
204 204
205 Common::AtomicStoreRelease(hasTsEvents, 1); 205 hasTsEvents.store(1, std::memory_order_release);
206} 206}
207 207
208// Same as ScheduleEvent_Threadsafe(0, ...) EXCEPT if we are already on the CPU thread 208// Same as ScheduleEvent_Threadsafe(0, ...) EXCEPT if we are already on the CPU thread
@@ -484,7 +484,7 @@ void ProcessFifoWaitEvents()
484 484
485void MoveEvents() 485void MoveEvents()
486{ 486{
487 Common::AtomicStoreRelease(hasTsEvents, 0); 487 hasTsEvents.store(0, std::memory_order_release);
488 488
489 std::lock_guard<std::recursive_mutex> lk(externalEventSection); 489 std::lock_guard<std::recursive_mutex> lk(externalEventSection);
490 // Move events from async queue into main queue 490 // Move events from async queue into main queue