Skip to content

Commit 263f5c0

Browse files
committed
fixed atomic issues with buffers
1 parent 32f02d5 commit 263f5c0

4 files changed

Lines changed: 6 additions & 9 deletions

File tree

code/core/OS/Buffer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ namespace OS {
3939
resetCursors();
4040
}
4141
Buffer::~Buffer() {
42-
mp_ctx->DecRef();
43-
int ref = mp_ctx->GetRefCount();
44-
if (ref == 0) {
42+
if (mp_ctx->DecRef() == 0) {
4543
delete mp_ctx;
4644
}
4745
}

code/core/OS/Buffer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ namespace OS {
6060

6161
Buffer &operator=(const Buffer& val) {
6262
if(mp_ctx) {
63-
mp_ctx->DecRef();
64-
if (mp_ctx->GetRefCount() == 0) {
63+
if (mp_ctx->DecRef() == 0) {
6564
delete mp_ctx;
6665
}
6766
}

code/core/OS/Net/NetPeer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ void INetPeer::CloseSocket() {
137137
}
138138
void INetPeer::close_callback(uv_handle_t *handle) {
139139
INetPeer *peer = (INetPeer *)uv_handle_get_data(handle);
140-
peer->DecRef();
141-
if(peer->GetRefCount() == 0) {
140+
141+
if(peer->DecRef() == 0) {
142142
delete peer;
143143
}
144144

code/core/OS/Ref.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace OS {
55
class Ref {
66
public:
77
Ref() { m_ref_count.store(1); };
8-
void DecRef() { m_ref_count--; };
9-
void IncRef() { m_ref_count++; };
8+
uint32_t DecRef() { return m_ref_count.fetch_sub(1)-1; };
9+
uint32_t IncRef() { return m_ref_count.fetch_add(1)+1; };
1010
int GetRefCount() { return m_ref_count.load(); };
1111
private:
1212
std::atomic<uint32_t> m_ref_count;

0 commit comments

Comments
 (0)