/* send delayed message according to the key */ void delay_table_send(uint64_t key, int fd) { link_list *msg_list; p_link_node first; msg_server_t *msg ; msg_list = (link_list *) hash_find(table, key); if (msg_list == NULL) { return; } while (!link_list_is_empty(msg_list)) { first = link_list_pop_first(msg_list); msg = (first->data); #if (INTERCEPT_COMBINED) buffer_and_send(fd, fd, msg); #else tc_socket_send(fd, (char *) msg, MSG_SERVER_SIZE); #endif msg_delay_sent_cnt++; msg_item_free_cnt++; link_node_internal_free(first); free(first); } }
void delay_table_snd(uint64_t key, int fd) { link_list *msg_list; p_link_node first; msg_server_t *msg ; delay_sess_t *s; s = (delay_sess_t *) hash_find(table, key); if (s == NULL || s->msg_list == NULL) { return; } msg_list = s->msg_list; while (!link_list_is_empty(msg_list)) { first = link_list_pop_first(msg_list); msg = (first->data); #if (TC_COMBINED) buffer_and_snd(fd, msg); #else if (tc_socket_snd(fd, (char *) msg, MSG_SERVER_SIZE) == TC_ERR) { tc_intercept_release_tunnel(fd, NULL); } #endif msg_delay_sent_cnt++; msg_item_free_cnt++; tc_pfree(s->pool, first); } }
int main(int argc, char *argv[]) { struct link_list * list = create_link_list(); list_node node; node.next = NULL; struct A * a = malloc(sizeof(*a)); a->node = node; a->a = 1; printf("list_node = %p\n",((list_node *)a)->next); printf("a = %p\n",a); // printf("pointer = %p\n",a->next); link_list_push_tail(list, (list_node *)a); list_node node1; node1.next = NULL; // struct A b = {node1, 2}; struct A * b = malloc(sizeof(*b)); b->node = node; b->a = 2; link_list_push_tail(list, (list_node *)b); while (link_list_is_empty(list) == 0) { list_node * node; node = link_list_pop(list); printf("node = %d\n",((struct A*)node)->a); } return 0; }
static inline mq_sync_pop(mq_t m,struct per_thread_struct *pts,uint32_t timeout) { mutex_lock(m->mtx); if(link_list_is_empty(m->share_list)) { if(timeout) { while(link_list_is_empty(m->share_list)) { double_link_push(&m->blocks,&pts->block); if(0 != condition_timedwait(pts->cond,m->mtx,timeout)) { double_link_remove(&pts->block); break; } } } } link_list_swap(pts->local_pop_q,m->share_list); mutex_unlock(m->mtx); }
void mq_push_list(mq_t m,struct link_list *l,uint32_t timeout) { struct per_thread_struct *pts = (struct per_thread_struct*)pthread_getspecific(m->t_key); if(!pts) { pts = per_thread_create(); LINK_LIST_PUSH_BACK(m->local_lists,pts); pthread_setspecific(m->t_key,(void*)pts); } if(link_list_is_empty(pts->local_pop_q)) mq_sync_pop(m,pts,timeout); link_list_swap(l,pts->local_pop_q); }
void sche_schedule(sche_t s) { uint32_t now = GetCurrentMs(); if(now >= s->next_check_timeout) check_time_out(s,now); if(link_list_is_empty(s->active_list_1) && link_list_is_empty(s->active_list_2)) { if(s->idel) s->idel(s->idel_arg); else sleepms(50); } else { coro_t co = _sche_next(s,s->co); if(co->status == CORO_DIE && co->_heapele.index == 0) { coro_destroy(&co); printf("a coro destroy\n"); } } }
static void destroy_log(log_t *l) { mutex_lock((*l)->mtx); while(!link_list_is_empty((*l)->log_queue)) { wpacket_t w = LINK_LIST_POP(wpacket_t,(*l)->log_queue); wpacket_destroy(&w); } mutex_unlock((*l)->mtx); close((*l)->file_descriptor); mutex_destroy(&(*l)->mtx); destroy_link_list(&(*l)->log_queue); destroy_link_list(&(*l)->pending_log); free(*l); *l = 0; }
static inline mq_sync_push(mq_t m,struct per_thread_struct *pts) { mutex_lock(m->mtx); uint8_t empty = link_list_is_empty(m->share_list); link_list_swap(m->share_list,pts->local_push_q); if(empty) { struct double_link_node *l = double_link_pop(&m->blocks); if(l) { //if there is block per_thread_struct wake it up struct per_thread_struct *block_pts = (struct per_thread_struct *)((uint8_t*)l - sizeof(struct list_node)); mutex_unlock(m->mtx); condition_signal(block_pts->cond); return; } } mutex_unlock(m->mtx); }
void close_log_system() { COMPARE_AND_SWAP(&(g_log_system->is_close),0,1); //停止写日志线程,并等待结束 //g_log_system->is_close = 1; thread_join(g_log_system->worker_thread); mutex_lock(g_log_system->mtx); while(!link_list_is_empty(g_log_system->log_files)) { log_t l = LINK_LIST_POP(log_t,g_log_system->log_files); destroy_log(&l); } mutex_unlock(g_log_system->mtx); mutex_destroy(&g_log_system->mtx); destroy_link_list(&g_log_system->log_files); destroy_thread(&g_log_system->worker_thread); //DESTROY(&(g_log_system->_wpacket_allocator)); free(g_log_system); g_log_system = 0; }
/* delete delay table item according to the key */ void delay_table_del(uint64_t key) { link_list *msg_list; p_link_node first; msg_list = (link_list *) hash_find(table, key); if (msg_list == NULL) { return; } while (!link_list_is_empty(msg_list)) { first = link_list_pop_first(msg_list); msg_item_free_cnt++; link_node_internal_free(first); free(first); } hash_del(table, key); free(msg_list); msg_ls_free_cnt++; }
static inline void mq_force_sync(mq_t m) { struct per_thread_struct *pts = (struct per_thread_struct*)pthread_getspecific(m->t_key); if(link_list_is_empty(pts->local_push_q) == 0) mq_sync_push(m,pts); }