ARG_ENABL_SET([coverage], [enable lcov coverage report generation.])
ARG_ENABL_SET([leak-detective], [enable malloc hooks to find memory leaks.])
ARG_ENABL_SET([lock-profiler], [enable lock/mutex profiling code.])
+ARG_ENABL_SET([log-thread-ids], [use thread ID, if available, instead of an incremented value starting from 1, to identify threads.])
ARG_ENABL_SET([monolithic], [build monolithic version of libstrongswan that includes all enabled plugins. Similarly, the plugins of charon are assembled in libcharon.])
# ===================================
if test x$capabilities = xlibcap -o x$capabilities = xnative; then
AC_DEFINE([CAPABILITIES], [], [capability dropping support])
fi
+if test x$log_thread_ids = xtrue; then
+ AC_DEFINE([USE_THREAD_IDS], [], [use thread ID for thread identification, if available])
+fi
if test x$monolithic = xtrue; then
AC_DEFINE([MONOLITHIC], [], [monolithic build embedding plugins])
fi
thread_t public;
/**
- * Human-readable ID of this thread.
+ * Identificator of this thread (human-readable/thread ID).
*/
u_int id;
free(this);
}
+/**
+ * Determine the ID of the current thread
+ */
+static u_int get_thread_id()
+{
+ u_int id;
+
+#if defined(USE_THREAD_IDS) && defined(HAVE_GETTID)
+ id = gettid();
+#else
+ id_mutex->lock(id_mutex);
+ id = next_id++;
+ id_mutex->unlock(id_mutex);
+#endif
+ return id;
+}
+
METHOD(thread_t, cancel, void,
private_thread_t *this)
{
{
void *res;
+ this->id = get_thread_id();
+
current_thread->set(current_thread, this);
pthread_cleanup_push((thread_cleanup_t)thread_cleanup, this);
this->main = main;
this->arg = arg;
- id_mutex->lock(id_mutex);
- this->id = next_id++;
- id_mutex->unlock(id_mutex);
if (pthread_create(&this->thread_id, NULL, (void*)thread_main, this) != 0)
{
if (!this)
{
this = thread_create_internal();
-
- id_mutex->lock(id_mutex);
- this->id = next_id++;
- id_mutex->unlock(id_mutex);
-
+ this->id = get_thread_id();
current_thread->set(current_thread, (void*)this);
}
return &this->public;
dummy1 = thread_value_create(NULL);
- next_id = 1;
- main_thread->id = 0;
+ next_id = 0;
main_thread->thread_id = pthread_self();
current_thread = thread_value_create(NULL);
current_thread->set(current_thread, (void*)main_thread);
id_mutex = mutex_create(MUTEX_TYPE_DEFAULT);
+ main_thread->id = get_thread_id();
#ifndef HAVE_PTHREAD_CANCEL
{ /* install a signal handler for our custom SIG_CANCEL */
thread_t *thread_current();
/**
- * Get the human-readable ID of the current thread.
+ * Get the ID of the current thread.
*
- * The IDs are assigned incrementally starting from 1.
+ * Depending on the build configuration thread IDs are either assigned
+ * incrementally starting from 1, or equal the value returned by an appropriate
+ * syscall (like gettid() or GetCurrentThreadId()), if available.
*
- * @return human-readable ID
+ * @return ID of the current thread
*/
u_int thread_current_id();
*/
u_int thread_current_id()
{
+#ifdef USE_THREAD_IDS
+ return get_current_thread()->id;
+#else
return get_current_thread()->tid;
+#endif
}
/**