annotate liboctave/oct-mutex.cc @ 11501:331fcc41ca23

data member initialization fixes
author John W. Eaton <jwe@octave.org>
date Thu, 13 Jan 2011 03:04:51 -0500
parents 16f53d29049f
children fd0a3ac60b0e
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
9245
16f53d29049f update copyright notices
John W. Eaton <jwe@octave.org>
parents: 9233
diff changeset
3 Copyright (C) 2008, 2009 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
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 option) any later version.
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 for more details.
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
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 #include <config.h>
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
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #if defined (__WIN32__) && ! defined (__CYGWIN__)
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
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)
b935bbfab7c4 Exclude pthread.h inclusion under Win32
Michael Goffioul <michael.goffioul@gmail.com>
parents: 7957
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
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
36 void
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
37 octave_base_mutex::lock (void)
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 {
7957
ba2e00a216e8 Do not use "error" in octave_base_mutex class
John W. Eaton <jwe@octave.org>
parents: 7952
diff changeset
39 (*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
40 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
42 void
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
43 octave_base_mutex::unlock (void)
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
44 {
7957
ba2e00a216e8 Do not use "error" in octave_base_mutex class
John W. Eaton <jwe@octave.org>
parents: 7952
diff changeset
45 (*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
46 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 #if defined (__WIN32__) && ! defined (__CYGWIN__)
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 class
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
51 octave_w32_mutex : public octave_base_mutex
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 {
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 public:
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
54 octave_w32_mutex (void)
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
55 : octave_base_mutex ()
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
56 {
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
57 InitializeCriticalSection (&cs);
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
58 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
60 ~octave_w32_mutex (void)
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
61 {
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
62 DeleteCriticalSection (&cs);
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
63 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
65 void lock (void)
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
66 {
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
67 EnterCriticalSection (&cs);
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
68 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
70 void unlock (void)
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
71 {
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
72 LeaveCriticalSection (&cs);
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
73 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 private:
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
76 CRITICAL_SECTION cs;
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 };
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 #elif defined (HAVE_PTHREAD_H)
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 class
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
82 octave_pthread_mutex : public octave_base_mutex
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 {
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 public:
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
85 octave_pthread_mutex (void)
11501
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
86 : octave_base_mutex (), pm ()
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
87 {
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
88 pthread_mutexattr_t attr;
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
90 pthread_mutexattr_init (&attr);
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
91 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
92 pthread_mutex_init (&pm, &attr);
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
93 pthread_mutexattr_destroy (&attr);
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
94 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
96 ~octave_pthread_mutex (void)
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
97 {
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
98 pthread_mutex_destroy (&pm);
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
99 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
101 void lock (void)
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
102 {
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
103 pthread_mutex_lock (&pm);
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
104 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
106 void unlock (void)
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
107 {
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
108 pthread_mutex_unlock (&pm);
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
109 }
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 private:
7952
2c0a0edae596 reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents: 7943
diff changeset
112 pthread_mutex_t pm;
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 };
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 #endif
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116
11501
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
117 static octave_base_mutex *
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
118 init_rep (void)
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 {
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 #if defined (__WIN32__) && ! defined (__CYGWIN__)
11501
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
121 return new octave_w32_mutex ();
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 #elif defined (HAVE_PTHREAD_H)
11501
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
123 return new octave_pthread_mutex ();
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124 #else
11501
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
125 return new octave_base_mutex ();
7934
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 #endif
5a156ab94dd2 Add octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 }
11501
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
128
331fcc41ca23 data member initialization fixes
John W. Eaton <jwe@octave.org>
parents: 9245
diff changeset
129 octave_mutex::octave_mutex (void) : rep (init_rep ()) { }