Rename _look ==> _read and _take ==> _write
This commit is contained in:
1 parent
535ea729ed
commit
229f99585d
3 files changed
+28
-27
No files matched your search
@@ -2038,9 +2038,9 @@ Example:
|
|||||||
void f(unsigned int * i) {
|
void f(unsigned int * i) {
|
||||||
snapshot_uint_t t;
|
snapshot_uint_t t;
|
||||||
snapshot_uint_init(t);
|
snapshot_uint_init(t);
|
||||||
i = snapshot_uint_take(t);
|
i = snapshot_uint_write(t);
|
||||||
*i = 1;
|
*i = 1;
|
||||||
i = snapshot_uint_look(t);
|
i = snapshot_uint_read(t);
|
||||||
snapshot_uint_clear(t);
|
snapshot_uint_clear(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2085,16 +2085,17 @@ This function is not thread safe.
|
|||||||
This function is defined only if the underlying type has defined the
|
This function is defined only if the underlying type has defined the
|
||||||
MOVE operator.
|
MOVE operator.
|
||||||
|
|
||||||
##### type *name\_take(snapshot\_t snap)
|
##### type *name\_write(snapshot\_t snap)
|
||||||
|
|
||||||
Take an atomic snap of the active contain of the snapshot 'snap'.
|
Take an atomic snap of the active written contain of the snapshot 'snap'
|
||||||
It returns the pointer to the new active contain of the snapshot
|
and clotures it.
|
||||||
|
It returns the pointer to the new active written contain of the snapshot
|
||||||
(which is not snapped).
|
(which is not snapped).
|
||||||
This functions is thread-safe and performs atomic operation on the snapshot.
|
This functions is thread-safe and performs atomic operation on the snapshot.
|
||||||
|
|
||||||
##### type *name\_look(snapshot\_t snap)
|
##### type *name\_read(snapshot\_t snap)
|
||||||
|
|
||||||
Look at the last atomic snap of the active contain of the snapshot 'snap'.
|
Look at the last atomic snap of the active read contain of the snapshot 'snap'.
|
||||||
It returns the pointer to the data.
|
It returns the pointer to the data.
|
||||||
This functions is thread-safe and performs atomic operation on the snapshot.
|
This functions is thread-safe and performs atomic operation on the snapshot.
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -181,7 +181,7 @@
|
|||||||
,) /* IF_METHOD (MOVE) */ \
|
,) /* IF_METHOD (MOVE) */ \
|
||||||
\
|
\
|
||||||
\
|
\
|
||||||
static inline type *M_C(name, _take)(M_C(name, _t) snap) \
|
static inline type *M_C(name, _write)(M_C(name, _t) snap) \
|
||||||
{ \
|
{ \
|
||||||
SNAPSHOTI_CONTRACT(snap); \
|
SNAPSHOTI_CONTRACT(snap); \
|
||||||
unsigned char nextFlags, origFlags = atomic_load (&snap->flags); \
|
unsigned char nextFlags, origFlags = atomic_load (&snap->flags); \
|
||||||
@@ -198,7 +198,7 @@
|
|||||||
return &snap->data[SNAPSHOTI_W(nextFlags)]; \
|
return &snap->data[SNAPSHOTI_W(nextFlags)]; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline const type *M_C(name, _look)(M_C(name, _t) snap) \
|
static inline const type *M_C(name, _read)(M_C(name, _t) snap) \
|
||||||
{ \
|
{ \
|
||||||
SNAPSHOTI_CONTRACT(snap); \
|
SNAPSHOTI_CONTRACT(snap); \
|
||||||
unsigned char nextFlags, origFlags = atomic_load (&snap->flags); \
|
unsigned char nextFlags, origFlags = atomic_load (&snap->flags); \
|
||||||
|
|||||||
+18
-18
@@ -39,40 +39,40 @@ static void test_uint(void)
|
|||||||
snapshot_uint_t t;
|
snapshot_uint_t t;
|
||||||
snapshot_uint_init(t);
|
snapshot_uint_init(t);
|
||||||
|
|
||||||
p_r = snapshot_uint_look(t);
|
p_r = snapshot_uint_read(t);
|
||||||
assert (p_r == snapshot_uint_get_read_buffer(t));
|
assert (p_r == snapshot_uint_get_read_buffer(t));
|
||||||
assert(*p_r == 0);
|
assert(*p_r == 0);
|
||||||
assert(snapshot_uint_look(t) == p_r);
|
assert(snapshot_uint_read(t) == p_r);
|
||||||
|
|
||||||
p_w = snapshot_uint_take(t);
|
p_w = snapshot_uint_write(t);
|
||||||
assert (snapshot_uint_updated_p (t) == true);
|
assert (snapshot_uint_updated_p (t) == true);
|
||||||
assert (p_w != p_r);
|
assert (p_w != p_r);
|
||||||
*p_w = 1;
|
*p_w = 1;
|
||||||
assert (*p_r == 0);
|
assert (*p_r == 0);
|
||||||
assert (snapshot_uint_look(t) != p_r);
|
assert (snapshot_uint_read(t) != p_r);
|
||||||
assert (snapshot_uint_updated_p (t) == false);
|
assert (snapshot_uint_updated_p (t) == false);
|
||||||
assert (*snapshot_uint_look(t) == 0);
|
assert (*snapshot_uint_read(t) == 0);
|
||||||
p_r = snapshot_uint_look(t);
|
p_r = snapshot_uint_read(t);
|
||||||
assert (*p_r == 0);
|
assert (*p_r == 0);
|
||||||
|
|
||||||
p_w = snapshot_uint_take(t);
|
p_w = snapshot_uint_write(t);
|
||||||
*p_w = 2;
|
*p_w = 2;
|
||||||
assert (*snapshot_uint_look(t) == 1);
|
assert (*snapshot_uint_read(t) == 1);
|
||||||
|
|
||||||
p_w = snapshot_uint_take(t);
|
p_w = snapshot_uint_write(t);
|
||||||
assert (p_w == snapshot_uint_get_write_buffer(t));
|
assert (p_w == snapshot_uint_get_write_buffer(t));
|
||||||
*p_w = 3;
|
*p_w = 3;
|
||||||
p_w = snapshot_uint_take(t);
|
p_w = snapshot_uint_write(t);
|
||||||
*p_w = 4;
|
*p_w = 4;
|
||||||
assert (*snapshot_uint_look(t) == 3);
|
assert (*snapshot_uint_read(t) == 3);
|
||||||
|
|
||||||
snapshot_uint_t t2;
|
snapshot_uint_t t2;
|
||||||
snapshot_uint_init_set (t2, t);
|
snapshot_uint_init_set (t2, t);
|
||||||
snapshot_uint_clear(t);
|
snapshot_uint_clear(t);
|
||||||
assert (*snapshot_uint_look(t) == 3);
|
assert (*snapshot_uint_read(t) == 3);
|
||||||
snapshot_uint_init(t);
|
snapshot_uint_init(t);
|
||||||
snapshot_uint_set (t, t2);
|
snapshot_uint_set (t, t2);
|
||||||
assert (*snapshot_uint_look(t) == 3);
|
assert (*snapshot_uint_read(t) == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -96,7 +96,7 @@ static void conso(void *arg)
|
|||||||
{
|
{
|
||||||
assert (arg == NULL);
|
assert (arg == NULL);
|
||||||
while (true) {
|
while (true) {
|
||||||
const data_t *p = snapshot_data_look(g_buff);
|
const data_t *p = snapshot_data_read(g_buff);
|
||||||
assert (p->n == -p->p);
|
assert (p->n == -p->p);
|
||||||
assert (p->n == ~p->c);
|
assert (p->n == ~p->c);
|
||||||
if (p->n == 0)
|
if (p->n == 0)
|
||||||
@@ -111,11 +111,11 @@ static void prod(void *arg)
|
|||||||
for(unsigned int i = 1; i < 100000;i++) {
|
for(unsigned int i = 1; i < 100000;i++) {
|
||||||
p->n = i * i;
|
p->n = i * i;
|
||||||
data_crc(p);
|
data_crc(p);
|
||||||
p = snapshot_data_take(g_buff);
|
p = snapshot_data_write(g_buff);
|
||||||
}
|
}
|
||||||
p->n = 0;
|
p->n = 0;
|
||||||
data_crc(p);
|
data_crc(p);
|
||||||
p = snapshot_data_take(g_buff);
|
p = snapshot_data_write(g_buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_global(void)
|
static void test_global(void)
|
||||||
@@ -123,10 +123,10 @@ static void test_global(void)
|
|||||||
m_thread_t idx[2];
|
m_thread_t idx[2];
|
||||||
|
|
||||||
snapshot_data_init(g_buff);
|
snapshot_data_init(g_buff);
|
||||||
data_t *p = snapshot_data_take(g_buff);
|
data_t *p = snapshot_data_write(g_buff);
|
||||||
p->n = 42;
|
p->n = 42;
|
||||||
data_crc(p);
|
data_crc(p);
|
||||||
p = snapshot_data_take(g_buff);
|
p = snapshot_data_write(g_buff);
|
||||||
|
|
||||||
m_thread_create (idx[0], conso, NULL);
|
m_thread_create (idx[0], conso, NULL);
|
||||||
m_thread_create (idx[1], prod, NULL);
|
m_thread_create (idx[1], prod, NULL);
|
||||||
|
|||||||
Reference in new issue
Block a user