static int traverse_fn(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { struct lock_struct *locks; struct lock_key *key; int i; BRLOCK_FN(traverse_callback) = (BRLOCK_FN_CAST())state; locks = (struct lock_struct *)dbuf.dptr; key = (struct lock_key *)kbuf.dptr; for (i=0;i<dbuf.dsize/sizeof(*locks);i++) { traverse_callback(key->device, key->inode, locks[i].context.pid, locks[i].lock_type, locks[i].start, locks[i].size); } return 0; }
/**************************************************************************** traverse the whole database with this function, calling traverse_callback on each share mode ****************************************************************************/ static int traverse_fn(TDB_CONTEXT * the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { struct locking_data *data; share_mode_entry *shares; char *name; int i; SHAREMODE_FN(traverse_callback) = (SHAREMODE_FN_CAST())state; data = (struct locking_data *)dbuf.dptr; shares = (share_mode_entry *) (dbuf.dptr + sizeof(*data)); name = dbuf.dptr + sizeof(*data) + data->num_share_mode_entries * sizeof(*shares); for (i = 0; i < data->num_share_mode_entries; i++) { traverse_callback(&shares[i], name); } return 0; }
static void run() { cmd_t* cmd = cmd_create(".history", "~>"); cmd_register(cmd, "base conhash", test_base_conhash); cmd_register(cmd, "base bitset", test_base_bitset); cmd_register(cmd, "base heap", test_base_heap); cmd_register(cmd, "base rbtree", test_base_rbtree); cmd_register(cmd, "base rbuffer", test_base_rbuffer); cmd_register(cmd, "base slist", test_base_slist); cmd_register(cmd, "base skiplist", test_base_skiplist); cmd_register(cmd, "base skiplist find", test_base_skiplist_find); cmd_register(cmd, "base skiplist duplicate", test_base_skiplist_duplicate); cmd_register(cmd, "base timer", test_base_timer); cmd_register(cmd, "core atomic", test_core_atomic); #ifdef OS_LINUX // seems some memory error ... // cmd_register(cmd, "core coroutine", test_core_coroutine); #endif cmd_register(cmd, "core fsm", test_core_fsm); cmd_register(cmd, "core lock", test_core_lock); cmd_register(cmd, "core spin", test_core_spin); cmd_register(cmd, "core thread", test_core_thread); cmd_register(cmd, "logic dirty", test_logic_dirty); cmd_register(cmd, "logic task", test_logic_task); cmd_register(cmd, "mm slab", test_mm_slab); cmd_register(cmd, "mm shm", test_mm_shm); cmd_register(cmd, "net curl", test_net_curl); cmd_register(cmd, "net echo", test_net_echo); cmd_register(cmd, "util base64", test_util_base64); cmd_register(cmd, "util cjson text", test_util_cjson_text); cmd_register(cmd, "util cjson file", test_util_cjson_file); cmd_register(cmd, "util cjson create", test_util_cjson_create); cmd_register(cmd, "util dh", test_util_dh); cmd_register(cmd, "util dh perf", test_util_dh_perf); cmd_register(cmd, "util random", test_util_random); cmd_register(cmd, "util shuffle", test_util_shuffle); cmd_register(cmd, "util unicode", test_util_unicode); cmd_register(cmd, "util wscode", test_util_wscode); // unit test mode if (mode_all) { int res = cmd_traverse(cmd, NULL, traverse_callback); if (res < 0) { fprintf(stderr, "\033[%dm--> [RUN ALL TEST CASES FAILURE] <--\033[0m\n\n", COLOR_RED); cmd_release(cmd); exit(res); } } // interact mode if (mode_interact) { while (1) { char* line = cmd_readline(cmd); if (!line) { break; } int ret = cmd_handle(cmd, line); traverse_callback(line, ret); free(line); if (cmd_eof(cmd)) { if (cmd_closed(cmd)) { break; } } } } cmd_release(cmd); }