From c17f6f96e2da0265a5d565a43cbca036f1571dfb Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Fri, 16 Dec 2011 16:21:01 +0100 Subject: Log native thread ID when a thread is created. If possible gettid() is used, otherwise pthread_self() is logged (which is not completely portable, but seems to work on most supported platforms). --- src/libstrongswan/threading/thread.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libstrongswan/threading/thread.c b/src/libstrongswan/threading/thread.c index d3da1e379..9092bf7b7 100644 --- a/src/libstrongswan/threading/thread.c +++ b/src/libstrongswan/threading/thread.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Tobias Brunner + * Copyright (C) 2009-2011 Tobias Brunner * Hochschule fuer Technik Rapperswil * * This program is free software; you can redistribute it and/or modify it @@ -17,6 +17,10 @@ #include #include #include +#ifdef HAVE_GETTID +#include +#include +#endif #include #include @@ -278,6 +282,17 @@ static void *thread_main(private_thread_t *this) sem_wait(&this->created); current_thread->set(current_thread, this); pthread_cleanup_push((thread_cleanup_t)thread_cleanup, this); + + /* TODO: this is not 100% portable as pthread_t is an opaque type (i.e. + * could be of any size, or even a struct) */ +#ifdef HAVE_GETTID + DBG2(DBG_LIB, "created thread %.2d [%u]", + this->id, syscall(SYS_gettid)); +#else + DBG2(DBG_LIB, "created thread %.2d [%lx]", + this->id, (u_long)this->thread_id); +#endif + res = this->main(this->arg); pthread_cleanup_pop(TRUE); -- cgit v1.2.3