connector_t connector_create() { connector_t c = malloc(sizeof(*c)); c->fd_seisize = 0; FD_ZERO(&c->Set); c->_pending_connect = create_link_list(); c->extern_pending_connect = create_link_list(); c->lock = mutex_create(); return c; }
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; }
log_t create_log(const char *path) { log_t l = calloc(1,sizeof(*l)); l->file_descriptor = open(path,O_RDWR|O_CREAT,S_IWUSR|S_IRUSR); if(l->file_descriptor < 0) { free(l); l = 0; } else { l->file_size = 0; l->mtx = mutex_create(); l->log_queue = create_link_list(); l->pending_log = create_link_list(); //add to log system mutex_lock(g_log_system->mtx); LINK_LIST_PUSH_BACK(g_log_system->log_files,l); mutex_unlock(g_log_system->mtx); log_write(l,"open log file",1); } return l; }
int32_t init_log_system() { if(!g_log_system) { g_log_system = calloc(1,sizeof(*g_log_system)); g_log_system->mtx = mutex_create(); g_log_system->is_close = 0; g_log_system->log_files = create_link_list(); g_log_system->worker_thread = CREATE_THREAD_RUN(1,worker_routine,0); g_log_system->last_tick = GetSystemMs(); g_log_system->bytes = 0; g_log_system->_wpacket_allocator = NULL; return 0; } return -1; }