From c18098176848d1b4dae53d3217b802c661fa9fff Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 15 Aug 2020 14:59:10 +0200 Subject: [PATCH] Add macros CONCURRENT_DEF_AS CONCURRENT_RP_DEF_AS --- m-concurrent.h | 24 ++++++++++++++++++++++++ tests/test-mconcurrent.c | 15 +++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/m-concurrent.h b/m-concurrent.h index 1cd98f6a..4334d947 100644 --- a/m-concurrent.h +++ b/m-concurrent.h @@ -40,6 +40,17 @@ M_END_PROTECTED_CODE +/* Define a protected concurrent container and its associated functions + based on the given container as the given name name_t + USAGE: CONCURRENT_DEF_AS(name, name_t, type [, oplist_of_the_type]) */ +#define CONCURRENT_DEF_AS(name, name_t, ...) \ + M_BEGIN_PROTECTED_CODE \ + CONCURRENTI_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \ + (name, __VA_ARGS__, name_t ))) \ + M_END_PROTECTED_CODE + + /* Define the oplist of a protected concurrent container given its name and its oplist. USAGE: CONCURRENT_OPLIST(name[, oplist of the type]) */ #define CONCURRENT_OPLIST(...) \ @@ -60,6 +71,19 @@ M_END_PROTECTED_CODE +/* Define a protected concurrent container and its associated functions + as the given name name_t + based on its given container. Operations that perform only read of the container + can be done in parallel. + USAGE: CONCURRENT_RP_DEF_AS(name, name_t, type [, oplist_of_the_type]) */ +#define CONCURRENT_RP_DEF_AS(name, name_t, ...) \ + M_BEGIN_PROTECTED_CODE \ + CONCURRENTI_RP_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ + ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \ + (name, __VA_ARGS__, name_t ))) \ + M_END_PROTECTED_CODE + + /********************************** INTERNAL ************************************/ /* Deferred evaluation for the oplist definition, diff --git a/tests/test-mconcurrent.c b/tests/test-mconcurrent.c index 8e4f326f..d52749d8 100644 --- a/tests/test-mconcurrent.c +++ b/tests/test-mconcurrent.c @@ -97,6 +97,9 @@ CONCURRENT_RP_DEF(rparray1, array1_t, ARRAY_OPLIST(array1)) CONCURRENT_RP_DEF(rpdict1, dict1_t, DICT_OPLIST(dict1)) +CONCURRENT_DEF_AS(ConcurrentDouble, ConcurrentDouble, double) +CONCURRENT_RP_DEF_AS(ConcurrentRpDouble, ConcurrentRpDouble, double) + /* OA dict needs more operators than the default ones to work */ static inline bool int_oor_equal_p(int s, unsigned char n) { @@ -210,11 +213,23 @@ static void test_rp_basic(void) rpdict1_clear(dict); } +static void test_double(void) +{ + ConcurrentDouble d; + ConcurrentDouble_init(d); + ConcurrentDouble_clear(d); + + ConcurrentRpDouble r; + ConcurrentRpDouble_init(r); + ConcurrentRpDouble_clear(r); +} + int main(void) { test_basic(); test_rp_basic(); test_thread(); test_rp_thread(); + test_double(); exit(0); }