summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2018-08-13 06:13:47 +0200
committerLioncash <mathew1800@gmail.com>2018-08-13 06:16:40 +0200
commit3476f5b4d38d31d6f17a335311a2fa814be8bf25 (patch)
treed0929304994c704ac6dd152a92d528c0e25d715b
parentMerge pull request #1043 from Subv/timing (diff)
downloadyuzu-3476f5b4d38d31d6f17a335311a2fa814be8bf25.tar
yuzu-3476f5b4d38d31d6f17a335311a2fa814be8bf25.tar.gz
yuzu-3476f5b4d38d31d6f17a335311a2fa814be8bf25.tar.bz2
yuzu-3476f5b4d38d31d6f17a335311a2fa814be8bf25.tar.lz
yuzu-3476f5b4d38d31d6f17a335311a2fa814be8bf25.tar.xz
yuzu-3476f5b4d38d31d6f17a335311a2fa814be8bf25.tar.zst
yuzu-3476f5b4d38d31d6f17a335311a2fa814be8bf25.zip
-rw-r--r--src/core/hle/kernel/kernel.cpp2
-rw-r--r--src/core/hle/kernel/object.h15
2 files changed, 9 insertions, 8 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 1b0cd0abf..8c19e86d3 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -11,7 +11,7 @@
namespace Kernel {
-unsigned int Object::next_object_id;
+std::atomic<u32> Object::next_object_id{0};
/// Initialize the kernel
void Init() {
diff --git a/src/core/hle/kernel/object.h b/src/core/hle/kernel/object.h
index 83df68dfd..526ac9cc3 100644
--- a/src/core/hle/kernel/object.h
+++ b/src/core/hle/kernel/object.h
@@ -4,6 +4,7 @@
#pragma once
+#include <atomic>
#include <string>
#include <utility>
@@ -42,8 +43,8 @@ public:
virtual ~Object();
/// Returns a unique identifier for the object. For debugging purposes only.
- unsigned int GetObjectId() const {
- return object_id;
+ u32 GetObjectId() const {
+ return object_id.load(std::memory_order_relaxed);
}
virtual std::string GetTypeName() const {
@@ -61,23 +62,23 @@ public:
bool IsWaitable() const;
public:
- static unsigned int next_object_id;
+ static std::atomic<u32> next_object_id;
private:
friend void intrusive_ptr_add_ref(Object*);
friend void intrusive_ptr_release(Object*);
- unsigned int ref_count = 0;
- unsigned int object_id = next_object_id++;
+ std::atomic<u32> ref_count{0};
+ std::atomic<u32> object_id{next_object_id++};
};
// Special functions used by boost::instrusive_ptr to do automatic ref-counting
inline void intrusive_ptr_add_ref(Object* object) {
- ++object->ref_count;
+ object->ref_count.fetch_add(1, std::memory_order_relaxed);
}
inline void intrusive_ptr_release(Object* object) {
- if (--object->ref_count == 0) {
+ if (object->ref_count.fetch_sub(1, std::memory_order_acq_rel) == 1) {
delete object;
}
}