Mercurial > octave
annotate liboctave/system/child-list.cc @ 30049:bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
* ODESFunc.h: Use "m_" prefix for member variables.
* child-list.cc, child-list.h: use "m_" prefix for member variables in child,
child_list classes.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 25 Aug 2021 17:28:52 -0700 |
parents | 0a5b15007766 |
children | a8c61e096c68 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
3 // Copyright (C) 1993-2021 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 # include "config.h" |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 #endif |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 #include "child-list.h" |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include "oct-syscalls.h" |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 namespace octave |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 { |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 class pid_equal |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 { |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 public: |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 pid_equal (pid_t v) : val (v) { } |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
41 bool operator () (const child& oc) const { return oc.m_pid == val; } |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 private: |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 pid_t val; |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 }; |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
48 void child_list::remove (pid_t m_pid) |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 { |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
50 m_list.remove_if (pid_equal (m_pid)); |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 } |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
52 |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
53 void child_list::child_list::insert (pid_t m_pid, child::child_event_handler f) |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
54 { |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
55 m_list.append (child (m_pid, f)); |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 } |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
57 |
24734
5d8c4cbc56d7
don't use singleton pattern for child_list
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
58 void child_list::reap (void) |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 { |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 // Mark the record for PID invalid. |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 |
24736
cd25b9c5f808
eliminate useless public iterator typedefs in child_list class
John W. Eaton <jwe@octave.org>
parents:
24734
diff
changeset
|
62 for (auto& oc : m_list) |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 { |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 // The call to the child::child_event_handler might |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 // invalidate the iterator (for example, by calling |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
66 // child_list::remove), so we increment the iterator |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 // here. |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
69 if (oc.m_have_status) |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 { |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
71 oc.m_have_status = 0; |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
73 child::child_event_handler f = oc.m_handler; |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
75 if (f && f (oc.m_pid, oc.m_status)) |
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
76 oc.m_pid = -1; |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 } |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
78 } |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
79 |
24734
5d8c4cbc56d7
don't use singleton pattern for child_list
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
80 // ?? |
5d8c4cbc56d7
don't use singleton pattern for child_list
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
81 remove (-1); |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
82 } |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
83 |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
84 // Wait on our children and record any changes in their m_status. |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
85 |
24734
5d8c4cbc56d7
don't use singleton pattern for child_list
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
86 bool child_list::wait (void) |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
87 { |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
88 bool retval = false; |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 |
24736
cd25b9c5f808
eliminate useless public iterator typedefs in child_list class
John W. Eaton <jwe@octave.org>
parents:
24734
diff
changeset
|
90 for (auto& oc : m_list) |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 { |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
92 pid_t m_pid = oc.m_pid; |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
93 |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
94 if (m_pid > 0) |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
95 { |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
96 int m_status; |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
97 |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
98 if (sys::waitpid (m_pid, &m_status, sys::wnohang ()) > 0) |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
99 { |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
100 oc.m_have_status = 1; |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
101 |
30049
bffdbda91d28
maint: use "m_" prefix for member variables in child, child_list classes
Rik <rik@octave.org>
parents:
29358
diff
changeset
|
102 oc.m_status = m_status; |
22049
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
103 |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
104 retval = true; |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
105 |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
106 break; |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
107 } |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
108 } |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
109 } |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
110 |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
111 return retval; |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
112 } |
ccf50f029999
move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
113 } |