wangzhengquan
2021-02-08 bc2afe32e8db4318f2a2adea49d85b10d0d4cc97
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#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}\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();
 
 
}