GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
thread-manager.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2013-2017 John W. Eaton
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 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #if defined (OCTAVE_USE_WINDOWS_API)
28 # include <windows.h>
29 #else
30 # include <pthread.h>
31 #endif
32 
33 #include "signal-wrappers.h"
34 
35 #include "thread-manager.h"
36 
37 #if defined (OCTAVE_USE_WINDOWS_API)
38 
39 class windows_thread_manager : public octave_base_thread_manager
40 {
41 public:
42 
43  windows_thread_manager (void) : octave_base_thread_manager () { }
44 
45  void register_current_thread (void) { }
46 
47  void interrupt (void)
48  {
49  GenerateConsoleCtrlEvent (CTRL_C_EVENT, 0);
50  }
51 };
52 
53 #else
54 
56 {
57 public:
58 
61  { }
62 
64  {
65  my_thread = pthread_self ();
66  initialized = true;
67  }
68 
69  void interrupt (void)
70  {
71  if (initialized)
72  {
73  // Send SIGINT to all other processes in our process group.
74  // This is needed to interrupt calls to system (), for example.
75 
76  // FIXME: What happens if some code inside a
77  // {BEGIN,END}_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE block starts
78  // additional threads and one of those happens to catch this signal?
79  // Would the interrupt handler and the subsequent longjmp and exception
80  // all be executed in the wrong thread? If so, is there any way to
81  // prevent that from happening?
82 
83  int sigint;
84  octave_get_sig_number ("SIGINT", &sigint);
85 
86  octave_kill_wrapper (0, sigint);
87  }
88  }
89 
90 private:
91 
92  pthread_t my_thread;
93 
95 };
96 
97 #endif
98 
100  : rep (octave_thread_manager::create_rep ())
101 { }
102 
103 void
105 {
107 }
108 
109 void
111 {
113 }
114 
117 {
118 #if defined (OCTAVE_USE_WINDOWS_API)
119  return new windows_thread_manager ();
120 #else
121  return new pthread_thread_manager ();
122 #endif
123 }
void register_current_thread(void)
int octave_kill_wrapper(pid_t pid, int signum)
static octave_base_thread_manager * create_rep(void)
virtual void interrupt(void)=0
static void unblock_interrupt_signal(void)
virtual void register_current_thread(void)=0
void octave_block_interrupt_signal(void)
is false
Definition: cellfun.cc:398
void octave_unblock_interrupt_signal(void)
bool octave_get_sig_number(const char *signame, int *signum)
static void block_interrupt_signal(void)