From 836d89283233e19a0951163d70f3dc8d0de1572e Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Thu, 28 Oct 2021 18:08:07 +0200 Subject: [PATCH] Rename BUFFER, I-LIST, PRIOQUEUE & SHARED _clean in _reset to avoid confusing _clean & _clear functions. See #97 --- README.md | 14 +++++++------- m-buffer.h | 10 ++++++++-- m-i-list.h | 12 +++++++++--- m-prioqueue.h | 10 ++++++++-- m-shared.h | 10 ++++++++-- tests/test-mbuffer.c | 6 +++--- tests/test-milist.c | 3 +++ tests/test-mprioqueue.c | 2 +- tests/test-mshared.c | 8 ++++---- 9 files changed, 51 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index f39cfac7..7202f055 100644 --- a/README.md +++ b/README.md @@ -3536,9 +3536,9 @@ from 'ref' and clear 'ref'. Set the Priority Queue 'queue' by stealing as resource as possible from 'ref' and clear 'ref'. -##### void name\_clean(name\_t queue) +##### void name\_reset(name\_t queue) -Clean the Priority Queue 'queue'. 'queue' remains initialized but empty. +Reset the Priority Queue 'queue' (It remains initialized but empty). ##### size\_t name\_size(const name\_t queue) @@ -3716,9 +3716,9 @@ Clear the buffer and destroy all its allocation. This function is not thread safe and doesn't perform any synchronization: all threads shall have stopped using the buffer. -##### void name\_clean(buffer\_t buffer) +##### void name\_reset(buffer\_t buffer) -Clean the buffer making it empty but remain initialized. +Reset the buffer, making it empty but initialized. This function is thread safe if the buffer was built thread safe. ##### bool name\_empty\_p(const buffer\_t buffer) @@ -4247,11 +4247,11 @@ the shared pointer loses its ownership of the object and it destroys it if no longer any other shared pointers own the object. This function is thread safe. -##### void name\_clean(shared\_t shared) +##### void name\_reset(shared\_t shared) -'shared' loses ownership of its object and destroy it +'shared' loses ownership of its object and destroys it if no longer any other shared pointers own it. -Then it makes the shared pointer 'shared' references NULL +Then it makes the shared pointer 'shared' references no object (NULL) (it doesn't reference its object any-longer and loses its ownership of it). This function is thread safe. diff --git a/m-buffer.h b/m-buffer.h index 5b2b8299..e223eb95 100644 --- a/m-buffer.h +++ b/m-buffer.h @@ -375,7 +375,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline void \ - M_C(name, _clean)(buffer_t v) \ + M_C(name, _reset)(buffer_t v) \ { \ M_BUFF3R_CONTRACT(v,m_size); \ if (!M_BUFF3R_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \ @@ -397,6 +397,12 @@ M_C(name, _init)(buffer_t v, size_t size) \ M_BUFF3R_CONTRACT(v,m_size); \ } \ \ + static inline void M_ATTR_DEPRECATED \ + M_C(name, _clean)(buffer_t v) \ + { \ + M_C(name,_reset)(v); \ + } \ + \ static inline void \ M_C(name, _init_set)(buffer_t dest, const buffer_t src) \ { \ @@ -1268,7 +1274,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ ,NAME(name) \ ,TYPE(M_C(name,_ct)) \ ,SUBTYPE(M_C(name, _subtype_ct)) \ - ,CLEAN(M_C(name,_clean)) \ + ,CLEAN(M_C(name,_reset)) \ ,PUSH(M_C(name,_push)) \ ,POP(M_C(name,_pop)) \ ,OPLIST(oplist) \ diff --git a/m-i-list.h b/m-i-list.h index 013e915b..9baf6551 100644 --- a/m-i-list.h +++ b/m-i-list.h @@ -99,7 +99,7 @@ typedef struct m_ilist_head_s { MOVE(M_C(name, _move)), \ NAME(name), \ TYPE(M_C(name,_ct)), \ - CLEAN(M_C(name,_clean)), \ + CLEAN(M_C(name,_reset)), \ SUBTYPE(M_C(name,_subtype_ct)), \ EMPTY_P(M_C(name,_empty_p)), \ IT_TYPE(M_C(name,_it_ct)), \ @@ -196,7 +196,7 @@ typedef struct m_ilist_head_s { } \ \ static inline void \ - M_C(name, _clean)(list_t list) \ + M_C(name, _reset)(list_t list) \ { \ M_IL1ST_CONTRACT(name, list); \ for(struct m_ilist_head_s *it = list->name.next, *next ; \ @@ -217,11 +217,17 @@ typedef struct m_ilist_head_s { M_IL1ST_CONTRACT(name, list); \ } \ \ + static inline void M_ATTR_DEPRECATED \ + M_C(name, _clean)(list_t list) \ + { \ + M_C(name,_reset)(list); \ + } \ + \ static inline void \ M_C(name, _clear)(list_t list) \ { \ /* Nothing to do more than clean the list itself */ \ - M_C(name, _clean)(list); \ + M_C(name, _reset)(list); \ /* For safety purpose (create invalid represenation of object) */ \ list->name.next = NULL; \ list->name.prev = NULL; \ diff --git a/m-prioqueue.h b/m-prioqueue.h index 60e86cbc..58fcf69e 100644 --- a/m-prioqueue.h +++ b/m-prioqueue.h @@ -83,7 +83,7 @@ ,NAME(name) \ ,TYPE(M_C(name,_ct)) \ ,SUBTYPE(M_C(name, _subtype_ct)) \ - ,CLEAN(M_C(name,_clean)) \ + ,CLEAN(M_C(name,_reset)) \ ,PUSH(M_C(name,_push)) \ ,POP(M_C(name,_pop)) \ ,OPLIST(oplist) \ @@ -186,9 +186,15 @@ } \ \ static inline void \ + M_C(name, _reset)(prioqueue_t p) \ + { \ + M_C(name, _array_reset)(p->array); \ + } \ + \ + static inline void M_ATTR_DEPRECATED \ M_C(name, _clean)(prioqueue_t p) \ { \ - M_C(name, _array_clean)(p->array); \ + M_C(name,_reset)(p); \ } \ \ static inline size_t \ diff --git a/m-shared.h b/m-shared.h index edb61b22..17360df8 100644 --- a/m-shared.h +++ b/m-shared.h @@ -112,7 +112,7 @@ M_BEGIN_PROTECTED_CODE INIT_SET(M_C(name, _init_set)), \ SET(M_C(name, _set)) \ INIT_MOVE(M_C(name, _init_move)), \ - CLEAN(M_C(name, _clean)), \ + CLEAN(M_C(name, _reset)), \ MOVE(M_C(name, _move)), \ SWAP(M_C(name, _swap)) \ ,NAME(name) \ @@ -271,12 +271,18 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } } \ \ static inline void \ - M_C(name, _clean)(shared_t dest) \ + M_C(name, _reset)(shared_t dest) \ { \ /* NOTE: Clear will also set dest to NULL */ \ M_C(name, _clear)(dest); \ } \ \ + static inline void M_ATTR_DEPRECATED \ + M_C(name, _clean)(shared_t dest) \ + { \ + M_C(name, _reset)(dest); \ + } \ + \ static inline void \ M_C(name, _set)(shared_t dest, \ const shared_t shared) \ diff --git a/tests/test-mbuffer.c b/tests/test-mbuffer.c index 4a7c9eb9..05c49cdb 100644 --- a/tests/test-mbuffer.c +++ b/tests/test-mbuffer.c @@ -125,7 +125,7 @@ static void test_global(void) assert (!buffer_uint_full_p(g_buff)); assert (buffer_uint_size(g_buff) == 0); - buffer_uint_clean(g_buff); + buffer_uint_reset(g_buff); assert (buffer_uint_empty_p(g_buff)); assert (!buffer_uint_full_p(g_buff)); assert (buffer_uint_size(g_buff) == 0); @@ -145,7 +145,7 @@ static void test_global(void) assert (buffer_uint_size(g_buff) == 10); assert (buffer_uint_push_blocking(g_buff, 15, false) == false); - buffer_uint_clean(g_buff); + buffer_uint_reset(g_buff); assert (buffer_uint_empty_p(g_buff)); assert (!buffer_uint_full_p(g_buff)); assert (buffer_uint_size(g_buff) == 0); @@ -260,7 +260,7 @@ static void test_no_thread(void) b = buffer_llong_push(buff, c); assert (b == true); - buffer_llong_clean(buff); + buffer_llong_reset(buff); assert (buffer_llong_empty_p(buff) == true); buffer_llong_clear(buff); diff --git a/tests/test-milist.c b/tests/test-milist.c index 3007ba82..072f2bb4 100644 --- a/tests/test-milist.c +++ b/tests/test-milist.c @@ -135,6 +135,9 @@ static void test(void) assert (ilist_tname_size (list) == 2); assert (ilist_tname_cref(it1) == &x3); assert (ilist_tname_previous_obj(list, &x3) == &x1); + + ilist_tname_reset(list); + assert (ilist_tname_empty_p(list)); ilist_tname_clear(list); } diff --git a/tests/test-mprioqueue.c b/tests/test-mprioqueue.c index e61c46a9..39d97d5c 100644 --- a/tests/test-mprioqueue.c +++ b/tests/test-mprioqueue.c @@ -275,7 +275,7 @@ static void test_it(void) int_pqueue_swap(p, q); assert(int_pqueue_size(p) == 20); assert(int_pqueue_size(q) == 21); - int_pqueue_clean(q); + int_pqueue_reset(q); assert(!int_pqueue_equal_p(p, q)); assert(int_pqueue_empty_p(q)); assert(!int_pqueue_empty_p(p)); diff --git a/tests/test-mshared.c b/tests/test-mshared.c index 2502e7cd..59f24f0a 100644 --- a/tests/test-mshared.c +++ b/tests/test-mshared.c @@ -59,14 +59,14 @@ static void test1(void) shared_int_init_set(p2, p1); assert(f(p2) == 12); - shared_int_clean(p1); + shared_int_reset(p1); assert(shared_int_NULL_p(p1)); assert(!shared_int_NULL_p(p2)); assert(f(p2) == 12); shared_int_set(p1, p2); - shared_int_clean(p2); + shared_int_reset(p2); assert(!shared_int_NULL_p(p1)); assert(shared_int_NULL_p(p2)); assert(f(p1) == 12); @@ -75,8 +75,8 @@ static void test1(void) assert(!shared_int_NULL_p(p2)); assert(f(p2) == 12); - shared_int_clean(p2); - shared_int_clean(p1); + shared_int_reset(p2); + shared_int_reset(p1); assert(shared_int_NULL_p(p1)); assert(shared_int_NULL_p(p2));