From 95800612dc098488bf2518aa6485eaaa795b7369 Mon Sep 17 00:00:00 2001 From: yuqing Date: Sun, 10 Aug 2014 14:01:58 +0800 Subject: [PATCH] use newest files from libfastcommon --- HISTORY | 2 +- common/fast_mblock.c | 11 +++++++---- common/fast_mblock.h | 7 +++++-- common/fast_task_queue.h | 2 +- common/hash.c | 1 + common/ioevent_loop.c | 8 ++++---- common/shared_func.c | 4 ++-- common/sockopt.c | 1 - 8 files changed, 21 insertions(+), 15 deletions(-) diff --git a/HISTORY b/HISTORY index f0755d8..953cc48 100644 --- a/HISTORY +++ b/HISTORY @@ -5,7 +5,7 @@ Version 5.03 2014-08-10 * use newest logger from libfastcommon * patches by liangry@ucweb.com * bug fixed: can't sync large files cause by v5.02 - * use newest ioevent_loop from libfastcommon + * use newest files from libfastcommon Version 5.02 2014-07-20 * corect README spell mistake diff --git a/common/fast_mblock.c b/common/fast_mblock.c index 488a084..c38035a 100644 --- a/common/fast_mblock.c +++ b/common/fast_mblock.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "fast_mblock.h" #include "logger.h" #include "shared_func.h" @@ -21,7 +22,7 @@ int fast_mblock_init(struct fast_mblock_man *mblock, const int element_size, \ return EINVAL; } - mblock->element_size = element_size; + mblock->element_size = MEM_ALIGN(element_size); if (alloc_elements_once > 0) { mblock->alloc_elements_once = alloc_elements_once; @@ -30,7 +31,7 @@ int fast_mblock_init(struct fast_mblock_man *mblock, const int element_size, \ { int block_size; block_size = MEM_ALIGN(sizeof(struct fast_mblock_node) \ - + element_size); + + mblock->element_size); mblock->alloc_elements_once = (1024 * 1024) / block_size; } @@ -44,6 +45,7 @@ int fast_mblock_init(struct fast_mblock_man *mblock, const int element_size, \ mblock->malloc_chain_head = NULL; mblock->free_chain_head = NULL; + mblock->total_count = 0; return 0; } @@ -84,12 +86,12 @@ static int fast_mblock_prealloc(struct fast_mblock_man *mblock) pNode = (struct fast_mblock_node *)p; pNode->next = (struct fast_mblock_node *)(p + block_size); } - ((struct fast_mblock_node *)pLast)->next = NULL; mblock->free_chain_head = (struct fast_mblock_node *)pTrunkStart; pMallocNode->next = mblock->malloc_chain_head; mblock->malloc_chain_head = pMallocNode; + mblock->total_count += mblock->alloc_elements_once; return 0; } @@ -114,6 +116,7 @@ void fast_mblock_destroy(struct fast_mblock_man *mblock) } mblock->malloc_chain_head = NULL; mblock->free_chain_head = NULL; + mblock->total_count = 0; pthread_mutex_destroy(&(mblock->lock)); } @@ -189,7 +192,7 @@ int fast_mblock_free(struct fast_mblock_man *mblock, \ return 0; } -int fast_mblock_count(struct fast_mblock_man *mblock) +int fast_mblock_free_count(struct fast_mblock_man *mblock) { struct fast_mblock_node *pNode; int count; diff --git a/common/fast_mblock.h b/common/fast_mblock.h index 496c9c7..858b306 100644 --- a/common/fast_mblock.h +++ b/common/fast_mblock.h @@ -37,11 +37,12 @@ struct fast_mblock_man struct fast_mblock_malloc *malloc_chain_head; //malloc chain to be freed int element_size; //element size int alloc_elements_once; //alloc elements once + int total_count; //total element count pthread_mutex_t lock; //the lock for read / write free node chain }; #define fast_mblock_to_node_ptr(data_ptr) \ - (struct fast_mblock_node *)(data_ptr - ((size_t)(char *) \ + (struct fast_mblock_node *)((char *)data_ptr - ((size_t)(char *) \ &((struct fast_mblock_node *)0)->data)) #ifdef __cplusplus @@ -90,7 +91,9 @@ parameters: mblock: the mblock pointer return the free node count of the mblock, return -1 if fail */ -int fast_mblock_count(struct fast_mblock_man *mblock); +int fast_mblock_free_count(struct fast_mblock_man *mblock); + +#define fast_mblock_total_count(mblock) (mblock)->total_count #ifdef __cplusplus } diff --git a/common/fast_task_queue.h b/common/fast_task_queue.h index 06a873e..785e656 100644 --- a/common/fast_task_queue.h +++ b/common/fast_task_queue.h @@ -47,7 +47,7 @@ struct nio_thread_data struct fast_task_info { - IOEventEntry event; + IOEventEntry event; //must first char client_ip[IP_ADDRESS_SIZE]; void *arg; //extra argument pointer char *data; //buffer for write or recv diff --git a/common/hash.c b/common/hash.c index d364489..47a0af9 100644 --- a/common/hash.c +++ b/common/hash.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "pthread_func.h" #include "hash.h" diff --git a/common/ioevent_loop.c b/common/ioevent_loop.c index 11b0755..f09411b 100644 --- a/common/ioevent_loop.c +++ b/common/ioevent_loop.c @@ -19,20 +19,20 @@ static void deal_ioevents(IOEventPoller *ioevent, const int count) static void deal_timeouts(FastTimerEntry *head) { FastTimerEntry *entry; - FastTimerEntry *curent; + FastTimerEntry *current; IOEventEntry *pEventEntry; entry = head->next; while (entry != NULL) { - curent = entry; + current = entry; entry = entry->next; - pEventEntry = (IOEventEntry *)curent->data; + pEventEntry = (IOEventEntry *)current->data; if (pEventEntry != NULL) { pEventEntry->callback(pEventEntry->fd, IOEVENT_TIMEOUT, - curent->data); + current->data); } } } diff --git a/common/shared_func.c b/common/shared_func.c index f3e9763..814e346 100644 --- a/common/shared_func.c +++ b/common/shared_func.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -1770,8 +1771,7 @@ int parse_bytes(char *pStr, const int default_unit_bytes, int64_t *bytes) if (*bytes < 0) { logError("file: "__FILE__", line: %d, " \ - "bytes: %"PRId64" < 0", \ - __LINE__, *bytes); + "bytes: %"PRId64" < 0", __LINE__, *bytes); return EINVAL; } diff --git a/common/sockopt.c b/common/sockopt.c index 3f4aece..a2bee3f 100644 --- a/common/sockopt.c +++ b/common/sockopt.c @@ -239,7 +239,6 @@ int tcpsenddata(int sock, void* data, const int size, const int timeout) if (pollfds.revents & POLLHUP) { return ENOTCONN; - break; } #endif