mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-30 10:42:47 +01:00
threadsafe_queue: Use std::size_t for representing size
Makes it consistent with the regular standard containers in terms of size representation. This also gets rid of dependence on our own type aliases, removing the need for an include.
This commit is contained in:
parent
f0bfb24c61
commit
0829ef97ca
1 changed files with 6 additions and 7 deletions
|
@ -7,11 +7,10 @@
|
||||||
// a simple lockless thread-safe,
|
// a simple lockless thread-safe,
|
||||||
// single reader, single writer queue
|
// single reader, single writer queue
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include "common/common_types.h"
|
#include <utility>
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -25,7 +24,7 @@ public:
|
||||||
delete read_ptr;
|
delete read_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 Size() const {
|
std::size_t Size() const {
|
||||||
return size.load();
|
return size.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +86,7 @@ private:
|
||||||
// and a pointer to the next ElementPtr
|
// and a pointer to the next ElementPtr
|
||||||
class ElementPtr {
|
class ElementPtr {
|
||||||
public:
|
public:
|
||||||
ElementPtr() : next(nullptr) {}
|
ElementPtr() {}
|
||||||
~ElementPtr() {
|
~ElementPtr() {
|
||||||
ElementPtr* next_ptr = next.load();
|
ElementPtr* next_ptr = next.load();
|
||||||
|
|
||||||
|
@ -96,12 +95,12 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
T current;
|
T current;
|
||||||
std::atomic<ElementPtr*> next;
|
std::atomic<ElementPtr*> next{nullptr};
|
||||||
};
|
};
|
||||||
|
|
||||||
ElementPtr* write_ptr;
|
ElementPtr* write_ptr;
|
||||||
ElementPtr* read_ptr;
|
ElementPtr* read_ptr;
|
||||||
std::atomic<u32> size{0};
|
std::atomic_size_t size{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
// a simple thread-safe,
|
// a simple thread-safe,
|
||||||
|
@ -110,7 +109,7 @@ private:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class MPSCQueue {
|
class MPSCQueue {
|
||||||
public:
|
public:
|
||||||
u32 Size() const {
|
std::size_t Size() const {
|
||||||
return spsc_queue.Size();
|
return spsc_queue.Size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue