diff options
author | Eugene Tarassov | 2018-05-22 21:18:43 +0000 |
---|---|---|
committer | Eugene Tarassov | 2018-05-22 21:18:43 +0000 |
commit | 4442c47b79949f4cd7fe264f5810f693c36a6e64 (patch) | |
tree | 7979322110ba6425293b60b4f2c096e0b882d8c0 | |
parent | 0698b5892866cddb8f8a6990f64422e1bcf4ea37 (diff) | |
download | org.eclipse.tcf.agent-4442c47b79949f4cd7fe264f5810f693c36a6e64.tar.gz org.eclipse.tcf.agent-4442c47b79949f4cd7fe264f5810f693c36a6e64.tar.xz org.eclipse.tcf.agent-4442c47b79949f4cd7fe264f5810f693c36a6e64.zip |
TCF Core: new macros list_entry() and member_to_type()
the macros help to improve readability of the code
-rw-r--r-- | agent/tcf/framework/link.h | 62 | ||||
-rw-r--r-- | agent/tcf/framework/mdep.h | 2 |
2 files changed, 34 insertions, 30 deletions
diff --git a/agent/tcf/framework/link.h b/agent/tcf/framework/link.h index e1ac2287..d0b449e3 100644 --- a/agent/tcf/framework/link.h +++ b/agent/tcf/framework/link.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 Wind River Systems, Inc. and others. + * Copyright (c) 2007-2018 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * and Eclipse Distribution License v1.0 which accompany this distribution. @@ -33,38 +33,40 @@ struct LINK { #define TCF_LIST_INIT(list) {&(list), &(list)} #define list_init(list) { \ - (list)->next = (list)->prev = (list); \ - } + (list)->next = (list)->prev = (list); \ +} #define list_is_empty(list) ((list)->next == (list) || (list)->next == NULL) #define list_remove(item) { \ - LINK * _l_ = item; \ - _l_->prev->next = _l_->next; \ - _l_->next->prev = _l_->prev; \ - _l_->next = _l_->prev = _l_; \ - } - -#define list_add_first(item,list) { \ - (item)->next = (list)->next; (item)->prev = (list); \ - (list)->next->prev = (item); (list)->next = (item); \ - } - -#define list_add_last(item,list) { \ - (item)->next = (list); (item)->prev = (list)->prev; \ - (list)->prev->next = (item); (list)->prev = (item); \ - } - -#define list_concat(item,list) { \ - if (!list_is_empty(list)) { \ - (item)->prev->next = (list)->next; \ - (list)->next->prev = (item)->prev; \ - (item)->prev = (list)->prev; \ - (list)->prev->next = (item); \ - } \ - } - -#define list_foreach(trav,list) \ - for (trav = (list)->next; trav != list; trav = trav->next) + LINK * _l_ = item; \ + _l_->prev->next = _l_->next; \ + _l_->next->prev = _l_->prev; \ + _l_->next = _l_->prev = _l_; \ +} + +#define list_add_first(item, list) { \ + (item)->next = (list)->next; (item)->prev = (list); \ + (list)->next->prev = (item); (list)->next = (item); \ +} + +#define list_add_last(item, list) { \ + (item)->next = (list); (item)->prev = (list)->prev; \ + (list)->prev->next = (item); (list)->prev = (item); \ +} + +#define list_concat(item, list) { \ + if (!list_is_empty(list)) { \ + (item)->prev->next = (list)->next; \ + (list)->next->prev = (item)->prev; \ + (item)->prev = (list)->prev; \ + (list)->prev->next = (item); \ + } \ +} + +#define list_foreach(trav, list) \ + for (trav = (list)->next; trav != list; trav = trav->next) + +#define list_entry(item, type, link) member_to_type(item, type, link) #endif /* D_link */ diff --git a/agent/tcf/framework/mdep.h b/agent/tcf/framework/mdep.h index 5147738a..0f8a7ef4 100644 --- a/agent/tcf/framework/mdep.h +++ b/agent/tcf/framework/mdep.h @@ -405,6 +405,8 @@ extern size_t strlcat(char * dst, const char * src, size_t size); # endif #endif +#define member_to_type(ptr, type, member) (type *)((char *)(ptr) - offsetof(type, member)) + /* Swap bytes in a buffer - change value endianness */ extern void swap_bytes(void * buf, size_t size); #define SWAP(x) swap_bytes(&(x), sizeof(x)) |