Port to new memory model:
Communication thread buffer needs to use the global pool, and not a local pool, since the allocation is done accross several threads. Therefore the non thread fixed queue & stack interfaces are moved into a dedicated header (m-queue) and remove support for non thread stack & queue into m-buffer Remove also deprecated policy too.
This commit is contained in:
1 parent
a7294abe0c
commit
01f5228a36
10 files changed
+224
-371
No files matched your search
@@ -198,6 +198,7 @@ SYNTHESIS_DATA= M-ALGO test-malgo.c.c test-malgo.synt \
|
||||
M-GENINT ../m-genint.h test-mgenint.synt \
|
||||
M-I-LIST test-milist.c.c test-milist.synt \
|
||||
M-I-SHARED test-mishared.c.c test-mishared.synt \
|
||||
M-QUEUE test-mqueue.c.c test-mqueue.synt \
|
||||
M-LIST test-mlist.c.c test-mlist.synt \
|
||||
M-MEMPOOL test-mmempool.c.c test-mmempool.synt \
|
||||
M-PRIOQUEUE test-mprioqueue.c.c test-mprioqueue.synt \
|
||||
|
||||
@@ -125,6 +125,9 @@
|
||||
#define M_TR33_CONTRACT(...) (void)0
|
||||
#undef M_TR33_IT_CONTRACT
|
||||
#define M_TR33_IT_CONTRACT(...) (void)0
|
||||
#undef M_QUEU3_CONTRACT
|
||||
#define M_QUEU3_CONTRACT(...) (void)0
|
||||
|
||||
/* Overwrite M_UNLIKELY_NOMEM so that it can never fails, to avoid spurious coverage */
|
||||
#undef M_UNLIKELY_NOMEM
|
||||
#define M_UNLIKELY_NOMEM(...) 0
|
||||
|
||||
+22
-74
@@ -26,19 +26,16 @@
|
||||
|
||||
START_COVERAGE
|
||||
// Define a fixed queue of unsigned int
|
||||
BUFFER_DEF(buffer_uint, unsigned int, 10, BUFFER_QUEUE|BUFFER_BLOCKING)
|
||||
BUFFER_DEF(buffer_uint, unsigned int, 10, BUFFER_QUEUE)
|
||||
QUEUE_MPMC_DEF(queue_uint, unsigned int, BUFFER_QUEUE)
|
||||
QUEUE_SPSC_DEF(squeue_uint, unsigned int, BUFFER_QUEUE)
|
||||
END_COVERAGE
|
||||
|
||||
// Define a variable stack of float
|
||||
BUFFER_DEF(buffer_floats, float, 0, BUFFER_STACK|BUFFER_BLOCKING)
|
||||
BUFFER_DEF(buffer_floats, float, 0, BUFFER_STACK)
|
||||
|
||||
// Define a fixed stack of char
|
||||
BUFFER_DEF(buffer_char, char, 10, BUFFER_STACK|BUFFER_UNBLOCKING)
|
||||
|
||||
// Define a fixed queue of long long
|
||||
BUFFER_DEF(buffer_llong, long long, 16, BUFFER_QUEUE|BUFFER_THREAD_UNSAFE|BUFFER_UNBLOCKING)
|
||||
BUFFER_DEF(buffer_char, char, 10, BUFFER_STACK)
|
||||
|
||||
// Define a buffer of complex structure.
|
||||
BUFFER_DEF(buffer_mpz, testobj_t, 32, BUFFER_QUEUE, TESTOBJ_OPLIST)
|
||||
@@ -170,8 +167,7 @@ static void test_global(void)
|
||||
assert (buffer_uint_size(g_buffB) == 5);
|
||||
for(unsigned int i = 0; i < 5;i++) {
|
||||
unsigned int j;
|
||||
bool b= buffer_uint_pop(&j, g_buffB);
|
||||
assert(b);
|
||||
buffer_uint_pop(&j, g_buffB);
|
||||
assert(j == i);
|
||||
}
|
||||
assert (buffer_uint_empty_p(g_buffB));
|
||||
@@ -182,8 +178,7 @@ static void test_global(void)
|
||||
assert (buffer_uint_size(g_buffB) == 5);
|
||||
for(unsigned int i = 0; i < 5;i++) {
|
||||
unsigned int j;
|
||||
bool b= buffer_uint_pop(&j, g_buffB);
|
||||
assert(b);
|
||||
buffer_uint_pop(&j, g_buffB);
|
||||
assert(j == i);
|
||||
}
|
||||
assert (buffer_uint_empty_p(g_buffB));
|
||||
@@ -231,56 +226,25 @@ static void test_stack2(void)
|
||||
buffer_char_init(buff, 10);
|
||||
for(int i = 0; i < 10; i++) {
|
||||
c = (char) i;
|
||||
b = buffer_char_push(buff, c);
|
||||
b = buffer_char_push_blocking(buff, c, false);
|
||||
assert (b == true);
|
||||
assert (buffer_char_empty_p(buff) == false);
|
||||
}
|
||||
b = buffer_char_push(buff, c);
|
||||
b = buffer_char_push_blocking(buff, c, false);
|
||||
assert (b == false);
|
||||
assert (buffer_char_full_p(buff) == true);
|
||||
for(int i = 0; i < 10; i++) {
|
||||
buffer_char_pop(&c, buff);
|
||||
b = buffer_char_pop_blocking(&c, buff, false);
|
||||
assert(b);
|
||||
assert(c == 9-i);
|
||||
assert (buffer_char_full_p(buff) == false);
|
||||
}
|
||||
b = buffer_char_pop(&c, buff);
|
||||
b = buffer_char_pop_blocking(&c, buff, false);
|
||||
assert (b == false);
|
||||
assert (buffer_char_empty_p(buff) == true);
|
||||
buffer_char_clear(buff);
|
||||
}
|
||||
|
||||
static void test_no_thread(void)
|
||||
{
|
||||
buffer_llong_t buff;
|
||||
bool b;
|
||||
long long c;
|
||||
buffer_llong_init(buff, 16);
|
||||
for(int i = 0; i < 16; i++) {
|
||||
c = i;
|
||||
b = buffer_llong_push(buff, c);
|
||||
assert (b == true);
|
||||
assert (buffer_llong_empty_p(buff) == false);
|
||||
}
|
||||
b = buffer_llong_push(buff, c);
|
||||
assert (b == false);
|
||||
assert (buffer_llong_full_p(buff) == true);
|
||||
for(int i = 0; i < 16; i++) {
|
||||
buffer_llong_pop(&c, buff);
|
||||
assert(c == i);
|
||||
assert (buffer_llong_full_p(buff) == false);
|
||||
}
|
||||
b = buffer_llong_pop(&c, buff);
|
||||
assert (b == false);
|
||||
assert (buffer_llong_empty_p(buff) == true);
|
||||
|
||||
b = buffer_llong_push(buff, c);
|
||||
assert (b == true);
|
||||
buffer_llong_reset(buff);
|
||||
assert (buffer_llong_empty_p(buff) == true);
|
||||
|
||||
buffer_llong_clear(buff);
|
||||
}
|
||||
|
||||
static void test_emplace(void)
|
||||
{
|
||||
buffer_mpz_t b;
|
||||
@@ -582,56 +546,41 @@ static void test_spsc(void)
|
||||
|
||||
static void test_double1(void)
|
||||
{
|
||||
bool b;
|
||||
M_LET(buffer, BufferDouble1) {
|
||||
b = BufferDouble1_push(buffer, 0.0);
|
||||
assert(b);
|
||||
b= BufferDouble1_push(buffer, 1.0);
|
||||
assert(b);
|
||||
BufferDouble1_push(buffer, 0.0);
|
||||
BufferDouble1_push(buffer, 1.0);
|
||||
double d;
|
||||
b = BufferDouble1_pop(&d, buffer);
|
||||
assert(b);
|
||||
BufferDouble1_pop(&d, buffer);
|
||||
assert(d == 0.0);
|
||||
b = BufferDouble1_pop(&d, buffer);
|
||||
assert(b);
|
||||
BufferDouble1_pop(&d, buffer);
|
||||
assert(d == 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_double2(void)
|
||||
{
|
||||
bool b;
|
||||
BufferDouble2 buffer;
|
||||
BufferDouble2_init(buffer, 2);
|
||||
b = BufferDouble2_push(buffer, 0.0);
|
||||
assert(b);
|
||||
b= BufferDouble2_push(buffer, 1.0);
|
||||
assert(b);
|
||||
BufferDouble2_push(buffer, 0.0);
|
||||
BufferDouble2_push(buffer, 1.0);
|
||||
double d;
|
||||
b = BufferDouble2_pop(&d, buffer);
|
||||
assert(b);
|
||||
BufferDouble2_pop(&d, buffer);
|
||||
assert(d == 0.0);
|
||||
b = BufferDouble2_pop(&d, buffer);
|
||||
assert(b);
|
||||
BufferDouble2_pop(&d, buffer);
|
||||
assert(d == 1.0);
|
||||
BufferDouble2_clear(buffer);
|
||||
}
|
||||
|
||||
static void test_double3(void)
|
||||
{
|
||||
bool b;
|
||||
BufferDouble3 buffer;
|
||||
BufferDouble3_init(buffer, 2);
|
||||
b = BufferDouble3_push(buffer, 0.0);
|
||||
assert(b);
|
||||
b= BufferDouble3_push(buffer, 1.0);
|
||||
assert(b);
|
||||
BufferDouble3_push(buffer, 0.0);
|
||||
BufferDouble3_push(buffer, 1.0);
|
||||
double d;
|
||||
b = BufferDouble3_pop(&d, buffer);
|
||||
assert(b);
|
||||
BufferDouble3_pop(&d, buffer);
|
||||
assert(d == 0.0);
|
||||
b = BufferDouble3_pop(&d, buffer);
|
||||
assert(b);
|
||||
BufferDouble3_pop(&d, buffer);
|
||||
assert(d == 1.0);
|
||||
BufferDouble3_clear(buffer);
|
||||
}
|
||||
@@ -668,7 +617,6 @@ int main(void)
|
||||
test_global();
|
||||
test_stack();
|
||||
test_stack2();
|
||||
test_no_thread();
|
||||
test_emplace();
|
||||
test_global_ishared();
|
||||
test_queue(1000000, 2, 2148371710223136ULL);
|
||||
|
||||
Reference in new issue
Block a user