int on_channel(int epoll_fd, int fd) { channel ch; if(recv_fd(fd, &ch) == L_HTTP_FAIL) { printf("receive fd fail\n"); return L_HTTP_FAIL; } switch(ch.cmd) { case HTTP_COMMAND_TRANS_FD: return add_connection(epoll_fd, ch.fd); case HTTP_COMMAND_RESTART: break; case HTTP_COMMAND_EXIT: syslog(LOG_INFO, "proc:%d receive shutdown cmd", getpid()); worker_shutdown(epoll_fd); break; default: printf("unknown cmd type\n"); return L_HTTP_FAIL; } return L_HTTP_SUCCESS; }
/*! * \brief Worker thread destructor * * Called automatically when refcount reaches 0. Shuts * down the worker thread and destroys its component * parts */ static void worker_thread_destroy(void *obj) { struct worker_thread *worker = obj; ast_debug(3, "Destroying worker thread %d\n", worker->id); worker_shutdown(worker); ast_mutex_destroy(&worker->lock); ast_cond_destroy(&worker->cond); }
/* * queue_free: * queue: the #Queue to free * * Releases all ressources assotiated to the queue. */ void queue_free (Queue* queue) { if (queue->schedule_idle) { g_warning (G_STRLOC ": FIXME: cancel scheduling thread"); } while (queue->threads) { Worker* worker = queue->threads->data; worker_shutdown (worker); queue->threads = g_list_delete_link (queue->threads, queue->threads); } g_list_free (queue->idle_threads); if (queue->jobs->length) { g_warning (G_STRLOC ": FIXME: cancel unfinished jobs first"); } g_queue_free (queue->jobs); g_slice_free (Queue, queue); }
static void do_shutdown(void) { int rc = 0; LogEvent(COMPONENT_MAIN, "NFS EXIT: stopping NFS service"); LogEvent(COMPONENT_MAIN, "Stopping delayed executor."); delayed_shutdown(); LogEvent(COMPONENT_MAIN, "Delayed executor stopped."); LogEvent(COMPONENT_MAIN, "Stopping state asynchronous request thread"); rc = state_async_shutdown(); if (rc != 0) { LogMajor(COMPONENT_THREAD, "Error shutting down state asynchronous request system: %d", rc); } else { LogEvent(COMPONENT_THREAD, "State asynchronous request system shut down."); } LogEvent(COMPONENT_MAIN, "Stopping request listener threads."); nfs_rpc_dispatch_stop(); LogEvent(COMPONENT_MAIN, "Stopping request decoder threads"); rc = fridgethr_sync_command(req_fridge, fridgethr_comm_stop, 120); if (rc == ETIMEDOUT) { LogMajor(COMPONENT_THREAD, "Shutdown timed out, cancelling threads!"); fridgethr_cancel(req_fridge); } else if (rc != 0) { LogMajor(COMPONENT_THREAD, "Failed to shut down the request thread fridge: %d!", rc); } else { LogEvent(COMPONENT_THREAD, "Request threads shut down."); } LogEvent(COMPONENT_MAIN, "Stopping worker threads"); rc = worker_shutdown(); if(rc != 0) LogMajor(COMPONENT_THREAD, "Unable to shut down worker threads: %d", rc); else LogEvent(COMPONENT_THREAD, "Worker threads successfully shut down."); rc = general_fridge_shutdown(); if (rc != 0) { LogMajor(COMPONENT_THREAD, "Error shutting down general fridge: %d", rc); } else { LogEvent(COMPONENT_THREAD, "General fridge shut down."); } rc = reaper_shutdown(); if (rc != 0) { LogMajor(COMPONENT_THREAD, "Error shutting down reaper thread: %d", rc); } else { LogEvent(COMPONENT_THREAD, "Reaper thread shut down."); } LogEvent(COMPONENT_MAIN, "Stopping LRU thread."); rc = cache_inode_lru_pkgshutdown(); if (rc != 0) { LogMajor(COMPONENT_THREAD, "Error shutting down LRU thread: %d", rc); } else { LogEvent(COMPONENT_THREAD, "LRU thread system shut down."); } LogEvent(COMPONENT_MAIN, "Destroying the inode cache."); cache_inode_destroyer(); LogEvent(COMPONENT_MAIN, "Inode cache destroyed."); LogEvent(COMPONENT_MAIN, "Destroying the FSAL system."); destroy_fsals(); LogEvent(COMPONENT_MAIN, "FSAL system destroyed."); unlink(pidfile_path); }