Skip to content

Commit

Permalink
fix: shm messge lost
Browse files Browse the repository at this point in the history
  • Loading branch information
ccr committed Jan 9, 2025
1 parent 38ae485 commit bb4826a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cyber/transport/shm/condition_notifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool ConditionNotifier::Notify(const ReadableInfo& info) {
uint64_t seq = indicator_->next_seq.fetch_add(1);
uint64_t idx = seq % kBufLength;
indicator_->infos[idx] = info;
indicator_->seqs[idx] = seq;
indicator_->seqs[idx].store(seq, std::memory_order_release);

return true;
}
Expand All @@ -84,7 +84,7 @@ bool ConditionNotifier::Listen(int timeout_ms, ReadableInfo* info) {
uint64_t seq = indicator_->next_seq.load();
if (seq != next_seq_) {
auto idx = next_seq_ % kBufLength;
auto actual_seq = indicator_->seqs[idx];
auto actual_seq = indicator_->seqs[idx].load(std::memory_order_acquire);
if (actual_seq >= next_seq_) {
next_seq_ = actual_seq;
*info = indicator_->infos[idx];
Expand Down
2 changes: 1 addition & 1 deletion cyber/transport/shm/condition_notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ConditionNotifier : public NotifierBase {
struct Indicator {
std::atomic<uint64_t> next_seq = {0};
ReadableInfo infos[kBufLength];
uint64_t seqs[kBufLength] = {0};
std::atomic<uint64_t> seqs[kBufLength] = {0};
};

public:
Expand Down

0 comments on commit bb4826a

Please sign in to comment.