Fix warnings.
Update interface to avoid silent cast from size_t to unsigned int.
This commit is contained in:
1 parent
a89db9ea56
commit
d19a5ad9de
2 files changed
+89
-3
No files matched your search
+5
-3
@@ -378,10 +378,12 @@ M_C(name, _init)(buffer_t v, size_t size) \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
M_C(name, _init)(buffer_t buffer, unsigned int size) \
|
||||
M_C(name, _init)(buffer_t buffer, size_t size) \
|
||||
{ \
|
||||
assert (buffer != NULL); \
|
||||
assert( M_POWEROF2_P(size)); \
|
||||
assert (size <= UINT_MAX); \
|
||||
assert(((policy) & (BUFFER_STACK|BUFFER_THREAD_UNSAFE|BUFFER_PUSH_OVERWRITE)) == 0); \
|
||||
atomic_init(&buffer->ProdIdx, size); \
|
||||
atomic_init(&buffer->ConsoIdx, size); \
|
||||
buffer->size = size; \
|
||||
@@ -390,7 +392,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
|
||||
M_MEMORY_FULL (size*sizeof(M_C(name, _el_t) )); \
|
||||
return; \
|
||||
} \
|
||||
for(int j = 0; j < size; j++) { \
|
||||
for(unsigned int j = 0; j < size; j++) { \
|
||||
atomic_init(&buffer->Tab[j].seq, 2*j+1); \
|
||||
M_GET_INIT oplist (buffer->Tab[j].x); \
|
||||
} \
|
||||
@@ -399,7 +401,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
|
||||
static inline void \
|
||||
M_C(name, _clear)(buffer_t buffer) \
|
||||
{ \
|
||||
for(int j = 0; j < buffer->size; j++) { \
|
||||
for(unsigned int j = 0; j < buffer->size; j++) { \
|
||||
M_GET_CLEAR oplist (buffer->Tab[j].x); \
|
||||
} \
|
||||
M_GET_FREE oplist (buffer->Tab); \
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
START_COVERAGE
|
||||
// Define a fixed queue of unsigned int
|
||||
BUFFER_DEF(buffer_uint, unsigned int, 10, BUFFER_QUEUE|BUFFER_BLOCKING)
|
||||
QUEUE_MPMC_DEF(queue_uint, unsigned int, BUFFER_QUEUE)
|
||||
END_COVERAGE
|
||||
|
||||
// Define a variable stack of float
|
||||
@@ -275,6 +276,88 @@ static void test_global_ishared(void)
|
||||
buffer_itest_clear(comm2);
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
QUEUE_MPMC_DEF(queue_ull, unsigned long long, BUFFER_QUEUE)
|
||||
|
||||
queue_uint_t g_buff2;
|
||||
queue_ull_t g_final2;
|
||||
unsigned long long g_result;
|
||||
|
||||
static void final2(void *arg)
|
||||
{
|
||||
size_t *p_n = arg;
|
||||
size_t n = *p_n;
|
||||
unsigned long long j, s = 0;
|
||||
for(unsigned int i = 0; i < n;i++) {
|
||||
while (!queue_ull_pop(&j, g_final2));
|
||||
s += j;
|
||||
}
|
||||
g_result = s;
|
||||
}
|
||||
|
||||
static void conso2(void *arg)
|
||||
{
|
||||
unsigned int j;
|
||||
size_t *p_n = arg;
|
||||
size_t n = *p_n;
|
||||
unsigned long long s = 0;
|
||||
for(unsigned int i = 0; i < n;i++) {
|
||||
while (!queue_uint_pop(&j, g_buff2));
|
||||
s += j;
|
||||
}
|
||||
while (!queue_ull_push(g_final2, s));
|
||||
}
|
||||
|
||||
static void prod2(void *arg)
|
||||
{
|
||||
size_t *p_n = arg;
|
||||
size_t n = *p_n;
|
||||
size_t r = n;
|
||||
for(unsigned int i = 0; i < n;i++) {
|
||||
while (!queue_uint_push(g_buff2, r ));
|
||||
r = r * 31421U + 6927U;
|
||||
}
|
||||
}
|
||||
|
||||
static void test_queue(size_t n, int cpu_count, unsigned long long ref)
|
||||
{
|
||||
const int prod_count = cpu_count / 2;
|
||||
const int conso_count = cpu_count - prod_count;
|
||||
|
||||
// Init
|
||||
queue_uint_init(g_buff2, 64*2);
|
||||
queue_ull_init (g_final2, 64*2);
|
||||
|
||||
// Create thread
|
||||
m_thread_t idx_p[prod_count];
|
||||
m_thread_t idx_c[conso_count];
|
||||
m_thread_t idx_final;
|
||||
for(int i = 0; i < prod_count; i++) {
|
||||
m_thread_create (idx_p[i], prod2, &n);
|
||||
}
|
||||
for(int i = 0; i < conso_count; i++) {
|
||||
m_thread_create (idx_c[i], conso2, &n);
|
||||
}
|
||||
size_t n2 = conso_count;
|
||||
m_thread_create(idx_final, final2, &n2);
|
||||
|
||||
// Wait for jobs to be done.
|
||||
for(int i = 0; i < prod_count; i++) {
|
||||
m_thread_join(idx_p[i]);
|
||||
}
|
||||
for(int i = 0; i < conso_count; i++) {
|
||||
m_thread_join(idx_c[i]);
|
||||
}
|
||||
m_thread_join(idx_final);
|
||||
|
||||
assert(g_result == ref);
|
||||
|
||||
// Clear & quit
|
||||
queue_ull_clear(g_final2);
|
||||
queue_uint_clear(g_buff2);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned int x, y;
|
||||
@@ -303,5 +386,6 @@ int main(void)
|
||||
test_stack2();
|
||||
test_no_thread();
|
||||
test_global_ishared();
|
||||
test_queue(1000000, 2, 2148371710223136ULL);
|
||||
exit(0);
|
||||
}
|
||||
Reference in new issue
Block a user