From ce6d6511c7fb7f82d2890de578ef9bb28e410281 Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Thu, 2 Aug 2012 14:42:12 -0700 Subject: [PATCH] Set thread name on Mac to make gdb thread info more useful. --- src/rt/rust_sched_driver.cpp | 12 ++++++++++++ src/rt/rust_sched_loop.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/rt/rust_sched_driver.cpp b/src/rt/rust_sched_driver.cpp index 0da9d580dc3b..4876c2796446 100644 --- a/src/rt/rust_sched_driver.cpp +++ b/src/rt/rust_sched_driver.cpp @@ -22,6 +22,18 @@ void rust_sched_driver::start_main_loop() { assert(sched_loop != NULL); +#ifdef __APPLE__ + { + char buf[64]; + snprintf(buf, sizeof(buf), "scheduler loop %d", sched_loop->get_id()); + // pthread_setname_np seems to have a different signature and + // different behavior on different platforms. Thus, this is + // only for Mac at the moment. There are equivalent versions + // for Linux that we can add if needed. + pthread_setname_np(buf); + } +#endif + rust_sched_loop_state state = sched_loop_state_keep_going; while (state != sched_loop_state_exit) { DLOG(sched_loop, dom, "pumping scheduler"); diff --git a/src/rt/rust_sched_loop.h b/src/rt/rust_sched_loop.h index eb70fe07b7e3..b664f2f3f7bc 100644 --- a/src/rt/rust_sched_loop.h +++ b/src/rt/rust_sched_loop.h @@ -130,6 +130,8 @@ public: // Called by tasks when they need a stack on which to run C code stk_seg *borrow_c_stack(); void return_c_stack(stk_seg *stack); + + int get_id() { return this->id; } }; inline rust_log &