13
0

add DEBUG_THREAD_SELF to allow use of DEBUG_TRACE with thread IDs on both normal pthreads platforms and PTW32

This commit is contained in:
Paul Davis 2014-12-10 09:32:25 -05:00
parent 2bbef1f32e
commit c06c15596b
2 changed files with 17 additions and 12 deletions

View File

@ -137,7 +137,7 @@ Butler::terminate_thread ()
{
if (have_thread) {
void* status;
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: ask butler to quit @ %2\n", pthread_self(), g_get_monotonic_time()));
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: ask butler to quit @ %2\n", DEBUG_THREAD_SELF, g_get_monotonic_time()));
queue_request (Request::Quit);
pthread_join (thread, &status);
}
@ -173,7 +173,7 @@ Butler::wait_for_requests ()
break;
}
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: butler awake at @ %2\n", pthread_self(), g_get_monotonic_time()));
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: butler awake at @ %2\n", DEBUG_THREAD_SELF, g_get_monotonic_time()));
if (pfd[0].revents & ~POLLIN) {
error << string_compose (_("Error on butler thread request pipe: fd=%1 err=%2"), pfd[0].fd, pfd[0].revents) << endmsg;
@ -223,10 +223,10 @@ Butler::thread_work ()
RouteList::iterator i;
while (true) {
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1 butler main loop, disk work outstanding ? %2 @ %3\n", pthread_self(), disk_work_outstanding, g_get_monotonic_time()));
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1 butler main loop, disk work outstanding ? %2 @ %3\n", DEBUG_THREAD_SELF, disk_work_outstanding, g_get_monotonic_time()));
if(!disk_work_outstanding) {
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1 butler waits for requests @ %2\n", pthread_self(), g_get_monotonic_time()));
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1 butler waits for requests @ %2\n", DEBUG_THREAD_SELF, g_get_monotonic_time()));
if (wait_for_requests ()) {
Request::Type req;
@ -239,17 +239,17 @@ Butler::thread_work ()
switch (req) {
case Request::Run:
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: butler asked to run @ %2\n", pthread_self(), g_get_monotonic_time()));
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: butler asked to run @ %2\n", DEBUG_THREAD_SELF, g_get_monotonic_time()));
should_run = true;
break;
case Request::Pause:
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: butler asked to pause @ %2\n", pthread_self(), g_get_monotonic_time()));
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: butler asked to pause @ %2\n", DEBUG_THREAD_SELF, g_get_monotonic_time()));
should_run = false;
break;
case Request::Quit:
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: butler asked to quit @ %2\n", pthread_self(), g_get_monotonic_time()));
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: butler asked to quit @ %2\n", DEBUG_THREAD_SELF, g_get_monotonic_time()));
return 0;
abort(); /*NOTREACHED*/
break;
@ -404,7 +404,7 @@ Butler::thread_work ()
goto restart;
}
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: butler signals pause @ %2\n", pthread_self(), g_get_monotonic_time()));
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: butler signals pause @ %2\n", DEBUG_THREAD_SELF, g_get_monotonic_time()));
paused.signal();
}
@ -437,7 +437,7 @@ Butler::queue_request (Request::Type r)
void
Butler::summon ()
{
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: summon butler to run @ %2\n", pthread_self(), g_get_monotonic_time()));
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: summon butler to run @ %2\n", DEBUG_THREAD_SELF, g_get_monotonic_time()));
queue_request (Request::Run);
}
@ -445,7 +445,7 @@ void
Butler::stop ()
{
Glib::Threads::Mutex::Lock lm (request_lock);
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: asking butler to stop @ %2\n", pthread_self(), g_get_monotonic_time()));
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: asking butler to stop @ %2\n", DEBUG_THREAD_SELF, g_get_monotonic_time()));
queue_request (Request::Pause);
paused.wait(request_lock);
}
@ -454,7 +454,7 @@ void
Butler::wait_until_finished ()
{
Glib::Threads::Mutex::Lock lm (request_lock);
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: waiting for butler to finish @ %2\n", pthread_self(), g_get_monotonic_time()));
DEBUG_TRACE (DEBUG::Butler, string_compose ("%1: waiting for butler to finish @ %2\n", DEBUG_THREAD_SELF, g_get_monotonic_time()));
queue_request (Request::Pause);
paused.wait(request_lock);
}

View File

@ -55,12 +55,17 @@ namespace PBD {
#define DEBUG_STR(id) __debug_str ## id
#define DEBUG_STR_APPEND(id,s) __debug_str ## id << s;
#define DEBUG_ENABLED(bits) ((bits) & PBD::debug_bits)
#define DEBUG_THREAD_SELF 0
#else
#define DEBUG_TRACE(bits,fmt,...) /*empty*/
#define DEBUG_STR(a) /* empty */
#define DEBUG_STR_APPEND(a,b) /* empty */
#define DEBUG_ENABLED(b) (0)
#ifdef PTW32_VERSION
#define DEBUG_THREAD_SELF pthread_self().p
#else
#define DEBUG_THREAD_SELF pthread_self()
#endif
#endif
#endif /* __libpbd_debug_h__ */