libcsdbg  1.28
C++ exception (and generic) stack trace debug library
thread * csdbg::process::current_thread ( )
virtual

Get the currently executing thread.

Returns
the csdbg::thread object that tracks the actual current thread
Exceptions
std::bad_alloc
Note
When an actual thread is created the m_threads chain is populated with an entry for the equivalent csdbg::thread object when the thread executes its first instrumented function

Definition at line 339 of file process.cpp.

References csdbg::thread::is_current(), likely, csdbg::util::lock(), m_threads, unlikely, and csdbg::util::unlock().

Referenced by csdbg::__cyg_profile_func_enter(), csdbg::__cyg_profile_func_exit(), csdbg::util::header(), csdbg::tracer::trace(), and csdbg::tracer::unwind().

340 {
341  util::lock();
342  for (u32 i = 0, sz = m_threads->size(); likely(i < sz); i++) {
343  thread *thr = m_threads->at(i);
344 
345  if ( unlikely(thr->is_current()) ) {
346  util::unlock();
347  return thr;
348  }
349  }
350 
351  thread *retval = NULL;
352  try {
353  retval = new thread;
354  m_threads->add(retval);
355  util::unlock();
356  return retval;
357  }
358 
359  catch (...) {
360  delete retval;
361  util::unlock();
362  throw;
363  }
364 }
chain< thread > * m_threads
Instrumented thread list.
Definition: process.hpp:37
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
Definition: config.hpp:344
static void lock()
Lock the global access mutex.
Definition: util.cpp:397
static void unlock()
Unlock the global access mutex.
Definition: util.cpp:406
unsigned int u32
32-bit unsigned integer
Definition: config.hpp:102
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
Definition: config.hpp:349

+ Here is the call graph for this function:

+ Here is the caller graph for this function: