Skip to content

Commit bb4826a

Browse files
author
ccr
committed
fix: shm messge lost
1 parent 38ae485 commit bb4826a

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

cyber/transport/shm/condition_notifier.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ bool ConditionNotifier::Notify(const ReadableInfo& info) {
6363
uint64_t seq = indicator_->next_seq.fetch_add(1);
6464
uint64_t idx = seq % kBufLength;
6565
indicator_->infos[idx] = info;
66-
indicator_->seqs[idx] = seq;
66+
indicator_->seqs[idx].store(seq, std::memory_order_release);
6767

6868
return true;
6969
}
@@ -84,7 +84,7 @@ bool ConditionNotifier::Listen(int timeout_ms, ReadableInfo* info) {
8484
uint64_t seq = indicator_->next_seq.load();
8585
if (seq != next_seq_) {
8686
auto idx = next_seq_ % kBufLength;
87-
auto actual_seq = indicator_->seqs[idx];
87+
auto actual_seq = indicator_->seqs[idx].load(std::memory_order_acquire);
8888
if (actual_seq >= next_seq_) {
8989
next_seq_ = actual_seq;
9090
*info = indicator_->infos[idx];

cyber/transport/shm/condition_notifier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ConditionNotifier : public NotifierBase {
3434
struct Indicator {
3535
std::atomic<uint64_t> next_seq = {0};
3636
ReadableInfo infos[kBufLength];
37-
uint64_t seqs[kBufLength] = {0};
37+
std::atomic<uint64_t> seqs[kBufLength] = {0};
3838
};
3939

4040
public:

0 commit comments

Comments
 (0)