Commit 1a6554bc authored by Davis King's avatar Davis King

merged

parents 68e88433 d5ca4a8b
...@@ -63,15 +63,29 @@ namespace dlib ...@@ -63,15 +63,29 @@ namespace dlib
rw->lock(); rw->lock();
} }
~auto_mutex ( void unlock()
)
{ {
if (m != 0) if (m != 0)
{
m->unlock(); m->unlock();
m = 0;
}
else if (r != 0) else if (r != 0)
{
r->unlock(); r->unlock();
else r = 0;
}
else if (rw != 0)
{
rw->unlock(); rw->unlock();
rw = 0;
}
}
~auto_mutex (
)
{
unlock();
} }
private: private:
......
...@@ -52,12 +52,21 @@ namespace dlib ...@@ -52,12 +52,21 @@ namespace dlib
- m will be locked via m.lock() (i.e. a write lock will be obtained) - m will be locked via m.lock() (i.e. a write lock will be obtained)
!*/ !*/
void unlock(
);
/*!
ensures
- if (unlock() has not already been called) then
- The mutex associated with *this has been unlocked. This is useful if
you want to unlock a mutex before the auto_mutex destructor executes.
!*/
~auto_mutex ( ~auto_mutex (
); );
/*! /*!
ensures ensures
- all resources allocated by *this have been freed - all resources allocated by *this have been freed
- the mutex associated with *this has been unlocked - calls unlock()
!*/ !*/
private: private:
......
...@@ -275,7 +275,7 @@ namespace dlib ...@@ -275,7 +275,7 @@ namespace dlib
// aren't any other worker threads free so just perform the task right // aren't any other worker threads free so just perform the task right
// here // here
m.unlock(); M.unlock();
bfp(); bfp();
// return a task id that is both non-zero and also one // return a task id that is both non-zero and also one
......
...@@ -182,7 +182,7 @@ namespace dlib ...@@ -182,7 +182,7 @@ namespace dlib
// aren't any other worker threads free so just perform the task right // aren't any other worker threads free so just perform the task right
// here // here
m.unlock(); M.unlock();
(obj.*funct)(); (obj.*funct)();
// return a task id that is both non-zero and also one // return a task id that is both non-zero and also one
...@@ -225,7 +225,7 @@ namespace dlib ...@@ -225,7 +225,7 @@ namespace dlib
// aren't any other worker threads free so just perform the task right // aren't any other worker threads free so just perform the task right
// here // here
m.unlock(); M.unlock();
(obj.*funct)(arg1); (obj.*funct)(arg1);
// return a task id that is both non-zero and also one // return a task id that is both non-zero and also one
...@@ -270,7 +270,7 @@ namespace dlib ...@@ -270,7 +270,7 @@ namespace dlib
// aren't any other worker threads free so just perform the task right // aren't any other worker threads free so just perform the task right
// here // here
m.unlock(); M.unlock();
(obj.*funct)(arg1, arg2); (obj.*funct)(arg1, arg2);
// return a task id that is both non-zero and also one // return a task id that is both non-zero and also one
......
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