-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunsafe_concurrent_guard.h
More file actions
49 lines (42 loc) · 1.4 KB
/
Copy pathunsafe_concurrent_guard.h
File metadata and controls
49 lines (42 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef SW_SHARED_PTR_UNSAFE_CONCURRENT_GUARD_H
#define SW_SHARED_PTR_UNSAFE_CONCURRENT_GUARD_H
#include "concurrent_guard.h"
template <class T>
class unsafe_concurrent_guard: public concurrent_guard<T> {
public:
unsafe_concurrent_guard(): concurrent_guard<T>() {}
bool try_set_unsafe(T* pointer) {
uintptr_t expected;
uintptr_t desired = reinterpret_cast<uintptr_t>(pointer) + addValue;
do {
expected = this->data.load(memory_order_acquire);
int a = 2;
if(expected > 0) {
return false;
}
} while (!this->data.compare_exchange_weak(expected, desired));
return true;
}
cg_shared_ptr<T> try_set_and_get_unsafe(T* pointer) {
cg_shared_ptr<T> result;
uintptr_t expected;
uintptr_t desired = reinterpret_cast<uintptr_t>(pointer) + addTwoValue;
do {
expected = this->data.load(memory_order_acquire);
int a = 2;
if(expected > 0) {
//cout << " > 0" << endl;
return result;
}
else {
//cout << " ======= 0" << endl;
}
} while (!this->data.compare_exchange_weak(expected, desired));
result.host = this;
return result;
}
void decrease_unsafe() {
this->decrease_counter();
}
};
#endif //SW_SHARED_PTR_UNSAFE_CONCURRENT_GUARD_H