Mercurial > octave
annotate liboctave/oct-mutex.cc @ 7957:ba2e00a216e8
Do not use "error" in octave_base_mutex class
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 21 Jul 2008 15:23:29 -0400 |
parents | 2c0a0edae596 |
children | b935bbfab7c4 |
rev | line source |
---|---|
7934 | 1 /* |
2 | |
3 Copyright (C) 2008 Michael Goffioul | |
4 | |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 3 of the License, or (at your | |
10 option) any later version. | |
11 | |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with Octave; see the file COPYING. If not, see | |
19 <http://www.gnu.org/licenses/>. | |
20 | |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
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 | 29 |
30 #if defined (HAVE_PTHREAD_H) | |
31 #include <pthread.h> | |
32 #endif | |
33 | |
34 #if defined (__WIN32__) && ! defined (__CYGWIN__) | |
35 #include <windows.h> | |
36 #endif | |
37 | |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
38 void |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
39 octave_base_mutex::lock (void) |
7934 | 40 { |
7957
ba2e00a216e8
Do not use "error" in octave_base_mutex class
John W. Eaton <jwe@octave.org>
parents:
7952
diff
changeset
|
41 (*current_liboctave_error_handler) ("mutex not supported on this platform"); |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
42 } |
7934 | 43 |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
44 void |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
45 octave_base_mutex::unlock (void) |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
46 { |
7957
ba2e00a216e8
Do not use "error" in octave_base_mutex class
John W. Eaton <jwe@octave.org>
parents:
7952
diff
changeset
|
47 (*current_liboctave_error_handler) ("mutex not supported on this platform"); |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
48 } |
7934 | 49 |
50 #if defined (__WIN32__) && ! defined (__CYGWIN__) | |
51 | |
52 class | |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
53 octave_w32_mutex : public octave_base_mutex |
7934 | 54 { |
55 public: | |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
56 octave_w32_mutex (void) |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
57 : octave_base_mutex () |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
58 { |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
59 InitializeCriticalSection (&cs); |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
60 } |
7934 | 61 |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
62 ~octave_w32_mutex (void) |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
63 { |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
64 DeleteCriticalSection (&cs); |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
65 } |
7934 | 66 |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
67 void lock (void) |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
68 { |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
69 EnterCriticalSection (&cs); |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
70 } |
7934 | 71 |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
72 void unlock (void) |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
73 { |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
74 LeaveCriticalSection (&cs); |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
75 } |
7934 | 76 |
77 private: | |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
78 CRITICAL_SECTION cs; |
7934 | 79 }; |
80 | |
81 #elif defined (HAVE_PTHREAD_H) | |
82 | |
83 class | |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
84 octave_pthread_mutex : public octave_base_mutex |
7934 | 85 { |
86 public: | |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
87 octave_pthread_mutex (void) |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
88 : octave_base_mutex () |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
89 { |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
90 pthread_mutexattr_t attr; |
7934 | 91 |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
92 pthread_mutexattr_init (&attr); |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
93 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
94 pthread_mutex_init (&pm, &attr); |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
95 pthread_mutexattr_destroy (&attr); |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
96 } |
7934 | 97 |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
98 ~octave_pthread_mutex (void) |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
99 { |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
100 pthread_mutex_destroy (&pm); |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
101 } |
7934 | 102 |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
103 void lock (void) |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
104 { |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
105 pthread_mutex_lock (&pm); |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
106 } |
7934 | 107 |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
108 void unlock (void) |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
109 { |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
110 pthread_mutex_unlock (&pm); |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
111 } |
7934 | 112 |
113 private: | |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
114 pthread_mutex_t pm; |
7934 | 115 }; |
116 | |
117 #endif | |
118 | |
119 octave_mutex::octave_mutex (void) | |
120 { | |
121 #if defined (__WIN32__) && ! defined (__CYGWIN__) | |
122 rep = new octave_w32_mutex (); | |
123 #elif defined (HAVE_PTHREAD_H) | |
124 rep = new octave_pthread_mutex (); | |
125 #else | |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
126 rep = new octave_base_mutex (); |
7934 | 127 #endif |
128 } |