Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual pr 0.7 main #513

Merged
merged 4 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.linux.x86-64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
runs-on: ubuntu-latest
container:
image: ghcr.io/coldwings/photon-ut-base:latest
options: --cpus 4
options: --cpus 4 --privileged
steps:
- uses: szenius/set-timezone@v1.2
with:
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
runs-on: ubuntu-latest
container:
image: ghcr.io/coldwings/photon-ut-base:latest
options: --cpus 4
options: --cpus 4 --privileged
steps:
- uses: szenius/set-timezone@v1.2
with:
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
runs-on: ubuntu-latest
container:
image: ghcr.io/coldwings/photon-ut-base:latest
options: --cpus 4
options: --cpus 4 --privileged
steps:
- uses: szenius/set-timezone@v1.2
with:
Expand Down Expand Up @@ -175,7 +175,7 @@ jobs:
runs-on: ubuntu-latest
container:
image: ghcr.io/coldwings/photon-ut-base:latest
options: --cpus 4
options: --cpus 4 --privileged
steps:
- uses: szenius/set-timezone@v1.2
with:
Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:
runs-on: ubuntu-latest
container:
image: ghcr.io/coldwings/photon-ut-base:latest
options: --cpus 4
options: --cpus 4 --privileged
steps:
- uses: szenius/set-timezone@v1.2
with:
Expand Down
28 changes: 8 additions & 20 deletions common/lockfree_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class LockfreeMPMCRingQueue : public LockfreeRingQueueBase<T, N> {
using Base::empty;
using Base::full;

bool push_weak(const T& x) {
bool push(const T& x) {
auto t = tail.load(std::memory_order_acquire);
for (;;) {
auto& slot = slots[idx(t)];
Expand All @@ -194,15 +194,16 @@ class LockfreeMPMCRingQueue : public LockfreeRingQueueBase<T, N> {
}
} else {
auto const prevTail = t;
auto h = head.load(std::memory_order_acquire);
t = tail.load(std::memory_order_acquire);
if (t == prevTail) {
if (t == prevTail && Base::check_full(h, t)) {
return false;
}
}
}
}

bool pop_weak(T& x) {
bool pop(T& x) {
auto h = head.load(std::memory_order_acquire);
for (;;) {
auto& slot = slots[idx(h)];
Expand All @@ -215,28 +216,15 @@ class LockfreeMPMCRingQueue : public LockfreeRingQueueBase<T, N> {
}
} else {
auto const prevHead = h;
auto t = tail.load(std::memory_order_acquire);
h = head.load(std::memory_order_acquire);
if (h == prevHead) {
if (h == prevHead && Base::check_empty(h, t)) {
return false;
}
}
}
}

bool push(const T& x) {
do {
if (push_weak(x)) return true;
} while (!full());
return false;
}

bool pop(T& x) {
do {
if (pop_weak(x)) return true;
} while (!empty());
return false;
}

template <typename Pause = ThreadPause>
void send(const T& x) {
static_assert(std::is_base_of<PauseBase, Pause>::value,
Expand Down Expand Up @@ -538,8 +526,8 @@ namespace common {
* and load balancing.
* Watch out that `recv` should run in photon environment (because it has to)
* use photon semaphore to be notified that new item has sended. `send` could
* running in photon or std::thread environment (needs to set template `Pause` as
* `ThreadPause`).
* running in photon or std::thread environment (needs to set template `Pause`
* as `ThreadPause`).
*
* @tparam QueueType shoulde be one of LockfreeMPMCRingQueue,
* LockfreeBatchMPMCRingQueue, or LockfreeSPSCRingQueue, with their own template
Expand Down
2 changes: 1 addition & 1 deletion examples/sync-primitive/sync-primitive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ int main() {
while (true) {
func_1us();
Message* m;
bool ok = ring.pop_weak(m);
bool ok = ring.pop(m);
if (!ok)
continue;
m->start = std::chrono::steady_clock::now();
Expand Down
Loading