Commit 7361edd0 authored by Davis King's avatar Davis King

Changed the name of the mutex in the threaded_object and multithreaded_object

so that it won't cause any ambiguities when you derive a class from a
gui widget and a thread base class.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402518
parent 801f07ef
...@@ -14,7 +14,7 @@ namespace dlib ...@@ -14,7 +14,7 @@ namespace dlib
multithreaded_object:: multithreaded_object::
multithreaded_object ( multithreaded_object (
): ):
s(m), s(m_),
is_running_(false), is_running_(false),
should_stop_(false), should_stop_(false),
threads_started(0) threads_started(0)
...@@ -40,7 +40,7 @@ namespace dlib ...@@ -40,7 +40,7 @@ namespace dlib
clear ( clear (
) )
{ {
auto_mutex M(m); auto_mutex M(m_);
stop(); stop();
wait(); wait();
dead_threads.clear(); dead_threads.clear();
...@@ -54,7 +54,7 @@ namespace dlib ...@@ -54,7 +54,7 @@ namespace dlib
is_running ( is_running (
) const ) const
{ {
auto_mutex M(m); auto_mutex M(m_);
return is_running_; return is_running_;
} }
...@@ -64,7 +64,7 @@ namespace dlib ...@@ -64,7 +64,7 @@ namespace dlib
number_of_threads_registered ( number_of_threads_registered (
) const ) const
{ {
auto_mutex M(m); auto_mutex M(m_);
return thread_ids.size() + dead_threads.size(); return thread_ids.size() + dead_threads.size();
} }
...@@ -74,7 +74,7 @@ namespace dlib ...@@ -74,7 +74,7 @@ namespace dlib
number_of_threads_alive ( number_of_threads_alive (
) const ) const
{ {
auto_mutex M(m); auto_mutex M(m_);
return threads_started; return threads_started;
} }
...@@ -84,7 +84,7 @@ namespace dlib ...@@ -84,7 +84,7 @@ namespace dlib
wait ( wait (
) const ) const
{ {
auto_mutex M(m); auto_mutex M(m_);
DLIB_ASSERT(thread_ids.is_in_domain(get_thread_id()) == false, DLIB_ASSERT(thread_ids.is_in_domain(get_thread_id()) == false,
"\tvoid multithreaded_object::wait()" "\tvoid multithreaded_object::wait()"
...@@ -102,7 +102,7 @@ namespace dlib ...@@ -102,7 +102,7 @@ namespace dlib
start ( start (
) )
{ {
auto_mutex M(m); auto_mutex M(m_);
const unsigned long num_threads_registered = dead_threads.size() + thread_ids.size(); const unsigned long num_threads_registered = dead_threads.size() + thread_ids.size();
// start any dead threads // start any dead threads
for (unsigned long i = threads_started; i < num_threads_registered; ++i) for (unsigned long i = threads_started; i < num_threads_registered; ++i)
...@@ -126,7 +126,7 @@ namespace dlib ...@@ -126,7 +126,7 @@ namespace dlib
pause ( pause (
) )
{ {
auto_mutex M(m); auto_mutex M(m_);
is_running_ = false; is_running_ = false;
} }
...@@ -136,7 +136,7 @@ namespace dlib ...@@ -136,7 +136,7 @@ namespace dlib
stop ( stop (
) )
{ {
auto_mutex M(m); auto_mutex M(m_);
should_stop_ = true; should_stop_ = true;
is_running_ = false; is_running_ = false;
s.broadcast(); s.broadcast();
...@@ -148,7 +148,7 @@ namespace dlib ...@@ -148,7 +148,7 @@ namespace dlib
should_stop ( should_stop (
) const ) const
{ {
auto_mutex M(m); auto_mutex M(m_);
DLIB_ASSERT(thread_ids.is_in_domain(get_thread_id()), DLIB_ASSERT(thread_ids.is_in_domain(get_thread_id()),
"\tbool multithreaded_object::should_stop()" "\tbool multithreaded_object::should_stop()"
<< "\n\tYou can only call this function from one of the registered threads in this object" << "\n\tYou can only call this function from one of the registered threads in this object"
...@@ -173,7 +173,7 @@ namespace dlib ...@@ -173,7 +173,7 @@ namespace dlib
// if there is a dead_thread sitting around then pull it // if there is a dead_thread sitting around then pull it
// out and put it into mf // out and put it into mf
{ {
auto_mutex M(m); auto_mutex M(m_);
if (dead_threads.size() > 0) if (dead_threads.size() > 0)
{ {
dead_threads.dequeue(mf); dead_threads.dequeue(mf);
...@@ -189,7 +189,7 @@ namespace dlib ...@@ -189,7 +189,7 @@ namespace dlib
// call the registered thread function // call the registered thread function
mf(); mf();
auto_mutex M(m); auto_mutex M(m_);
if (thread_ids.is_in_domain(id)) if (thread_ids.is_in_domain(id))
{ {
mfp temp; mfp temp;
...@@ -202,7 +202,7 @@ namespace dlib ...@@ -202,7 +202,7 @@ namespace dlib
dead_threads.enqueue(mf); dead_threads.enqueue(mf);
} }
auto_mutex M(m); auto_mutex M(m_);
--threads_started; --threads_started;
// If this is the last thread to terminate then // If this is the last thread to terminate then
// signal that that is the case. // signal that that is the case.
...@@ -215,7 +215,7 @@ namespace dlib ...@@ -215,7 +215,7 @@ namespace dlib
} }
catch (...) catch (...)
{ {
auto_mutex M(m); auto_mutex M(m_);
if (thread_ids.is_in_domain(id)) if (thread_ids.is_in_domain(id))
{ {
mfp temp; mfp temp;
......
...@@ -44,8 +44,8 @@ namespace dlib ...@@ -44,8 +44,8 @@ namespace dlib
- dead_threads == a queue that contains all the member function pointers - dead_threads == a queue that contains all the member function pointers
for threads that are currently registered but not running for threads that are currently registered but not running
- m == the mutex used to protect all our variables - m_ == the mutex used to protect all our variables
- s == the signaler for m - s == the signaler for m_
!*/ !*/
public: public:
...@@ -93,7 +93,7 @@ namespace dlib ...@@ -93,7 +93,7 @@ namespace dlib
void (T::*thread)() void (T::*thread)()
) )
{ {
auto_mutex M(m); auto_mutex M(m_);
try try
{ {
mfp mf; mfp mf;
...@@ -118,7 +118,7 @@ namespace dlib ...@@ -118,7 +118,7 @@ namespace dlib
typedef member_function_pointer<>::kernel_1a_c mfp; typedef member_function_pointer<>::kernel_1a_c mfp;
rmutex m; rmutex m_;
rsignaler s; rsignaler s;
map<thread_id_type,mfp,memory_manager<char>::kernel_2a>::kernel_1a thread_ids; map<thread_id_type,mfp,memory_manager<char>::kernel_2a>::kernel_1a thread_ids;
queue<mfp,memory_manager<char>::kernel_2a>::kernel_1a dead_threads; queue<mfp,memory_manager<char>::kernel_2a>::kernel_1a dead_threads;
......
...@@ -14,7 +14,7 @@ namespace dlib ...@@ -14,7 +14,7 @@ namespace dlib
threaded_object:: threaded_object::
threaded_object ( threaded_object (
): ):
s(m), s(m_),
id1(0), id1(0),
is_running_(false), is_running_(false),
is_alive_(false), is_alive_(false),
...@@ -42,7 +42,7 @@ namespace dlib ...@@ -42,7 +42,7 @@ namespace dlib
is_running ( is_running (
) const ) const
{ {
auto_mutex M(m); auto_mutex M(m_);
DLIB_ASSERT(id1 != get_thread_id() || id_valid == false, DLIB_ASSERT(id1 != get_thread_id() || id_valid == false,
"\tbool threaded_object::is_running()" "\tbool threaded_object::is_running()"
...@@ -59,7 +59,7 @@ namespace dlib ...@@ -59,7 +59,7 @@ namespace dlib
is_alive ( is_alive (
) const ) const
{ {
auto_mutex M(m); auto_mutex M(m_);
DLIB_ASSERT(id1 != get_thread_id() || id_valid == false, DLIB_ASSERT(id1 != get_thread_id() || id_valid == false,
"\tbool threaded_object::is_alive()" "\tbool threaded_object::is_alive()"
...@@ -76,7 +76,7 @@ namespace dlib ...@@ -76,7 +76,7 @@ namespace dlib
wait ( wait (
) const ) const
{ {
auto_mutex M(m); auto_mutex M(m_);
DLIB_ASSERT(id1 != get_thread_id() || id_valid == false, DLIB_ASSERT(id1 != get_thread_id() || id_valid == false,
"\tvoid threaded_object::wait()" "\tvoid threaded_object::wait()"
...@@ -94,7 +94,7 @@ namespace dlib ...@@ -94,7 +94,7 @@ namespace dlib
start ( start (
) )
{ {
auto_mutex M(m); auto_mutex M(m_);
DLIB_ASSERT(id1 != get_thread_id() || id_valid == false, DLIB_ASSERT(id1 != get_thread_id() || id_valid == false,
"\tvoid threaded_object::start()" "\tvoid threaded_object::start()"
...@@ -122,7 +122,7 @@ namespace dlib ...@@ -122,7 +122,7 @@ namespace dlib
pause ( pause (
) )
{ {
auto_mutex M(m); auto_mutex M(m_);
DLIB_ASSERT(id1 != get_thread_id() || id_valid == false, DLIB_ASSERT(id1 != get_thread_id() || id_valid == false,
"\tvoid threaded_object::pause()" "\tvoid threaded_object::pause()"
...@@ -139,7 +139,7 @@ namespace dlib ...@@ -139,7 +139,7 @@ namespace dlib
stop ( stop (
) )
{ {
auto_mutex M(m); auto_mutex M(m_);
DLIB_ASSERT(id1 != get_thread_id() || id_valid == false, DLIB_ASSERT(id1 != get_thread_id() || id_valid == false,
"\tvoid threaded_object::stop()" "\tvoid threaded_object::stop()"
...@@ -158,7 +158,7 @@ namespace dlib ...@@ -158,7 +158,7 @@ namespace dlib
should_stop ( should_stop (
) const ) const
{ {
auto_mutex M(m); auto_mutex M(m_);
DLIB_ASSERT(is_alive_ && id1 == get_thread_id() && id_valid == true, DLIB_ASSERT(is_alive_ && id1 == get_thread_id() && id_valid == true,
"\tbool threaded_object::should_stop()" "\tbool threaded_object::should_stop()"
<< "\n\tYou can only call this function from the thread that executes threaded_object::thread" << "\n\tYou can only call this function from the thread that executes threaded_object::thread"
...@@ -181,7 +181,7 @@ namespace dlib ...@@ -181,7 +181,7 @@ namespace dlib
#endif #endif
thread(); thread();
auto_mutex M(m); auto_mutex M(m_);
#ifdef ENABLE_ASSERTS #ifdef ENABLE_ASSERTS
id_valid = false; id_valid = false;
......
...@@ -42,8 +42,8 @@ namespace dlib ...@@ -42,8 +42,8 @@ namespace dlib
- id_valid == false - id_valid == false
#endif #endif
- m == the mutex used to protect all our variables - m_ == the mutex used to protect all our variables
- s == the signaler for m - s == the signaler for m_
!*/ !*/
public: public:
...@@ -85,7 +85,7 @@ namespace dlib ...@@ -85,7 +85,7 @@ namespace dlib
virtual void thread ( virtual void thread (
) = 0; ) = 0;
mutex m; mutex m_;
signaler s; signaler s;
thread_id_type id1; thread_id_type id1;
bool is_running_; bool is_running_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment