transfused: create threads already detached

Signed-off-by: David Sheets <david.sheets@docker.com>
This commit is contained in:
David Sheets 2016-03-20 11:20:00 +00:00
parent 72157cf5ee
commit c0b857c7bb
3 changed files with 12 additions and 21 deletions

View File

@ -53,6 +53,8 @@ char * usage =
int debug = 0;
pthread_attr_t detached;
typedef struct {
char * descr;
long connection;
@ -343,14 +345,10 @@ void start_reader(connection_t * connection, int fuse) {
copy_state->tag = "read";
copy_state->from = read_fd;
copy_state->to = fuse;
if ((errno = pthread_create(&child, NULL,
if ((errno = pthread_create(&child, &detached,
copy_clean_from_thread, copy_state)))
die(1, "", "couldn't create read copy thread for connection %ld: ",
connection->id);
if ((errno = pthread_detach(child)))
die(1, "", "couldn't detach read copy thread for connection %ld: ",
connection->id);
}
void start_writer(connection_t * connection, int fuse) {
@ -374,14 +372,10 @@ void start_writer(connection_t * connection, int fuse) {
copy_state->tag = "write";
copy_state->from = fuse;
copy_state->to = write_fd;
if ((errno = pthread_create(&child, NULL,
if ((errno = pthread_create(&child, &detached,
copy_clean_to_thread, copy_state)))
die(1, "", "Couldn't create write copy thread for connection %ld: ",
connection->id);
if ((errno = pthread_detach(child)))
die(1, "", "couldn't detach write copy thread for connection %ld: ",
connection->id);
}
void * mount_connection(connection_t * conn) {
@ -783,15 +777,11 @@ void process_events(char * events_path, int events, parameters * params) {
die(1, NULL, "Unknown connection type '%c'", buf[0]);
}
if ((errno = pthread_create(&child, NULL,
if ((errno = pthread_create(&child, &detached,
connection_handler_thread, conn)))
die(1, "", "Couldn't create thread for %s connection '%ld': ",
conn->type_descr, conn_id);
if ((errno = pthread_detach(child)))
die(1, "", "Couldn't detach thread for %s connection '%ld': ",
conn->type_descr, conn_id);
if (debug) log_time(conn, "thread spawned\n");
}
}
@ -812,6 +802,10 @@ int main(int argc, char * argv[]) {
parse_parameters(argc, argv, &params);
setup_debug();
if ((errno = pthread_attr_setdetachstate(&detached,
PTHREAD_CREATE_DETACHED)))
die(1, "Couldn't set pthread detach state", "");
if (params.pidfile != NULL) write_pidfile(params.pidfile);
if (params.logfile != NULL) {

View File

@ -18,6 +18,8 @@ typedef struct {
char * type_descr;
} connection_t;
pthread_attr_t detached;
void * must_malloc(char *const descr, size_t size);
void lock(char *const descr, pthread_mutex_t * mutex);

View File

@ -128,14 +128,9 @@ void thread_log_time(connection_t * conn, const char * fmt, ...) {
// far from ideal but fine for now as we anticipate thread-sensitive
// log demand to be low.
if ((errno = pthread_create(&logger, NULL, log_time_thread, log_state)))
if ((errno = pthread_create(&logger, &detached, log_time_thread, log_state)))
die(1, "", "Couldn't create log thread for %s connection '%ld': ",
conn->type_descr, conn->id);
if ((errno = pthread_detach(logger)))
die(1, "", "Couldn't detach thread for %s connection '%ld': ",
conn->type_descr, conn->id);
}
void log_continue_locked(connection_t * connection, const char * fmt, ...) {