Externalized currentWrite

This commit is contained in:
Patrick Pelissier committed 2018-02-17 20:21:53 +01:00
1 parent b37cd7dba7
commit 20be2d8850
1 file changed
+7 -3
+7 -3
View File
@@ -334,10 +334,9 @@ static inline unsigned int snapshot_mrsw_int_get_write_idx(const snapshot_mrsw_i
return s->currentWrite; return s->currentWrite;
} }
static inline unsigned int snapshot_mrsw_int_write(snapshot_mrsw_int_t s) static inline unsigned int snapshot_mrsw_int_write_idx(snapshot_mrsw_int_t s, unsigned int idx)
{ {
SNAPSHOTI_MRSW_INT_CONTRACT(s); SNAPSHOTI_MRSW_INT_CONTRACT(s);
unsigned int idx = s->currentWrite;
unsigned int newNext, previous = atomic_load(&s->lastNext); unsigned int newNext, previous = atomic_load(&s->lastNext);
do { do {
newNext = SNAPSHOTI_MRSW_INT_FLAG(idx, true); newNext = SNAPSHOTI_MRSW_INT_FLAG(idx, true);
@@ -359,11 +358,16 @@ static inline unsigned int snapshot_mrsw_int_write(snapshot_mrsw_int_t s)
assert (atomic_load(&s->cptTab[idx]) == 0); assert (atomic_load(&s->cptTab[idx]) == 0);
atomic_store(&s->cptTab[idx], 1); atomic_store(&s->cptTab[idx], 1);
} }
s->currentWrite = idx;
SNAPSHOTI_MRSW_INT_CONTRACT(s); SNAPSHOTI_MRSW_INT_CONTRACT(s);
return idx; return idx;
} }
static inline unsigned int snapshot_mrsw_int_write(snapshot_mrsw_int_t s)
{
s->currentWrite = snapshot_mrsw_int_write_idx(s, s->currentWrite);
return s->currentWrite;
}
static inline unsigned int snapshot_mrsw_int_read_start(snapshot_mrsw_int_t s) static inline unsigned int snapshot_mrsw_int_read_start(snapshot_mrsw_int_t s)
{ {
SNAPSHOTI_MRSW_INT_CONTRACT(s); SNAPSHOTI_MRSW_INT_CONTRACT(s);