annotate liboctave/system/child-list.cc @ 27923:bd51beb6205e

update formatting of copyright notices * Use <https://octave.org/copyright/> instead of <https://octave.org/COPYRIGHT.html/>. * For consistency with other comments in the Octave sources, use C++-style comments for copyright blocks in C and C++ files. * Use delimiters above and below copyright blocks that are appropriate for the language used in the file. * Eliminate extra spacing inside copyright blocks. * lex.ll (looks_like_copyright): Also allow newlines and carriage returns before the word "Copyright". * scripts/mk-doc.pl (gethelp): Also skip empty comment lines. * bp-table.cc, type.m: Adjust tests.
author John W. Eaton <jwe@octave.org>
date Wed, 08 Jan 2020 11:59:41 -0500
parents 1891570abac8
children 0a5b15007766
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
3 // Copyright (C) 1993-2020 The Octave Project Developers
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
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 bool operator () (const child& oc) const { return oc.pid == val; }
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
24734
5d8c4cbc56d7 don't use singleton pattern for child_list
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
48 void child_list::remove (pid_t pid)
22049
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 {
24734
5d8c4cbc56d7 don't use singleton pattern for child_list
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
50 m_list.remove_if (pid_equal (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
24734
5d8c4cbc56d7 don't use singleton pattern for child_list
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
53 void child_list::child_list::insert (pid_t 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 {
24734
5d8c4cbc56d7 don't use singleton pattern for child_list
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
55 m_list.append (child (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
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 if (oc.have_status)
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 {
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 oc.have_status = 0;
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 child::child_event_handler f = oc.handler;
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 if (f && f (oc.pid, oc.status))
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 oc.pid = -1;
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
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 // Wait on our children and record any changes in their status.
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 {
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 pid_t pid = oc.pid;
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 if (pid > 0)
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 {
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 int status;
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
98 if (sys::waitpid (pid, &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 {
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 oc.have_status = 1;
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101
ccf50f029999 move octave_child_list to separate file and define inside namespace
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102 oc.status = status;
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 }