void gearman_server_thread_free(gearman_server_thread_st *thread) { gearman_server_con_st *con; gearman_server_packet_st *packet; _proc_thread_kill(thread->server); while (thread->con_list != NULL) gearman_server_con_free(thread->con_list); while (thread->free_con_list != NULL) { con= thread->free_con_list; thread->free_con_list= con->next; free(con); } while (thread->free_packet_list != NULL) { packet= thread->free_packet_list; thread->free_packet_list= packet->next; free(packet); } if (thread->gearman != NULL) gearman_universal_free(thread->gearman); pthread_mutex_destroy(&(thread->lock)); GEARMAN_LIST_DEL(thread->server->thread, thread,) if (thread->options.allocated) free(thread); }
void gearman_server_thread_free(gearman_server_thread_st *thread) { _proc_thread_kill(Server); while (thread->con_list != NULL) { gearman_server_con_free(thread->con_list); } while (thread->free_con_list != NULL) { gearman_server_con_st *con= thread->free_con_list; thread->free_con_list= con->next; destroy_gearman_server_con_st(con); } while (thread->free_packet_list != NULL) { gearman_server_packet_st *packet= thread->free_packet_list; thread->free_packet_list= packet->next; destroy_gearman_server_packet_st(packet); } if (thread->gearman != NULL) { gearman_connection_list_free(thread->gearman); } pthread_mutex_destroy(&(thread->lock)); GEARMAN_LIST_DEL(Server->thread, thread,) }
gearman_server_thread_st * gearman_server_thread_create(gearman_server_st *server, gearman_server_thread_st *thread) { if (server->thread_count == 1) { /* The server is going to be multi-threaded, start processing thread. */ if (_proc_thread_start(server) != GEARMAN_SUCCESS) return NULL; } if (thread == NULL) { thread= (gearman_server_thread_st *)malloc(sizeof(gearman_server_thread_st)); if (thread == NULL) { _proc_thread_kill(server); return NULL; } thread->options.allocated= true; } else { thread->options.allocated= false; } thread->con_count= 0; thread->io_count= 0; thread->proc_count= 0; thread->free_con_count= 0; thread->free_packet_count= 0; thread->server= server; thread->log_fn= NULL; thread->log_context= NULL; thread->run_fn= NULL; thread->run_fn_arg= NULL; thread->con_list= NULL; thread->io_list= NULL; thread->proc_list= NULL; thread->free_con_list= NULL; thread->free_packet_list= NULL; if (pthread_mutex_init(&(thread->lock), NULL) != 0) { if (thread->options.allocated) free(thread); return NULL; } GEARMAN_LIST_ADD(server->thread, thread,); gearman_universal_options_t options[]= { GEARMAN_NON_BLOCKING, GEARMAN_DONT_TRACK_PACKETS, GEARMAN_MAX}; thread->gearman= gearman_universal_create(&(thread->gearman_universal_static), options); if (thread->gearman == NULL) { gearman_server_thread_free(thread); return NULL; } return thread; }