Mercurial > hg > octave-lyh
annotate liboctave/oct-mutex.cc @ 10485:b4e14e628fc9
Truncate argv() for scripts used without command line parameters. Bug #29423
author | Judd Storrs <jstorrs@gmail.com> |
---|---|
date | Fri, 02 Apr 2010 13:28:02 -0400 |
parents | 16f53d29049f |
children | 331fcc41ca23 |
rev | line source |
---|---|
7934 | 1 /* |
2 | |
9245 | 3 Copyright (C) 2008, 2009 Michael Goffioul |
7934 | 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 (__WIN32__) && ! defined (__CYGWIN__) | |
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 | 34 #endif |
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 | 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 | 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 | 47 |
48 #if defined (__WIN32__) && ! defined (__CYGWIN__) | |
49 | |
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 | 52 { |
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 | 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 | 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 | 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 | 74 |
75 private: | |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
76 CRITICAL_SECTION cs; |
7934 | 77 }; |
78 | |
79 #elif defined (HAVE_PTHREAD_H) | |
80 | |
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 | 83 { |
84 public: | |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
85 octave_pthread_mutex (void) |
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
86 : octave_base_mutex () |
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 | 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 | 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 | 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 | 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 | 110 |
111 private: | |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
112 pthread_mutex_t pm; |
7934 | 113 }; |
114 | |
115 #endif | |
116 | |
117 octave_mutex::octave_mutex (void) | |
118 { | |
119 #if defined (__WIN32__) && ! defined (__CYGWIN__) | |
120 rep = new octave_w32_mutex (); | |
121 #elif defined (HAVE_PTHREAD_H) | |
122 rep = new octave_pthread_mutex (); | |
123 #else | |
7952
2c0a0edae596
reorganize octave_mutex class
John W. Eaton <jwe@octave.org>
parents:
7943
diff
changeset
|
124 rep = new octave_base_mutex (); |
7934 | 125 #endif |
126 } |