#ifndef _HEADER_HPP #define _HEADER_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //////utils #define __XASSERT(flag, fmt, arg...) \ {\ bool ___bsl_flag = flag; \ if (!(___bsl_flag)) { \ fprintf(stdout, "\n[error][%s:%d][%s]"fmt"\n", __FILE__, __LINE__, #flag, ##arg); \ return false; \ }\ } #define __XASSERT2(flag) __XASSERT(flag, "") static std::vector g_pid; static bool g_pthread_flag = true; #define __XASSERT_R(flag, fmt, arg...) \ {\ bool ___bsl_flag = flag; \ if (!(___bsl_flag)) { \ fprintf(stdout, "\n[error][%s:%d][%s]"fmt"\n", __FILE__, __LINE__, #flag, ##arg); \ g_pthread_flag = false; \ for (int i=0; i<(int)g_pid.size(); ++i) { \ if (g_pid[i] != pthread_self()) { \ int ret = pthread_cancel(g_pid[i]); \ fprintf(stdout, "\n[error]kill pthread_t[%ld][%d]ret[%d][%m]\n", (long)g_pid[i], i, ret); \ } \ } \ return NULL; \ }\ } #define __XASSERT2_R(flag) __XASSERT_R(flag, "") class auto_timer { char buf[64]; timeval s, e; public: auto_timer(const char *str = NULL) { buf[0] = 0; if (str) snprintf(buf, sizeof(buf), "%s", str); gettimeofday(&s, NULL); } auto_timer(const char *str, int val) { snprintf(buf, sizeof(buf), "%s %d ", str, val); gettimeofday(&s, NULL); } ~auto_timer() { gettimeofday(&e, NULL); long t = (long)((e.tv_sec - s.tv_sec) * 1000000 + (e.tv_usec - s.tv_usec)); if (t/1000 > 0) { __BSL_DEBUG("%s %ld", buf, t); } } }; class dis_timer { timeval s, e; public: void start() { gettimeofday(&s, NULL); } void end() { gettimeofday(&e, NULL); } int costms () { return (int)((e.tv_sec-s.tv_sec)*1000 + (e.tv_usec-s.tv_usec)/1000); } }; std::string randstr(int wan=32) { char buf[130] = {0}; int len = rand()%wan + 1; for (int i=0; i bool test_phashmap_temp(int pnum, void *(*pfun)(void *), int upnum, void *(*upfun)(void *), int lnum = 0, void *(*lfun)(void *) = 0) { HASH * test = new (std::nothrow) HASH; g_pthread_flag = true; __XASSERT2(test != NULL); __XASSERT2(test->create(1<<20) == 0); g_pid.clear(); pthread_t pid; { //auto_timer t("phashmap costime"); for (int i=0; i