From 318eec25b5bb1b8b380d4917e9c7e12e26da9c12 Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Thu, 31 Aug 2017 13:06:17 +0200 Subject: [PATCH] async.c: included macro SEARCH_PAIR from commit 5b1a8f67 Commit 5b1a8f67 added two macros LL_SEARCH_PAIR and LL_SEARCH_PAIR2 to utlist.h which is maintained at [1]. To simplify updates of this file, the macros have been moved into async.c as this is the only place where they are used. To avoid confusion with linked list macros from utlist.h, the prefix "LL_" has been removed from the custom macros. [1] https://github.com/troydhanson/uthash --- src/async.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/async.c b/src/async.c index 38ecc8ee..d8a48f5d 100644 --- a/src/async.c +++ b/src/async.c @@ -20,13 +20,24 @@ #include "mem.h" #include "utlist.h" +/* utlist-style macros for searching pairs in linked lists */ +#define SEARCH_PAIR(head,out,field1,val1,field2,val2) \ + SEARCH_PAIR2(head,out,field1,val1,field2,val2,next) + +#define SEARCH_PAIR2(head,out,field1,val1,field2,val2,next) \ + do { \ + LL_FOREACH2(head,out,next) { \ + if ((out)->field1 == (val1) && (out)->field2 == (val2)) break; \ + } \ +} while(0) + coap_async_state_t * coap_register_async(coap_context_t *context, coap_session_t *session, coap_pdu_t *request, unsigned char flags, void *data) { coap_async_state_t *s; coap_tid_t id = ntohs( request->hdr->id ); - LL_SEARCH_PAIR(context->async_state,s,session,session,id,id); + SEARCH_PAIR(context->async_state,s,session,session,id,id); if (s != NULL) { /* We must return NULL here as the caller must know that he is @@ -69,7 +80,7 @@ coap_register_async(coap_context_t *context, coap_session_t *session, coap_async_state_t * coap_find_async(coap_context_t *context, coap_session_t *session, coap_tid_t id) { coap_async_state_t *tmp; - LL_SEARCH_PAIR(context->async_state,tmp,session,session,id,id); + SEARCH_PAIR(context->async_state,tmp,session,session,id,id); return tmp; }