static inline int8_t _put(msgque_t que,lnode *msg,uint8_t type) { ptq_t ptq = get_per_thread_que(que,MSGQ_WRITE); if(ptq->mode == MSGQ_READ && msg) { msgque_sync_pop(ptq,0); LLIST_PUSH_BACK(&ptq->local_que,msg); return 0; }else if(ptq->mode == MSGQ_WRITE) { ptq->write_que.flag = 1; pts_t pts = get_per_thread_struct(); dlist_push(&pts->per_thread_que,&ptq->write_que.pnode); if(msg)LLIST_PUSH_BACK(&ptq->local_que,msg); if(type == 1) msgque_sync_push(ptq); else if(type == 2){ if(ptq->write_que.flag == 2 || llist_size(&ptq->local_que) >= que->syn_size) msgque_sync_push(ptq); } ptq->write_que.flag = 0; return 0; } return -1; }
logfile_t create_logfile(const char *filename) { pthread_once(&g_log_key_once,log_once_routine); logfile_t _logfile = calloc(1,sizeof(*_logfile)); _logfile->filename = new_string(filename); mutex_lock(g_mtx_log_file_list); LLIST_PUSH_BACK(&g_log_file_list,_logfile); mutex_unlock(g_mtx_log_file_list); LOG(_logfile,LOG_INFO,"log open success"); return _logfile; }
static void log_once_routine(){ //pthread_key_create(&g_log_key,NULL); llist_init(&g_log_file_list); sys_log = calloc(1,sizeof(*sys_log)); sys_log->filename = new_string(SYSLOG_NAME); g_mtx_log_file_list = mutex_create(); mutex_lock(g_mtx_log_file_list); LLIST_PUSH_BACK(&g_log_file_list,sys_log); mutex_unlock(g_mtx_log_file_list); pending_log = new_msgque(64,default_item_destroyer); g_log_thd = create_thread(THREAD_JOINABLE); thread_start_run(g_log_thd,log_routine,NULL); atexit(on_process_end); LOG(sys_log,LOG_INFO,"log open success"); }
int32_t send_packet(struct connection *c,wpacket_t w) { if(!test_sendable(c->status)){ wpk_destroy(&w); return -1; } st_io *O; if(w){ w->base.tstamp = GetSystemMs64(); LLIST_PUSH_BACK(&c->send_list,w); } if(!c->doing_send){ c->doing_send = 1; O = prepare_send(c); if(O) return Post_Send(c->socket,O); } return 0; }