summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/atomic_ops.cpp37
-rw-r--r--src/common/atomic_ops.h10
-rw-r--r--src/common/logging/backend.cpp22
-rw-r--r--src/common/logging/backend.h14
4 files changed, 41 insertions, 42 deletions
diff --git a/src/common/atomic_ops.cpp b/src/common/atomic_ops.cpp
index 1098e21ff..1612d0e67 100644
--- a/src/common/atomic_ops.cpp
+++ b/src/common/atomic_ops.cpp
@@ -14,50 +14,55 @@ namespace Common {
14 14
15#if _MSC_VER 15#if _MSC_VER
16 16
17bool AtomicCompareAndSwap(u8 volatile* pointer, u8 value, u8 expected) { 17bool AtomicCompareAndSwap(volatile u8* pointer, u8 value, u8 expected) {
18 u8 result = _InterlockedCompareExchange8((char*)pointer, value, expected); 18 const u8 result =
19 _InterlockedCompareExchange8(reinterpret_cast<volatile char*>(pointer), value, expected);
19 return result == expected; 20 return result == expected;
20} 21}
21 22
22bool AtomicCompareAndSwap(u16 volatile* pointer, u16 value, u16 expected) { 23bool AtomicCompareAndSwap(volatile u16* pointer, u16 value, u16 expected) {
23 u16 result = _InterlockedCompareExchange16((short*)pointer, value, expected); 24 const u16 result =
25 _InterlockedCompareExchange16(reinterpret_cast<volatile short*>(pointer), value, expected);
24 return result == expected; 26 return result == expected;
25} 27}
26 28
27bool AtomicCompareAndSwap(u32 volatile* pointer, u32 value, u32 expected) { 29bool AtomicCompareAndSwap(volatile u32* pointer, u32 value, u32 expected) {
28 u32 result = _InterlockedCompareExchange((long*)pointer, value, expected); 30 const u32 result =
31 _InterlockedCompareExchange(reinterpret_cast<volatile long*>(pointer), value, expected);
29 return result == expected; 32 return result == expected;
30} 33}
31 34
32bool AtomicCompareAndSwap(u64 volatile* pointer, u64 value, u64 expected) { 35bool AtomicCompareAndSwap(volatile u64* pointer, u64 value, u64 expected) {
33 u64 result = _InterlockedCompareExchange64((__int64*)pointer, value, expected); 36 const u64 result = _InterlockedCompareExchange64(reinterpret_cast<volatile __int64*>(pointer),
37 value, expected);
34 return result == expected; 38 return result == expected;
35} 39}
36 40
37bool AtomicCompareAndSwap(u64 volatile* pointer, u128 value, u128 expected) { 41bool AtomicCompareAndSwap(volatile u64* pointer, u128 value, u128 expected) {
38 return _InterlockedCompareExchange128((__int64*)pointer, value[1], value[0], 42 return _InterlockedCompareExchange128(reinterpret_cast<volatile __int64*>(pointer), value[1],
39 (__int64*)expected.data()) != 0; 43 value[0],
44 reinterpret_cast<__int64*>(expected.data())) != 0;
40} 45}
41 46
42#else 47#else
43 48
44bool AtomicCompareAndSwap(u8 volatile* pointer, u8 value, u8 expected) { 49bool AtomicCompareAndSwap(volatile u8* pointer, u8 value, u8 expected) {
45 return __sync_bool_compare_and_swap(pointer, expected, value); 50 return __sync_bool_compare_and_swap(pointer, expected, value);
46} 51}
47 52
48bool AtomicCompareAndSwap(u16 volatile* pointer, u16 value, u16 expected) { 53bool AtomicCompareAndSwap(volatile u16* pointer, u16 value, u16 expected) {
49 return __sync_bool_compare_and_swap(pointer, expected, value); 54 return __sync_bool_compare_and_swap(pointer, expected, value);
50} 55}
51 56
52bool AtomicCompareAndSwap(u32 volatile* pointer, u32 value, u32 expected) { 57bool AtomicCompareAndSwap(volatile u32* pointer, u32 value, u32 expected) {
53 return __sync_bool_compare_and_swap(pointer, expected, value); 58 return __sync_bool_compare_and_swap(pointer, expected, value);
54} 59}
55 60
56bool AtomicCompareAndSwap(u64 volatile* pointer, u64 value, u64 expected) { 61bool AtomicCompareAndSwap(volatile u64* pointer, u64 value, u64 expected) {
57 return __sync_bool_compare_and_swap(pointer, expected, value); 62 return __sync_bool_compare_and_swap(pointer, expected, value);
58} 63}
59 64
60bool AtomicCompareAndSwap(u64 volatile* pointer, u128 value, u128 expected) { 65bool AtomicCompareAndSwap(volatile u64* pointer, u128 value, u128 expected) {
61 unsigned __int128 value_a; 66 unsigned __int128 value_a;
62 unsigned __int128 expected_a; 67 unsigned __int128 expected_a;
63 std::memcpy(&value_a, value.data(), sizeof(u128)); 68 std::memcpy(&value_a, value.data(), sizeof(u128));
diff --git a/src/common/atomic_ops.h b/src/common/atomic_ops.h
index e6181d521..8d6b73c00 100644
--- a/src/common/atomic_ops.h
+++ b/src/common/atomic_ops.h
@@ -8,10 +8,10 @@
8 8
9namespace Common { 9namespace Common {
10 10
11bool AtomicCompareAndSwap(u8 volatile* pointer, u8 value, u8 expected); 11bool AtomicCompareAndSwap(volatile u8* pointer, u8 value, u8 expected);
12bool AtomicCompareAndSwap(u16 volatile* pointer, u16 value, u16 expected); 12bool AtomicCompareAndSwap(volatile u16* pointer, u16 value, u16 expected);
13bool AtomicCompareAndSwap(u32 volatile* pointer, u32 value, u32 expected); 13bool AtomicCompareAndSwap(volatile u32* pointer, u32 value, u32 expected);
14bool AtomicCompareAndSwap(u64 volatile* pointer, u64 value, u64 expected); 14bool AtomicCompareAndSwap(volatile u64* pointer, u64 value, u64 expected);
15bool AtomicCompareAndSwap(u64 volatile* pointer, u128 value, u128 expected); 15bool AtomicCompareAndSwap(volatile u64* pointer, u128 value, u128 expected);
16 16
17} // namespace Common 17} // namespace Common
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 04bc3128f..62cfde397 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -113,19 +113,19 @@ private:
113 Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, 113 Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr,
114 const char* function, std::string message) const { 114 const char* function, std::string message) const {
115 using std::chrono::duration_cast; 115 using std::chrono::duration_cast;
116 using std::chrono::microseconds;
116 using std::chrono::steady_clock; 117 using std::chrono::steady_clock;
117 118
118 Entry entry; 119 return {
119 entry.timestamp = 120 .timestamp = duration_cast<microseconds>(steady_clock::now() - time_origin),
120 duration_cast<std::chrono::microseconds>(steady_clock::now() - time_origin); 121 .log_class = log_class,
121 entry.log_class = log_class; 122 .log_level = log_level,
122 entry.log_level = log_level; 123 .filename = filename,
123 entry.filename = filename; 124 .line_num = line_nr,
124 entry.line_num = line_nr; 125 .function = function,
125 entry.function = function; 126 .message = std::move(message),
126 entry.message = std::move(message); 127 .final_entry = false,
127 128 };
128 return entry;
129 } 129 }
130 130
131 std::mutex writing_mutex; 131 std::mutex writing_mutex;
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h
index fc338c70d..e5d702568 100644
--- a/src/common/logging/backend.h
+++ b/src/common/logging/backend.h
@@ -21,19 +21,13 @@ class Filter;
21 */ 21 */
22struct Entry { 22struct Entry {
23 std::chrono::microseconds timestamp; 23 std::chrono::microseconds timestamp;
24 Class log_class; 24 Class log_class{};
25 Level log_level; 25 Level log_level{};
26 const char* filename; 26 const char* filename = nullptr;
27 unsigned int line_num; 27 unsigned int line_num = 0;
28 std::string function; 28 std::string function;
29 std::string message; 29 std::string message;
30 bool final_entry = false; 30 bool final_entry = false;
31
32 Entry() = default;
33 Entry(Entry&& o) = default;
34
35 Entry& operator=(Entry&& o) = default;
36 Entry& operator=(const Entry& o) = default;
37}; 31};
38 32
39/** 33/**