Skip to content

Commit

Permalink
set an explicit memory fence between stored series inserts and count …
Browse files Browse the repository at this point in the history
…increments (morganstanley#267)
  • Loading branch information
kthielen authored and chenkai036 committed Jun 7, 2019
1 parent 12c7fac commit 4d7d8e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/hobbes/db/series.C
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

#include <hobbes/db/series.H>
#include <atomic>

namespace hobbes {

Expand Down Expand Up @@ -328,6 +329,9 @@ void RawStoredSeries::record(const void* v, bool signal) {
// store this data at the stream head
this->storeFn(this->outputFile, v, this->batchHead);

// fence data storage and count increment
std::atomic_thread_fence(std::memory_order_release);

// then advance the stream head
// (allocate a new batch cell if necessary)
this->batchHead += this->storageSize;
Expand Down Expand Up @@ -686,6 +690,10 @@ const MonoTypePtr& CompressedStoredSeries::storageType() const {
// (assumes that all such values are passed by reference)
void CompressedStoredSeries::record(const void* x, bool signal) {
this->writeFn(&this->w, this->dynModel, x);

// fence data storage and count increment
std::atomic_thread_fence(std::memory_order_release);

if (this->w.step()) {
this->prepMFn(&this->w, this->dynModel);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/hobbes/db/signals.C
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <hobbes/hobbes.H>
#include <vector>
#include <set>
#include <atomic>
#include <string.h>
#include <errno.h>

Expand Down Expand Up @@ -51,6 +52,10 @@ struct FileWatch {
};

void sweepFileWatch(FileWatch& fw) {
// if we get a signal to read, we should be able to read everything up to the signal
std::atomic_thread_fence(std::memory_order_acquire);

// check whether any value updates signal changes
for (auto brwi = fw.byteRangeWatches.begin(); brwi != fw.byteRangeWatches.end();) {
auto& brwp = *brwi;
ByteRangeWatch& brw = brwp.second;
Expand Down

0 comments on commit 4d7d8e8

Please sign in to comment.