Makefile | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
demo/dgram_mod_bus | 补丁 | 查看 | 原始文档 | blame | 历史 | |
demo/dgram_mod_req_rep | 补丁 | 查看 | 原始文档 | blame | 历史 | |
demo/dgram_mod_survey | 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/libshm_queue.a | 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/queue/hashtable.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/queue/include/hashtable.h | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/Makefile | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/lambda.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/protocle_parse | 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/strtok | 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/test | 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/test.c | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/test_set | 补丁 | 查看 | 原始文档 | blame | 历史 | |
test/test_vector | 补丁 | 查看 | 原始文档 | blame | 历史 | |
test_socket/dgram_mod_bus | 补丁 | 查看 | 原始文档 | blame | 历史 | |
test_socket/dgram_mod_req_rep | 补丁 | 查看 | 原始文档 | blame | 历史 | |
test_socket/dgram_mod_survey | 补丁 | 查看 | 原始文档 | blame | 历史 |
Makefile
@@ -1,5 +1,6 @@ DIRS = src test_socket demo DIRS = src test_socket demo test TAR_NAME = shm_queue.tar.gz all: for i in $(DIRS); do \ (cd $$i && echo "making $$i" && $(MAKE) ) || exit 1; \ demo/dgram_mod_busBinary files differ
demo/dgram_mod_req_repBinary files differ
demo/dgram_mod_surveyBinary files differ
src/libshm_queue.aBinary files differ
src/queue/hashtable.c
@@ -3,6 +3,7 @@ #include "mm.h" #include "sem_util.h" #include <set> #include <functional> typedef struct tailq_entry_t { @@ -32,7 +33,7 @@ } void *_hashtable_get(hashtable_t *hashtable, int key) static inline void *_hashtable_get(hashtable_t *hashtable, int key) { size_t code = hashcode(key); tailq_entry_t *item; @@ -54,7 +55,7 @@ } void * _hashtable_put(hashtable_t *hashtable, int key, void *value) static inline void * _hashtable_put(hashtable_t *hashtable, int key, void *value) { size_t code = hashcode(key); void *oldvalue; @@ -187,8 +188,11 @@ SemUtil::dec(hashtable->wlock); } SemUtil::inc(hashtable->mutex); // ================ void * res = _hashtable_get(hashtable, key); // ================== SemUtil::dec(hashtable->mutex); hashtable->readcnt--; @@ -204,6 +208,7 @@ void hashtable_put(hashtable_t *hashtable, int key, void *value) { SemUtil::dec(hashtable->mutex); // 设置读优先级高 while (hashtable->readcnt > 0) { SemUtil::set(hashtable->cond, 0); @@ -218,6 +223,7 @@ //获取读写锁 SemUtil::dec(hashtable->wlock); _hashtable_put(hashtable, key, value); //释放读写锁 SemUtil::inc(hashtable->wlock); @@ -225,7 +231,7 @@ void hashtable_foreach(hashtable_t *hashtable, hashtable_foreach_cb cb) { static inline void _hashtable_foreach(hashtable_t *hashtable, std::function<void(int, void *)> cb) { tailq_entry_t *item; for (int i = 0; i < MAPSIZE; i++) { tailq_header_t *my_tailq_head = hashtable->array[i] ; @@ -240,18 +246,35 @@ } } int hashtable_alloc_key(hashtable_t *hashtable) { int key = START_KEY; SemUtil::dec(hashtable->wlock); while(_hashtable_get(hashtable, key) != NULL) { key++; } void hashtable_foreach(hashtable_t *hashtable, hashtable_foreach_cb cb) { SemUtil::dec(hashtable->mutex); hashtable->readcnt++; if (hashtable->readcnt == 1) { //获取读写锁 SemUtil::dec(hashtable->wlock); } SemUtil::inc(hashtable->mutex); _hashtable_put(hashtable, key, (void *)1); SemUtil::inc(hashtable->wlock); return key; // ================== _hashtable_foreach(hashtable, cb); // ================== SemUtil::dec(hashtable->mutex); hashtable->readcnt--; if(hashtable->readcnt == 0) { //释放读写锁 SemUtil::inc(hashtable->wlock); //通知写 SemUtil::set(hashtable->cond, 1); } SemUtil::inc(hashtable->mutex); } std::set<int> * hashtable_keyset(hashtable_t *hashtable) { std::set<int> *keyset = new std::set<int>; @@ -271,3 +294,17 @@ } int hashtable_alloc_key(hashtable_t *hashtable) { int key = START_KEY; SemUtil::dec(hashtable->wlock); while(_hashtable_get(hashtable, key) != NULL) { key++; } _hashtable_put(hashtable, key, (void *)1); SemUtil::inc(hashtable->wlock); return key; } src/queue/include/hashtable.h
@@ -23,10 +23,17 @@ void *hashtable_remove(hashtable_t *hashtable, int key); void hashtable_removeall(hashtable_t *hashtable); /** * 遍历hash_table * @demo * hashtable_foreach(&hashtable, [&](int key, void * value){ * printf("%d, %p\n", key, value); * }); * */ void hashtable_foreach(hashtable_t *hashtable, hashtable_foreach_cb cb); void hashtable_printall(hashtable_t *hashtable); // void hashtable_printall(hashtable_t *hashtable); int hashtable_alloc_key(hashtable_t *hashtable); test/Makefile
@@ -14,7 +14,7 @@ include $(ROOT)/Make.defines.$(PLATFORM) PROGS = protocle_parse strtok test_set test_vector PROGS = protocle_parse strtok test_set test_vector lambda test build: $(PROGS) test/lambda.c
New file @@ -0,0 +1,19 @@ #include "usg_common.h" #include "usg_typedef.h" #include "hashtable.h" #include "shm_mm.h" int main() { shm_init(512); hashtable_t hashtable; hashtable_init(&hashtable); for(int i = 0; i < 10; i++) { hashtable_put(&hashtable, i, (void *)(i)); } hashtable_foreach(&hashtable, [&](int key, void * value){ printf("%d, %p\n", key, value); }); shm_destroy(); } test/protocle_parseBinary files differ
test/strtokBinary files differ
test/testBinary files differ
test/test.c
@@ -1,12 +1,15 @@ #include "usg_common.h" #include "usg_typedef.h" void test(char *src, int size) { int test(char *src, int size) { int i = strlen(src); char dest[size]; strncpy(dest, src, size); puts(dest); return i; } int main() { char *str = "hello"; test(str, strlen(str)); int r = test(str, strlen(str)); printf("%d\n", r); } test/test_setBinary files differ
test/test_vectorBinary files differ
test_socket/dgram_mod_busBinary files differ
test_socket/dgram_mod_req_repBinary files differ
test_socket/dgram_mod_surveyBinary files differ