#define FUN_ERROR(message, expression, handler) do { if (!(expression)) { \
PLATFORM_ERROR(message); handler;}} while(0)
用法 FUN_ERROR("pcb already connected", pcb->state == CLOSED, return NULL);
#define TCP_REG(pcbs, npcb) \
do { \
(npcb)->next = *pcbs; \
*(pcbs) = (npcb); \
tcp_timer_needed(); \
} while (0)
#define TCP_RMV(pcbs, npcb) \
do { \
if(*(pcbs) == (npcb)) { \
(*(pcbs)) = (*pcbs)->next; \
} \
else { \
for(tcp_tmp_pcb = *pcbs; \
tcp_tmp_pcb != NULL; \
tcp_tmp_pcb = tcp_tmp_pcb->next) { \
if(tcp_tmp_pcb->next == (npcb)) { \
tcp_tmp_pcb->next = (npcb)->next; \
break; \
} \
} \
} \
(npcb)->next = NULL; \
} while(0)
#define STATS_INC(x) ++l_stats.x
#define STATS_DEC(x) --l_stats.x
#define ip4_addr_ismulticast(addr1) (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL))
#define ip4_addr_isloopback(ipaddr) (((ipaddr)->addr & PP_HTONL(IP_CLASSA_NET)) == PP_HTONL(((u32_t)IP_LOOPBACKNET) << 24))
#define FOLD_U32T(u) (((u) >> 16) + ((u) & 0x0000ffffUL))
#define ip4_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
#define TCP_SEQ_LT(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) < 0)
#define TCP_SEQ_LEQ(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) <= 0)
#define TCP_SEQ_GT(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) > 0)
#define TCP_SEQ_GEQ(a,b) ((s32_t)((u32_t)(a) - (u32_t)(b)) >= 0)
#define TCP_SEQ_BETWEEN(a,b,c) (TCP_SEQ_GEQ(a,b) && TCP_SEQ_LEQ(a,c))
#define CIS_LIST_ADD(H,N) cis_list_add((cis_list_t *)H, (cis_list_t *)N);
#define CIS_LIST_RM(H,I,N) cis_list_remove((cis_list_t *)H, I, (cis_list_t **)N);
#define CIS_LIST_FIND(H,I) cis_list_find((cis_list_t *)H, I)
#define CIS_LIST_FIND_U16(H,I) cis_list_find_u16((cis_list_t *)H, I)
#define CIS_LIST_FREE(H) cis_list_free((cis_list_t *)H)
#define CIS_LIST_COUNT(H) cis_list_count((cis_list_t *)H);
cis_list_t * cis_list_add(cis_list_t * head,
cis_list_t * node)
{
cis_list_t * target;
if (NULL == head)
{
return node;
}
if (head->id > node->id)
{
node->next = head;
return node;
}
target = head;
while (NULL != target->next && target->next->id < node->id)
{
target = target->next;
}
node->next = target->next;
target->next = node;
return head;
}
cis_list_t * cis_list_find(cis_list_t * head,
cis_listid_t id)
{
while (NULL != head && head->id < id)
{
head = head->next;
}
if (NULL != head && head->id == id)
{
return head;
}
return NULL;
}
cis_list_t * cis_list_find_u16(cis_list_t * head,
uint16_t id)
{
while (NULL != head && (head->id & 0xFFFF) < id)
{
head = head->next;
}
if (NULL != head && (head->id & 0xFFFF) == id)
{
return head;
}
return NULL;
}
cis_list_t * cis_list_remove(cis_list_t * head,
cis_listid_t id,
cis_list_t ** nodeP)
{
cis_list_t * target;
if (head == NULL)
{
if (nodeP)
{
*nodeP = NULL;
}
return NULL;
}
if (head->id == id)
{
if (nodeP)
{
*nodeP = head;
}
return head->next;
}
target = head;
while (NULL != target->next && target->next->id < id)
{
target = target->next;
}
if (NULL != target->next && target->next->id == id)
{
if (nodeP)
{
*nodeP = target->next;
}
target->next = target->next->next;
}
else
{
if (nodeP)
{
*nodeP = NULL;
}
}
return head;
}
cis_listid_t cis_list_newId(cis_list_t * head)
{
cis_listid_t id;
cis_list_t * target;
id = 0;
target = head;
while (target != NULL && id == target->id)
{
id = target->id + 1;
target = target->next;
}
return id;
}
void cis_list_free(cis_list_t * head)
{
if (head != NULL)
{
cis_list_t * nextP;
nextP = head->next;
cis_free(head);
cis_list_free(nextP);
}
}
cis_listid_t cis_list_count(cis_list_t * head)
{
cis_listid_t count = 0;
cis_list_t * target;
target = head;
while (target != NULL)
{
count++;
target = target->next;
}
return count;
}
static inline unsigned long
__find_buddy_index(unsigned long page_idx, unsigned int order)
{
return page_idx ^ (1 << order);
}
combined_idx = buddy_idx & page_idx;
page = page + (combined_idx - page_idx);
page_idx = combined_idx; //page_idx会还原回原来的值
阅读(2679) | 评论(1) | 转发(0) |