From f71c50e9470d18afc9716378537c9cdfca315368 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期四, 25 二月 2021 14:25:58 +0800
Subject: [PATCH] update
---
shm_util/CMakeLists.txt | 31 +++++++++++++--
/dev/null | 66 ---------------------------------
test_net_socket/shm_util.cpp | 14 +++++--
shm_util/shm_util.cpp | 1
CMakeLists.txt | 1
5 files changed, 39 insertions(+), 74 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8cbc168..5d9be24 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,4 +30,5 @@
add_subdirectory(${PROJECT_SOURCE_DIR}/test)
add_subdirectory(${PROJECT_SOURCE_DIR}/test_net_socket)
add_subdirectory(${PROJECT_SOURCE_DIR}/test_socket)
+ add_subdirectory(${PROJECT_SOURCE_DIR}/shm_util)
endif()
diff --git a/shm_util/CMakeLists.txt b/shm_util/CMakeLists.txt
index e58ff5b..038b858 100644
--- a/shm_util/CMakeLists.txt
+++ b/shm_util/CMakeLists.txt
@@ -1,11 +1,34 @@
-add_executable(shm_util shm_util.cpp )
-target_link_libraries(shm_util PRIVATE shm_queue ${EXTRA_LIBS} )
-target_include_directories(shm_util PRIVATE
- "${PROJECT_BINARY_DIR}"
+find_library(SHMQUEUE
+ NAMES shm_queue libshm_queue
+ HINTS "/home/wzq/Downloads"
+)
+
+
+if(SHMQUEUE)
+ message(STATUS "Looking for SHMQUEUE - found: ${SHMQUEUE}")
+else()
+ message(STATUS "Looking for SHMQUEUE - not found")
+endif()
+
+list(APPEND M_INCLUDES
+ ${PROJECT_BINARY_DIR}/src
+ ${PROJECT_SOURCE_DIR}/src
+ ${PROJECT_SOURCE_DIR}/src/shm
+ ${PROJECT_SOURCE_DIR}/src/queue
+ ${PROJECT_SOURCE_DIR}/src/socket
+ ${PROJECT_SOURCE_DIR}/src/net
+)
+
+add_executable(shm_util2 shm_util.cpp )
+target_link_libraries(shm_util2 PRIVATE ${SHMQUEUE} ${EXTRA_LIBS} )
+target_include_directories(shm_util2 PRIVATE
+ ${PROJECT_BINARY_DIR}
${EXTRA_INCLUDES}
+ ${M_INCLUDES}
)
+
add_executable(shm_map shm_map.cpp )
target_link_libraries(shm_map PRIVATE shm_queue ${EXTRA_LIBS} )
target_include_directories(shm_map PRIVATE
diff --git a/shm_util/shm_util.cpp b/shm_util/shm_util.cpp
deleted file mode 100644
index 8ce411e..0000000
--- a/shm_util/shm_util.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * 鏌ョ湅涓庣Щ鍑簁ey鐨勫伐鍏�
- */
-#include <assert.h>
-#include "net_mod_server_socket_wrapper.h"
-#include "net_mod_socket_wrapper.h"
-#include "bus_server_socket_wrapper.h"
-
-#include "shm_mm_wrapper.h"
-#include "usg_common.h"
-#include <getopt.h>
-#include "logger_factory.h"
-
-
-static void usage(const char *name) {
- printf("Usage: %s {list | rm ...}\n", name);
-
-}
-
-
-void list () {
- hashtable_t *hashtable = mm_get_hashtable();
- hashtable_foreach(hashtable, [&](int key, void * value){
- printf("%d\n", key);
- });
-}
-
-
-void remove(int key) {
- hashtable_t *hashtable = mm_get_hashtable();
-
- LockFreeQueue<shm_packet_t> * mqueue = (LockFreeQueue<shm_packet_t> *)hashtable_get(hashtable, key);
- if(mqueue != NULL) {
- delete mqueue;
- hashtable_remove(hashtable, key);
- }
-}
-
-int main(int argc, char *argv[]) {
- shm_mm_wrapper_init(512);
- int key;
- int i;
- if(argc < 2) {
- usage(argv[0]);
- return 1;
- }
-
- if(strcmp(argv[1], "list") == 0) {
- list();
- }
- else if(strcmp(argv[1], "rm") == 0) {
- if(argc < 3) {
- usage(argv[0]);
- return 1;
- }
- for(i = 2; i < argc; i++) {
- key = atoi(argv[i]);
- remove(key);
- }
-
- }
-
- shm_mm_wrapper_destroy();
-
-
-}
\ No newline at end of file
diff --git a/shm_util/shm_util.cpp b/shm_util/shm_util.cpp
new file mode 120000
index 0000000..5878b94
--- /dev/null
+++ b/shm_util/shm_util.cpp
@@ -0,0 +1 @@
+../test_net_socket/shm_util.cpp
\ No newline at end of file
diff --git a/test_net_socket/shm_util.cpp b/test_net_socket/shm_util.cpp
index 34efbc4..bf214ed 100644
--- a/test_net_socket/shm_util.cpp
+++ b/test_net_socket/shm_util.cpp
@@ -526,9 +526,17 @@
}
void list () {
+ LockFreeQueue<shm_packet_t> * mqueue;
hashtable_t *hashtable = mm_get_hashtable();
+ printf("%10s \t %10s\n", "KEY", "LENGTH");
hashtable_foreach(hashtable, [&](int key, void * value){
- printf("%d\n", key);
+ if(key >= 100 ) {
+ mqueue = (LockFreeQueue<shm_packet_t> *)hashtable_get(hashtable, key);
+ printf("%10d \t %10d\n", key, mqueue->size());
+ } else {
+ printf("%10d \t %10s\n", key, "");
+ }
+
});
}
@@ -820,7 +828,6 @@
else if (strcmp("start_reply", fun) == 0) {
opt = parse_args(argc, argv);
- opt = parse_args(argc, argv);
if(opt.key == 0) {
usage(argv[0]);
exit(1);
@@ -889,7 +896,6 @@
}
- printf("==========end========\n");
- // shm_mm_wrapper_destroy();
+ shm_mm_wrapper_destroy();
}
--
Gitblit v1.8.0