GNU Octave
10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Loading...
Searching...
No Matches
oct-mutex.h
Go to the documentation of this file.
1
////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (C) 2008-2025 The Octave Project Developers
4
//
5
// See the file COPYRIGHT.md in the top-level directory of this
6
// distribution or <https://octave.org/copyright/>.
7
//
8
// This file is part of Octave.
9
//
10
// Octave is free software: you can redistribute it and/or modify it
11
// under the terms of the GNU General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
14
//
15
// Octave is distributed in the hope that it will be useful, but
16
// WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU General Public License for more details.
19
//
20
// You should have received a copy of the GNU General Public License
21
// along with Octave; see the file COPYING. If not, see
22
// <https://www.gnu.org/licenses/>.
23
//
24
////////////////////////////////////////////////////////////////////////
25
26
#if ! defined (octave_oct_mutex_h)
27
#define octave_oct_mutex_h 1
28
29
#include "octave-config.h"
30
31
#include <memory>
32
33
OCTAVE_BEGIN_NAMESPACE
(octave)
34
35
class
mutex
;
36
37
class
OCTAVE_API
base_mutex
38
{
39
public
:
40
friend
class
mutex
;
41
42
OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE (
base_mutex
)
43
44
virtual ~
base_mutex
() = default;
45
46
virtual
void
lock ();
47
48
virtual
void
unlock ();
49
50
virtual
bool
try_lock ();
51
};
52
53
class
OCTAVE_API
mutex
54
{
55
public
:
56
mutex
();
57
58
OCTAVE_DEFAULT_COPY_MOVE_DELETE (
mutex
)
59
60
void lock ()
61
{
62
m_rep->lock ();
63
}
64
65
void
unlock
()
66
{
67
m_rep->unlock ();
68
}
69
70
bool
try_lock
()
71
{
72
return
m_rep->try_lock ();
73
}
74
75
protected
:
76
std::shared_ptr<base_mutex>
m_rep
;
77
};
78
79
class
OCTAVE_API
autolock
80
{
81
public
:
82
autolock
(
const
mutex
& m,
bool
block =
true
)
83
: m_mutex (m), m_lock_result (false)
84
{
85
if
(block)
86
{
87
m_mutex.lock ();
88
m_lock_result =
true
;
89
}
90
else
91
m_lock_result = m_mutex.try_lock ();
92
}
93
94
OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (
autolock
)
95
96
~autolock
()
97
{
98
if
(m_lock_result)
99
m_mutex.unlock ();
100
}
101
102
bool
ok
()
const
{
return
m_lock_result; }
103
104
operator
bool
()
const
{
return
ok (); }
105
106
private
:
107
108
mutex
m_mutex;
109
110
bool
m_lock_result;
111
};
112
113
114
class
OCTAVE_API
thread
115
{
116
public
:
117
118
static
void
init
();
119
120
static
bool
is_thread
();
121
};
122
123
OCTAVE_END_NAMESPACE(octave)
124
125
#endif
autolock
Definition
oct-mutex.h:80
autolock::ok
bool ok() const
Definition
oct-mutex.h:102
autolock::~autolock
~autolock()
Definition
oct-mutex.h:96
autolock::autolock
autolock(const mutex &m, bool block=true)
Definition
oct-mutex.h:82
base_mutex
Definition
oct-mutex.h:38
bool
mutex
Definition
oct-mutex.h:54
mutex::unlock
void unlock()
Definition
oct-mutex.h:65
mutex::try_lock
bool try_lock()
Definition
oct-mutex.h:70
mutex::m_rep
std::shared_ptr< base_mutex > m_rep
Definition
oct-mutex.h:76
thread
Definition
oct-mutex.h:115
thread::init
static void init()
thread::is_thread
static bool is_thread()
OCTAVE_BEGIN_NAMESPACE
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTAVE_API
#define OCTAVE_API
Definition
main.in.cc:55
liboctave
util
oct-mutex.h
Generated on Sat Aug 2 2025 06:52:15 for GNU Octave by
1.9.8