annotate liboctave/util/oct-mutex.cc @ 23220:092078913d54

maint: Merge stable to default.
author John W. Eaton <jwe@octave.org>
date Wed, 22 Feb 2017 12:58:07 -0500
parents ef4d915df748 3ac9f9ecfae5
children 08036a7f3660
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 2008-2017 Michael Goffioul
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 This file is part of Octave.
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
8 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
10 (at your option) any later version.
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
15 GNU General Public License for more details.
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 */
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21202
diff changeset
24 # include "config.h"
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 #endif
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #include "oct-mutex.h"
7957
ba2e00a216e8 Do not use "error" in octave_base_mutex class
John W. Eaton <jwe@octave.org>
parents: 7952
diff changeset
28 #include "lo-error.h"
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
21979
d04da18a407a use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
30 #if defined (OCTAVE_USE_WINDOWS_API)
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 19697
diff changeset
31 # include <windows.h>
9233
b935bbfab7c4 Exclude pthread.h inclusion under Win32
Michael Goffioul <michael.goffioul@gmail.com>
parents: 7957
diff changeset
32 #elif defined (HAVE_PTHREAD_H)
21202
f7121e111991 maint: indent #ifdef blocks in liboctave and src directories.
Rik <rik@octave.org>
parents: 19697
diff changeset
33 # include <pthread.h>
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #endif
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
36 namespace octave
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
37 {
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
38 void
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
39 base_mutex::lock (void)
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
40 {
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
41 (*current_liboctave_error_handler) ("mutex not supported on this platform");
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
42 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
44 void
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
45 base_mutex::unlock (void)
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
46 {
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
47 (*current_liboctave_error_handler) ("mutex not supported on this platform");
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
48 }
13281
834f904a3dcb Add support for full asynchronous graphics toolkit running in a separate
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11523
diff changeset
49
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
50 bool
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
51 base_mutex::try_lock (void)
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
52 {
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
53 (*current_liboctave_error_handler) ("mutex not supported on this platform");
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
54
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
55 return false;
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
56 }
13281
834f904a3dcb Add support for full asynchronous graphics toolkit running in a separate
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11523
diff changeset
57
21979
d04da18a407a use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
58 #if defined (OCTAVE_USE_WINDOWS_API)
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
60 class
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
61 w32_mutex : public base_mutex
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
62 {
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
63 public:
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
64 w32_mutex (void)
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
65 : base_mutex ()
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
66 {
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
67 InitializeCriticalSection (&cs);
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
68 }
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
69
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
70 ~w32_mutex (void)
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
71 {
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
72 DeleteCriticalSection (&cs);
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
73 }
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
74
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
75 void lock (void)
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
76 {
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
77 EnterCriticalSection (&cs);
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
78 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
80 void unlock (void)
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
81 {
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
82 LeaveCriticalSection (&cs);
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
83 }
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
84
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
85 bool try_lock (void)
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
86 {
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
87 return (TryEnterCriticalSection (&cs) != 0);
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
88 }
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
89
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
90 private:
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
91 CRITICAL_SECTION cs;
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
92 };
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
93
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
94 static DWORD thread_id = 0;
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
95
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
96 void
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
97 thread::init (void)
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
98 {
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
99 thread_id = GetCurrentThreadId ();
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
100 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
102 bool
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
103 thread::is_thread (void)
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
104 {
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
105 return (GetCurrentThreadId () == thread_id);
13281
834f904a3dcb Add support for full asynchronous graphics toolkit running in a separate
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11523
diff changeset
106 }
834f904a3dcb Add support for full asynchronous graphics toolkit running in a separate
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11523
diff changeset
107
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 #elif defined (HAVE_PTHREAD_H)
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
110 class
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
111 pthread_mutex : public base_mutex
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
112 {
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
113 public:
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
114 pthread_mutex (void)
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
115 : base_mutex (), pm ()
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
116 {
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
117 pthread_mutexattr_t attr;
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
118
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
119 pthread_mutexattr_init (&attr);
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
120 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
121 pthread_mutex_init (&pm, &attr);
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
122 pthread_mutexattr_destroy (&attr);
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
123 }
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
124
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
125 ~pthread_mutex (void)
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
126 {
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
127 pthread_mutex_destroy (&pm);
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
128 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
130 void lock (void)
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
131 {
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
132 pthread_mutex_lock (&pm);
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
133 }
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
134
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
135 void unlock (void)
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
136 {
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
137 pthread_mutex_unlock (&pm);
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
138 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
140 bool try_lock (void)
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
141 {
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
142 return (pthread_mutex_trylock (&pm) == 0);
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
143 }
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
144
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
145 private:
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
146 pthread_mutex_t pm;
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
147 };
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
148
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
149 static pthread_t thread_id = 0;
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
150
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
151 void
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
152 thread::init (void)
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
153 {
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
154 thread_id = pthread_self ();
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
155 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
157 bool
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
158 thread::is_thread (void)
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
159 {
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
160 return (pthread_equal (thread_id, pthread_self ()) != 0);
13281
834f904a3dcb Add support for full asynchronous graphics toolkit running in a separate
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11523
diff changeset
161 }
834f904a3dcb Add support for full asynchronous graphics toolkit running in a separate
Michael Goffioul <michael.goffioul@gmail.com>
parents: 11523
diff changeset
162
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
163 #endif
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
164
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
165 static octave::base_mutex *
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
166 init_rep (void)
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
167 {
21979
d04da18a407a use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
168 #if defined (OCTAVE_USE_WINDOWS_API)
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
169 return new octave::w32_mutex ();
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
170 #elif defined (HAVE_PTHREAD_H)
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
171 return new octave::pthread_mutex ();
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172 #else
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
173 return new octave::base_mutex ();
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174 #endif
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
175 }
11501
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
176
23057
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
177 mutex::mutex (void) : rep (init_rep ()) { }
bb7513d73673 move mutex classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22755
diff changeset
178 }