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
multithreaded_object::
multithreaded_object (
):
s(m),
s(m_),
is_running_(false),
should_stop_(false),
threads_started(0)
......@@ -40,7 +40,7 @@ namespace dlib
clear (
)
{
auto_mutex M(m);
auto_mutex M(m_);
stop();
wait();
dead_threads.clear();
......@@ -54,7 +54,7 @@ namespace dlib
is_running (
) const
{
auto_mutex M(m);
auto_mutex M(m_);
return is_running_;
}
......@@ -64,7 +64,7 @@ namespace dlib
number_of_threads_registered (
) const
{
auto_mutex M(m);
auto_mutex M(m_);
return thread_ids.size() + dead_threads.size();
}
......@@ -74,7 +74,7 @@ namespace dlib
number_of_threads_alive (
) const
{
auto_mutex M(m);
auto_mutex M(m_);
return threads_started;
}
......@@ -84,7 +84,7 @@ namespace dlib
wait (
) const
{
auto_mutex M(m);
auto_mutex M(m_);
DLIB_ASSERT(thread_ids.is_in_domain(get_thread_id()) == false,
"\tvoid multithreaded_object::wait()"
......@@ -102,7 +102,7 @@ namespace dlib
start (
)
{
auto_mutex M(m);
auto_mutex M(m_);
const unsigned long num_threads_registered = dead_threads.size() + thread_ids.size();
// start any dead threads
for (unsigned long i = threads_started; i < num_threads_registered; ++i)
......@@ -126,7 +126,7 @@ namespace dlib
pause (
)
{
auto_mutex M(m);
auto_mutex M(m_);
is_running_ = false;
}
......@@ -136,7 +136,7 @@ namespace dlib
stop (
)
{
auto_mutex M(m);
auto_mutex M(m_);
should_stop_ = true;
is_running_ = false;
s.broadcast();
......@@ -148,7 +148,7 @@ namespace dlib
should_stop (
) const
{
auto_mutex M(m);
auto_mutex M(m_);
DLIB_ASSERT(thread_ids.is_in_domain(get_thread_id()),
"\tbool multithreaded_object::should_stop()"
<< "\n\tYou can only call this function from one of the registered threads in this object"
......@@ -173,7 +173,7 @@ namespace dlib
// if there is a dead_thread sitting around then pull it
// out and put it into mf
{
auto_mutex M(m);
auto_mutex M(m_);
if (dead_threads.size() > 0)
{
dead_threads.dequeue(mf);
......@@ -189,7 +189,7 @@ namespace dlib
// call the registered thread function
mf();
auto_mutex M(m);
auto_mutex M(m_);
if (thread_ids.is_in_domain(id))
{
mfp temp;
......@@ -202,7 +202,7 @@ namespace dlib
dead_threads.enqueue(mf);
}
auto_mutex M(m);
auto_mutex M(m_);
--threads_started;
// If this is the last thread to terminate then
// signal that that is the case.
......@@ -215,7 +215,7 @@ namespace dlib
}
catch (...)
{
auto_mutex M(m);
auto_mutex M(m_);
if (thread_ids.is_in_domain(id))
{
mfp temp;
......
......@@ -44,8 +44,8 @@ namespace dlib
- dead_threads == a queue that contains all the member function pointers
for threads that are currently registered but not running
- m == the mutex used to protect all our variables
- s == the signaler for m
- m_ == the mutex used to protect all our variables
- s == the signaler for m_
!*/
public:
......@@ -93,7 +93,7 @@ namespace dlib
void (T::*thread)()
)
{
auto_mutex M(m);
auto_mutex M(m_);
try
{
mfp mf;
......@@ -118,7 +118,7 @@ namespace dlib
typedef member_function_pointer<>::kernel_1a_c mfp;
rmutex m;
rmutex m_;
rsignaler s;
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;
......
......@@ -14,7 +14,7 @@ namespace dlib
threaded_object::
threaded_object (
):
s(m),
s(m_),
id1(0),
is_running_(false),
is_alive_(false),
......@@ -42,7 +42,7 @@ namespace dlib
is_running (
) const
{
auto_mutex M(m);
auto_mutex M(m_);
DLIB_ASSERT(id1 != get_thread_id() || id_valid == false,
"\tbool threaded_object::is_running()"
......@@ -59,7 +59,7 @@ namespace dlib
is_alive (
) const
{
auto_mutex M(m);
auto_mutex M(m_);
DLIB_ASSERT(id1 != get_thread_id() || id_valid == false,
"\tbool threaded_object::is_alive()"
......@@ -76,7 +76,7 @@ namespace dlib
wait (
) const
{
auto_mutex M(m);
auto_mutex M(m_);
DLIB_ASSERT(id1 != get_thread_id() || id_valid == false,
"\tvoid threaded_object::wait()"
......@@ -94,7 +94,7 @@ namespace dlib
start (
)
{
auto_mutex M(m);
auto_mutex M(m_);
DLIB_ASSERT(id1 != get_thread_id() || id_valid == false,
"\tvoid threaded_object::start()"
......@@ -122,7 +122,7 @@ namespace dlib
pause (
)
{
auto_mutex M(m);
auto_mutex M(m_);
DLIB_ASSERT(id1 != get_thread_id() || id_valid == false,
"\tvoid threaded_object::pause()"
......@@ -139,7 +139,7 @@ namespace dlib
stop (
)
{
auto_mutex M(m);
auto_mutex M(m_);
DLIB_ASSERT(id1 != get_thread_id() || id_valid == false,
"\tvoid threaded_object::stop()"
......@@ -158,7 +158,7 @@ namespace dlib
should_stop (
) const
{
auto_mutex M(m);
auto_mutex M(m_);
DLIB_ASSERT(is_alive_ && id1 == get_thread_id() && id_valid == true,
"\tbool threaded_object::should_stop()"
<< "\n\tYou can only call this function from the thread that executes threaded_object::thread"
......@@ -181,7 +181,7 @@ namespace dlib
#endif
thread();
auto_mutex M(m);
auto_mutex M(m_);
#ifdef ENABLE_ASSERTS
id_valid = false;
......
......@@ -42,8 +42,8 @@ namespace dlib
- id_valid == false
#endif
- m == the mutex used to protect all our variables
- s == the signaler for m
- m_ == the mutex used to protect all our variables
- s == the signaler for m_
!*/
public:
......@@ -85,7 +85,7 @@ namespace dlib
virtual void thread (
) = 0;
mutex m;
mutex m_;
signaler s;
thread_id_type id1;
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