Skip to content

Commit

Permalink
Add pthread naming to WorkerThread (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
dskyle committed Sep 26, 2018
1 parent bfe05cc commit eebd9a0
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions include/madara/threads/WorkerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include "madara/utility/java/Acquire_VM.h"
#endif

#ifndef _WIN32
#include <pthread.h>
#endif


#include <iostream>
#include <algorithm>
Expand Down Expand Up @@ -109,18 +113,29 @@ WorkerThread::operator= (const WorkerThread & input)
}
}*/

void
WorkerThread::run (void)
{
#ifndef _WIN32
#else
//result = 0;
//_beginthreadex(NULL, 0, worker_thread_windows_glue, (void*)this, 0, 0);
// Call pthread_setname_np if it exists ...
template<typename... Args>
auto try_pthread_setname_np(Args&&... args) ->
decltype(pthread_setname_np(std::forward<Args>(args)...))
{
return pthread_setname_np(std::forward<Args>(args)...);
}

// Otherwise, do nothing
void try_pthread_setname_np(...) {}
#endif

void
WorkerThread::run (void)
{
try {
me_ = std::thread(&WorkerThread::svc, this);

#ifndef _WIN32
try_pthread_setname_np(me_.native_handle(), name_.substr(0, 15).c_str());
#endif

std::ostringstream os;
os << std::this_thread::get_id() << " spawned " << me_.get_id() << std::endl;

Expand Down

0 comments on commit eebd9a0

Please sign in to comment.