src/queue/hashtable.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/queue/include/lock_free_queue.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/queue/socket.c.bk | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test_socket/dgram_mod_req_rep.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/queue/hashtable.c
@@ -20,6 +20,7 @@ typedef TAILQ_HEAD(tailq_header_t, tailq_entry_t) tailq_header_t; static size_t hashcode(int key); void hashtable_init(hashtable_t *hashtable ) @@ -30,6 +31,7 @@ hashtable->wlock = SemUtil::get(IPC_PRIVATE, 1); hashtable->cond = SemUtil::get(IPC_PRIVATE, 1); hashtable->readcnt = 0; } @@ -181,11 +183,17 @@ void *hashtable_get(hashtable_t *hashtable, int key) { SemUtil::dec(hashtable->mutex); struct timespec timeout = {1, 0}; if (SemUtil::dec_timeout(hashtable->mutex, &timeout) != 0) { SemUtil::inc(hashtable->mutex); SemUtil::dec(hashtable->mutex); } hashtable->readcnt++; if (hashtable->readcnt == 1) { //获取读写锁 SemUtil::dec(hashtable->wlock); // err_msg(0, "hashtable_get dec %d %d\n", --hashtable->tmp); } SemUtil::inc(hashtable->mutex); // ================ @@ -199,6 +207,7 @@ if(hashtable->readcnt == 0) { //释放读写锁 SemUtil::inc(hashtable->wlock); // err_msg(0, "hashtable_get inc %d\n", ++hashtable->tmp); //通知写 SemUtil::set(hashtable->cond, 1); } @@ -207,14 +216,22 @@ } void hashtable_put(hashtable_t *hashtable, int key, void *value) { SemUtil::dec(hashtable->mutex); struct timespec timeout = {2, 0}; if (SemUtil::dec_timeout(hashtable->mutex, &timeout) != 0) { SemUtil::inc(hashtable->mutex); SemUtil::dec(hashtable->mutex); } // 设置读优先级高 while (hashtable->readcnt > 0) { SemUtil::set(hashtable->cond, 0); SemUtil::inc(hashtable->mutex); //等待写通知 SemUtil::dec(hashtable->cond); if (SemUtil::dec_timeout(hashtable->cond, &timeout) != 0) { hashtable->readcnt = 0; SemUtil::inc(hashtable->cond); SemUtil::dec(hashtable->cond); } SemUtil::dec(hashtable->mutex); @@ -222,11 +239,15 @@ SemUtil::inc(hashtable->mutex); //获取读写锁 SemUtil::dec(hashtable->wlock); // err_msg(0, "hashtable_put dec %d\n", --hashtable->tmp); _hashtable_put(hashtable, key, value); //释放读写锁 SemUtil::inc(hashtable->wlock); // err_msg(0, "hashtable_put inc %d\n", ++hashtable->tmp); } @@ -295,13 +316,20 @@ int hashtable_alloc_key(hashtable_t *hashtable) { int key = START_KEY; SemUtil::dec(hashtable->wlock); struct timespec timeout = {1, 0}; if (SemUtil::dec_timeout(hashtable->wlock, &timeout) != 0) { SemUtil::inc(hashtable->wlock); SemUtil::dec(hashtable->wlock); } while(_hashtable_get(hashtable, key) != NULL) { key++; } // 占用key _hashtable_put(hashtable, key, (void *)1); SemUtil::inc(hashtable->wlock); // err_msg(0, "hashtable_alloc_key inc %d\n", ++hashtable->tmp); return key; } src/queue/include/lock_free_queue.h
@@ -200,7 +200,7 @@ template <typename T, typename AT> class Q_TYPE> bool LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::push(const ELEM_T &a_data) { // printf("==================LockFreeQueue push before\n"); // printf("==================LockFreeQueue push before\n"); if (SemUtil::dec(slots) == -1) { err_msg(errno, "LockFreeQueue push"); return false; @@ -209,7 +209,7 @@ if ( m_qImpl.push(a_data) ) { SemUtil::inc(items); // printf("==================LockFreeQueue push after\n"); // printf("==================LockFreeQueue push after\n"); return true; } return false; @@ -274,7 +274,7 @@ template <typename T, typename AT> class Q_TYPE> bool LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::pop(ELEM_T &a_data) { // printf("==================LockFreeQueue pop before\n"); // printf("==================LockFreeQueue pop before\n"); if (SemUtil::dec(items) == -1) { err_msg(errno, "LockFreeQueue pop"); return false; @@ -282,7 +282,7 @@ if (m_qImpl.pop(a_data)) { SemUtil::inc(slots); // printf("==================LockFreeQueue pop after\n"); // printf("==================LockFreeQueue pop after\n"); return true; } return false; @@ -319,6 +319,7 @@ template <typename T, typename AT> class Q_TYPE> bool LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::pop_timeout(ELEM_T &a_data, struct timespec * timeout) { // printf("==================LockFreeQueue pop_timeout before\n"); if (SemUtil::dec_timeout(items, timeout) == -1) { if (errno == EAGAIN) return false; @@ -329,7 +330,8 @@ } if (m_qImpl.pop(a_data)) { SemUtil::inc(slots); SemUtil::inc(slots); // printf("==================LockFreeQueue pop_timeout after\n"); return true; } return false; src/queue/socket.c.bk
File was deleted test_socket/dgram_mod_req_rep.c
@@ -163,8 +163,10 @@ // int temp = shm_alloc_key(); // printf("tmp=%d\n", temp); server(port); } else if (strcmp("client", argv[1]) == 0) { } else if (strcmp("mclient", argv[1]) == 0) { startClients(port); } else if (strcmp("client", argv[1]) == 0) { client(port); } else { printf("input invalidate arguments\n"); }