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>
Tue, 4 Dec 2018 23:12:25 +0000 (18:12 -0500)
commitb878f05a6e62779ddf2364d5bb51821cb6d6d572
tree5eb330b26aeab33c3210833a1d7c6534b0333646
parent124473a3e6a82e10bbb23727fdff6e1f0c0415cb
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.024869 seconds and 4 git commands to generate.