Add a thread utility class and thread list
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 26 Nov 2018 20:09:10 +0000 (15:09 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 10 Dec 2018 20:24:49 +0000 (15:24 -0500)
commit8b182865dd36c1758bb46f34e0cdb1ad802b5371
tree2f4e3b856f4ba488ceb3908889b171b1d27b5d8f
parentf859080e7a2b2721e88055b28416c62a2a6313d4
Add a thread utility class and thread list

As part of the re-work of the order of the teardown of the sessiond's
threads, this utility is introduced to track running threads and unify
the mechanisms through which they are launched and shutdown.

This makes it easier to reason about (and track) the order in which
threads are launched and shutdown.

The lttng_thread class allows threads to be implemented by
defining the following methods:
  - An entry point ("main" function),
  - A shutdown method,
  - A clean-up method.

Since the sessiond's threads use a variety of techniques to initiate
their teardown (through an explicit command in a queue, using the
global "quit" pipe, or through a futex + variable), it is more
practical to let them define a shutdown method which notifies the
thread to shutdown than to impose a standard mechanism.

A clean-up method is meant to work around situations where the
ownership of data structures shared between the main thread and
a worker thread can be ambiguous (mostly in error paths).
The clean-up method is invoked when the last reference to a thread
is released.

While some threads need to be shutdown in a particular order, most of
them can be shutdown in bulk. The lttng_thread utility maintains a
global thread list which allows for a generic path through which
threads can be shutdown using the lttng_thread_list_shutdown_orphans()
function.

The lttng_thread_shutdown() method, in return, allows the user
(most likely the main thread) to explicitly teardown threads which
must be shutdown in a specific order before issuing the bulk
lttng_thread_list_shutdown_orphans() call.

Note that lttng_thread objects are reference counted. The thread
list holds a reference to each thread until it is shutdown. Hence,
it is safe to hold a reference to a thread, invoke its shutdown
method, and then invoke lttng_thread_list_shutdown_orphans().

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/Makefile.am
src/bin/lttng-sessiond/thread.c [new file with mode: 0644]
src/bin/lttng-sessiond/thread.h [new file with mode: 0644]
This page took 0.025419 seconds and 4 git commands to generate.