summaryrefslogtreecommitdiffstats
path: root/ml/dlib/dlib/threads/auto_mutex_extension_abstract.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:19:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:20:02 +0000
commit58daab21cd043e1dc37024a7f99b396788372918 (patch)
tree96771e43bb69f7c1c2b0b4f7374cb74d7866d0cb /ml/dlib/dlib/threads/auto_mutex_extension_abstract.h
parentReleasing debian version 1.43.2-1. (diff)
downloadnetdata-58daab21cd043e1dc37024a7f99b396788372918.tar.xz
netdata-58daab21cd043e1dc37024a7f99b396788372918.zip
Merging upstream version 1.44.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ml/dlib/dlib/threads/auto_mutex_extension_abstract.h')
-rw-r--r--ml/dlib/dlib/threads/auto_mutex_extension_abstract.h185
1 files changed, 185 insertions, 0 deletions
diff --git a/ml/dlib/dlib/threads/auto_mutex_extension_abstract.h b/ml/dlib/dlib/threads/auto_mutex_extension_abstract.h
new file mode 100644
index 000000000..1990c834e
--- /dev/null
+++ b/ml/dlib/dlib/threads/auto_mutex_extension_abstract.h
@@ -0,0 +1,185 @@
+// Copyright (C) 2005 Davis E. King (davis@dlib.net)
+// License: Boost Software License See LICENSE.txt for the full license.
+#undef DLIB_AUTO_MUTEX_EXTENSIOn_ABSTRACT_
+#ifdef DLIB_AUTO_MUTEX_EXTENSIOn_ABSTRACT_
+
+#include "threads_kernel_abstract.h"
+#include "rmutex_extension_abstract.h"
+#include "read_write_mutex_extension_abstract.h"
+
+namespace dlib
+{
+
+// ----------------------------------------------------------------------------------------
+
+ class auto_mutex
+ {
+ /*!
+ INITIAL VALUE
+ The mutex given in the constructor is locked and associated with this
+ object.
+
+ WHAT THIS OBJECT REPRESENTS
+ This object represents a mechanism for automatically locking and unlocking
+ a mutex object.
+ !*/
+ public:
+
+ explicit auto_mutex (
+ const mutex& m
+ );
+ /*!
+ ensures
+ - #*this is properly initialized
+ - m will be locked
+ !*/
+
+ explicit auto_mutex (
+ const rmutex& m
+ );
+ /*!
+ ensures
+ - #*this is properly initialized
+ - m will be locked
+ !*/
+
+ explicit auto_mutex (
+ const read_write_mutex& m
+ );
+ /*!
+ ensures
+ - #*this is properly initialized
+ - 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 (
+ );
+ /*!
+ ensures
+ - all resources allocated by *this have been freed
+ - calls unlock()
+ !*/
+
+ private:
+ // restricted functions
+ auto_mutex(auto_mutex&); // copy constructor
+ auto_mutex& operator=(auto_mutex&); // assignment operator
+ };
+
+// ----------------------------------------------------------------------------------------
+
+ class auto_mutex_readonly
+ {
+ /*!
+ INITIAL VALUE
+ The mutex given in the constructor is locked using a read-only lock and
+ associated with this object.
+
+ WHAT THIS OBJECT REPRESENTS
+ This object represents a mechanism for automatically locking and unlocking
+ a read_write_mutex object. In particular, a readonly lock is used.
+ !*/
+ public:
+
+ explicit auto_mutex_readonly (
+ const read_write_mutex& m
+ );
+ /*!
+ ensures
+ - #*this is properly initialized
+ - a readonly lock will be obtained on m using m.lock_readonly()
+ - #has_read_lock() == true
+ !*/
+
+ ~auto_mutex_readonly (
+ );
+ /*!
+ ensures
+ - all resources allocated by *this have been freed
+ - the mutex associated with *this has been unlocked
+ !*/
+
+ bool has_read_lock (
+ );
+ /*!
+ ensures
+ - returns true if this object has called read_write_mutex::lock_readonly()
+ on its associated mutex and has yet to release that lock.
+ !*/
+
+ bool has_write_lock (
+ );
+ /*!
+ ensures
+ - returns true if this object has called read_write_mutex::lock() on its
+ associated mutex and has yet to release that lock.
+ !*/
+
+ void lock_readonly (
+ );
+ /*!
+ ensures
+ - This function converts the lock on the associated mutex into a readonly lock.
+ Specifically:
+ if (!has_read_lock()) then
+ - if (has_write_lock()) then
+ - unlocks the associated mutex and then relocks it by calling
+ read_write_mutex::lock_readonly()
+ - else
+ - locks the associated mutex by calling read_write_mutex::lock_readonly()
+ - #has_read_lock() == true
+ - Note that the lock switch is not atomic. This means that whatever
+ resource is protected by the mutex might have been modified during the
+ call to lock_readonly().
+ !*/
+
+ void lock_write (
+ );
+ /*!
+ ensures
+ - This function converts the lock on the associated mutex into a write lock.
+ Specifically:
+ if (!has_write_lock()) then
+ - if (has_read_lock()) then
+ - unlocks the associated mutex and then relocks it by calling
+ read_write_mutex::lock()
+ - else
+ - locks the associated mutex by calling read_write_mutex::lock()
+ - #has_write_lock() == true
+ - Note that the lock switch is not atomic. This means that whatever
+ resource is protected by the mutex might have been modified during the
+ call to lock_write().
+ !*/
+
+ void unlock (
+ );
+ /*!
+ ensures
+ - if (has_read_lock() || has_write_lock()) then
+ - unlocks the associated mutex. This is useful if you want to unlock a
+ mutex before the auto_mutex_readonly destructor executes.
+ - #has_read_lock() == false
+ - #has_write_lock() == false
+ !*/
+
+ private:
+ // restricted functions
+ auto_mutex_readonly(auto_mutex_readonly&); // copy constructor
+ auto_mutex_readonly& operator=(auto_mutex_readonly&); // assignment operator
+ };
+
+// ----------------------------------------------------------------------------------------
+
+}
+
+#endif // DLIB_AUTO_MUTEX_EXTENSIOn_ABSTRACT_
+