addr foreach_dq (d_q *dq, qfunc f, void *args) { dqlink_t *link; dqlink_t *next; addr rc; for (link = dq->next; link != dq; link = next) { next = link->next; qassert(link->next->prev==link); qassert(link->prev->next==link); rc = f(link, args); if (rc) return rc; } return 0; }
double qtimer_wtime(void) { struct timespec s; qassert(clock_gettime(CLOCK_MONOTONIC, &(s)), 0); return s.tv_sec + (s.tv_nsec * 1e-9); }
static int qopqdp_force_random(lua_State *L) { #define NC QDP_get_nc(g->links[0]) BEGIN_ARGS; GET_GAUGE(g); END_ARGS; QDP_RandomState *rs = g->lat->rs; qassert(rs!=NULL); if(QLA_Nc==3) { // use MILC conventions QLA_RandomState *s = QDP_expose_S(rs); for(int i=0; i<g->nd; i++) { QDP_M_eq_funcia(g->links[i], randforce, s, QDP_all_L(g->qlat)); } QDP_reset_S(rs); } else { QDP_ColorMatrix *m = QDP_create_M_L(g->qlat); for(int i=0; i<g->nd; i++) { QDP_M_eq_gaussian_S(m, rs, QDP_all_L(g->qlat)); QDP_M_eq_antiherm_M(g->links[i], m, QDP_all_L(g->qlat)); } QDP_destroy_M(m); } return 0; #undef NC }
static void destroy_logs() { if (!qlist_empty(&(logger->free_list))) { qlog_free(&(logger->free_list)); qlist_entry_init(&(logger->free_list)); } qassert(qlist_empty(&logger->free_list)); }
unsigned long qtimer_fastrand(void) { struct timespec s; static volatile aligned_t state = GOLDEN_RATIO; volatile aligned_t tmp; // this volatile is to prevent the compiler from optimizing tmp out of existence qassert(clock_gettime(CLOCK_MONOTONIC, &(s)), 0); state = tmp = qt_hash_bytes(&s.tv_nsec, sizeof(s.tv_nsec), state); return tmp; }
static int qopqdp_gauge_zero(lua_State *L) { qassert(lua_gettop(L)==1); gauge_t *g = qopqdp_gauge_check(L, -1); for(int i=0; i<g->nd; i++) { QDP_M_eq_zero(g->links[i], QDP_all_L(g->qlat)); } return 0; }
static int qopqdp_gauge_unit(lua_State *L) { qassert(lua_gettop(L)==1); gauge_t *g = qopqdp_gauge_check(L, -1); QLA_Complex z; QLA_c_eq_r(z, 1); for(int i=0; i<g->nd; i++) { QDP_M_eq_c(g->links[i], &z, QDP_all_L(g->qlat)); } return 0; }
static void socket_accept(int fd, int flags, void *data) { int sock, error; struct sockaddr_in remote; socklen_t n; qsocket_t *socket; lua_State *state; qengine_t *engine; qactor_t *actor; UNUSED(fd); UNUSED(flags); n = sizeof(remote); socket = (qsocket_t*)data; qassert(socket->state == QINET_STATE_ACCEPTING); actor = qactor_get(socket->aid); if (actor == NULL) { return; } actor->waiting_netio = 0; state = actor->state; sock = qnet_tcp_accept(socket->fd, (struct sockaddr*)&remote, &n, &error); if (sock == -1) { lua_pushnil(state); lua_pushfstring(state, "%s accept error:%s", socket->peer, strerror(error)); qlua_resume(state, 2); return; } /* restore the listen fd state */ engine = qactor_get_engine(actor->aid); qevent_del(&socket->event, QEVENT_READ); socket->state = QINET_STATE_LISTENING; socket = new_tcp_socket(sock, state, actor, &remote); if (!socket) { qnet_close(fd); lua_pushnil(state); lua_pushliteral(state, "create socket error"); qlua_resume(state, 2); return; } lua_pushlightuserdata(state, socket); qlua_resume(state, 1); return; }
void qopqdp_gauge_array_check(lua_State *L, int idx, int n, gauge_t *g[n]) { luaL_checktype(L, idx, LUA_TTABLE); qassert(lua_objlen(L, idx)==n); lua_pushvalue(L, idx); // make copy for indexing convenience for(int i=0; i<n; i++) { lua_pushnumber(L, i+1); lua_gettable(L, -2); g[i] = qopqdp_gauge_check(L, -1); lua_pop(L, 1); } lua_pop(L, 1); }
static int worker_start_handler(qmsg_t *msg, void *reader) { qwmsg_start_t *start; qworker_t *worker; int ret; qid_t aid; qactor_t *actor; lua_State *state; qinfo("handle start msg"); worker = (qworker_t*)reader; start = (qwmsg_start_t*)msg; aid = start->aid; actor = qactor_new(aid); if (actor == NULL) { qerror("new actor: %d error", aid); return QERROR; } qassert(actor->state == NULL); qactor_attach(actor, qlua_new_thread(worker, &actor->ref)); actor->tid = worker->tid; if (qlua_threadloadfile(actor, actor->state, config.main) != 0) { qerror("load server start script %s error", config.main); return QERROR; } state = actor->state; lua_getglobal(state, "server"); if (lua_isnil(state, -1)) { qerror("load server script server table error"); return QERROR; } lua_getfield(state, -1, "start"); if (lua_isnil(state, -1)) { qerror("load server script server.start func error"); return QERROR; } if (qlua_call(state, 0, 0) == 0) { ret = (int)lua_tonumber(state, -1); lua_pop(state, 1 ); } else { qlua_fail(state); } return ret; }
int qlog_thread_new(qmem_pool_t *pool, int thread_num) { int i; int result, fd; g_log_thread = qalloc(pool, sizeof(qlog_thread_t)); if (g_log_thread == NULL) { return -1; } if (pthread_key_create(&g_thread_log_key, log_key_destroy) < 0) { return -1; } g_log_thread->engine = qengine_new(pool); if (g_log_thread->engine == NULL) { qfree(pool, g_log_thread, sizeof(qlog_thread_t)); g_log_thread = NULL; return -1; } g_log_thread->thread_num = thread_num; g_log_thread->signals = qalloc(pool, thread_num * sizeof(qsignal_t*)); if (g_log_thread->signals == NULL) { qengine_destroy(g_log_thread->engine); qfree(pool, g_log_thread, sizeof(qlog_thread_t)); g_log_thread = NULL; return -1; } for (i = 0; i < thread_num; ++i) { g_log_thread->signals[i] = qsignal_new(pool); fd = qsignal_get_fd(g_log_thread->signals[i]); qengine_add_event(g_log_thread->engine, fd, QEVENT_READ, thread_log_box, g_log_thread->signals[i]); } g_log_thread->started = 0; result = pthread_create(&g_log_thread->id, NULL, main_loop, g_log_thread); qassert(result == 0); /* ugly, but works */ while (g_log_thread->started == 0) { usleep(100); } return 0; }
qtest(testFoo3, Bar2Case) { qassert(true); }
qtest(testFoo2, Bar2Case) { qassert(i != 0); }
void qtimer_stop(qtimer_t q) { assert(q); qassert(clock_gettime(CLOCK_MONOTONIC, &(q->stop)), 0); }
qtest(testFoo2, BarCase) { qassert(true); }
qtest(testFoo, BarCase) { qassert(i != 0); }