Mercurial > octave
annotate liboctave/util/oct-mutex.h @ 31529:918e09edc6ed stable
Export typeinfo of base_mutex and autolock classes.
* liboctave/util/oct-mutex.h (base_mutex, autolock): Add API attribute to class
definitions.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Thu, 24 Nov 2022 14:11:47 +0100 |
parents | 796f54d4ddbf |
children | e88a07dec498 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29565
diff
changeset
|
3 // Copyright (C) 2008-2022 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
7934 | 25 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
26 #if ! defined (octave_oct_mutex_h) |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
27 #define octave_oct_mutex_h 1 |
7934 | 28 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
29 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
20791
diff
changeset
|
30 |
29565
7733ca1db419
use shared_ptr to manage memory for mutex object
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
31 #include <memory> |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13281
diff
changeset
|
32 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
33 namespace octave |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
34 { |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
35 class mutex; |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
36 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
37 class |
31529
918e09edc6ed
Export typeinfo of base_mutex and autolock classes.
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
38 OCTAVE_API |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
39 base_mutex |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
40 { |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
41 public: |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
42 friend class mutex; |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
43 |
29565
7733ca1db419
use shared_ptr to manage memory for mutex object
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
44 base_mutex (void) = default; |
13281
834f904a3dcb
Add support for full asynchronous graphics toolkit running in a separate
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11523
diff
changeset
|
45 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
46 virtual ~base_mutex (void) = default; |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
47 |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
48 virtual void lock (void); |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
49 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
50 virtual void unlock (void); |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
51 |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
52 virtual bool try_lock (void); |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
53 }; |
7934 | 54 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
55 class |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
56 OCTAVE_API |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
57 mutex |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
58 { |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
59 public: |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
60 mutex (void); |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
61 |
29565
7733ca1db419
use shared_ptr to manage memory for mutex object
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
62 mutex (const mutex& m) = default; |
7934 | 63 |
29565
7733ca1db419
use shared_ptr to manage memory for mutex object
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
64 ~mutex (void) = default; |
7934 | 65 |
29565
7733ca1db419
use shared_ptr to manage memory for mutex object
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
66 mutex& operator = (const mutex& m) = default; |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
67 |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
68 void lock (void) |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
69 { |
27379
3db033e86376
use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
70 m_rep->lock (); |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
71 } |
7934 | 72 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
73 void unlock (void) |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
74 { |
27379
3db033e86376
use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
75 m_rep->unlock (); |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
76 } |
7934 | 77 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
78 bool try_lock (void) |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
79 { |
27379
3db033e86376
use m_ prefix for data members in most liboctave/util classes
John W. Eaton <jwe@octave.org>
parents:
26377
diff
changeset
|
80 return m_rep->try_lock (); |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
81 } |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
82 |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
83 protected: |
29565
7733ca1db419
use shared_ptr to manage memory for mutex object
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
84 std::shared_ptr<base_mutex> m_rep; |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
85 }; |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
86 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
87 class |
31529
918e09edc6ed
Export typeinfo of base_mutex and autolock classes.
Markus Mützel <markus.muetzel@gmx.de>
parents:
30564
diff
changeset
|
88 OCTAVE_API |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
89 autolock |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
90 { |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
91 public: |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
92 autolock (const mutex& m, bool block = true) |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
93 : m_mutex (m), m_lock_result (false) |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
94 { |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
95 if (block) |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
96 { |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
97 m_mutex.lock (); |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
98 m_lock_result = true; |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
99 } |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
100 else |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
101 m_lock_result = m_mutex.try_lock (); |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
102 } |
7934 | 103 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
104 // No copying. |
13281
834f904a3dcb
Add support for full asynchronous graphics toolkit running in a separate
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11523
diff
changeset
|
105 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
106 autolock (const autolock&) = delete; |
13281
834f904a3dcb
Add support for full asynchronous graphics toolkit running in a separate
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11523
diff
changeset
|
107 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
108 autolock& operator = (const autolock&) = delete; |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7934
diff
changeset
|
109 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
110 ~autolock (void) |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
111 { |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
112 if (m_lock_result) |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
113 m_mutex.unlock (); |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
114 } |
13281
834f904a3dcb
Add support for full asynchronous graphics toolkit running in a separate
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11523
diff
changeset
|
115 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
116 bool ok (void) const { return m_lock_result; } |
7934 | 117 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
118 operator bool (void) const { return ok (); } |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
119 |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
120 private: |
22865
89756f2f085b
use c++11 style for deleting default copy constructor and assignment operator
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
121 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
122 mutex m_mutex; |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
123 |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
124 bool m_lock_result; |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
125 }; |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
126 |
13281
834f904a3dcb
Add support for full asynchronous graphics toolkit running in a separate
Michael Goffioul <michael.goffioul@gmail.com>
parents:
11523
diff
changeset
|
127 |
23057
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
128 class |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
129 OCTAVE_API |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
130 thread |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
131 { |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
132 public: |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
133 |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
134 static void init (void); |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
135 |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
136 static bool is_thread (void); |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
137 }; |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
138 } |
bb7513d73673
move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
139 |
7934 | 140 #endif |