annotate libinterp/corefcn/event-queue.h @ 27919:1891570abac8

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2020.
author John W. Eaton <jwe@octave.org>
date Mon, 06 Jan 2020 22:29:51 -0500
parents b442ec6dda5c
children bd51beb6205e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
27919
1891570abac8 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27918
diff changeset
3 Copyright (C) 2012-2020 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
4
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
5 See the file COPYRIGHT.md in the top-level directory of this distribution
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
6 or <https://octave.org/COPYRIGHT.html/>.
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26377
diff changeset
7
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 This file is part of Octave.
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23747
diff changeset
11 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
12 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23747
diff changeset
13 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
14 (at your option) any later version.
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
16 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
17 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
19 GNU General Public License for more details.
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 You should have received a copy of the GNU General Public License
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23747
diff changeset
23 <https://www.gnu.org/licenses/>.
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 */
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20545
diff changeset
27 #if ! defined (octave_event_queue_h)
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #define octave_event_queue_h 1
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
21244
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21141
diff changeset
30 #include "octave-config.h"
1473547f50f5 include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents: 21141
diff changeset
31
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include <queue>
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include <memory>
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include "action-container.h"
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36
23747
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
37 namespace octave
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 {
23747
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
39 class
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
40 event_queue : public action_container
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 {
23747
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
42 public:
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
43
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
44 event_queue (void) : fifo () { }
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
45
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
46 // No copying!
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
47
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
48 event_queue (const event_queue&) = delete;
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
49
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
50 event_queue& operator = (const event_queue&) = delete;
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51
23747
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
52 // Destructor should not raise an exception, so all actions
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
53 // registered should be exception-safe. If you're not sure, see
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
54 // event_queue_safe.
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55
23747
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
56 ~event_queue (void) { run (); }
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
57
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
58 void run_first (void)
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
59 {
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
60 if (! empty ())
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
61 {
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
62 // No leak on exception!
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
63 std::unique_ptr<elem> ptr (fifo.front ());
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
64 fifo.pop ();
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
65 ptr->run ();
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
66 }
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
67 }
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68
23747
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
69 void discard_first (void)
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
70 {
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
71 if (! empty ())
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
72 {
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
73 elem *ptr = fifo.front ();
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
74 fifo.pop ();
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
75 delete ptr;
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
76 }
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
77 }
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78
23747
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
79 size_t size (void) const { return fifo.size (); }
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
80
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
81 protected:
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82
25653
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
83 void add_action (elem *new_elem)
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
84 {
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
85 fifo.push (new_elem);
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
86 }
b3d357990b52 better use of templates for action_container and derived classes
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
87
23747
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
88 std::queue<elem *> fifo;
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
89 };
22869
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22865
diff changeset
90
23747
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
91 // Like event_queue, but this one will guard against the
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
92 // possibility of seeing an exception (or interrupt) in the cleanup actions.
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
93 // Not that we can do much about it, but at least we won't crash.
22869
f75d289645ec make deleted functions public
John W. Eaton <jwe@octave.org>
parents: 22865
diff changeset
94
23747
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
95 class
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
96 event_queue_safe : public event_queue
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
97 {
23747
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
98 private:
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
99
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
100 void warn_unhandled_exception (void) const;
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
101
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
102 public:
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
103
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
104 event_queue_safe (void) : event_queue () { }
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
105
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
106 // No copying!
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
107
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
108 event_queue_safe (const event_queue_safe&) = delete;
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
109
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
110 event_queue_safe& operator = (const event_queue_safe&) = delete;
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
111
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
112 ~event_queue_safe (void)
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
113 {
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
114 while (! empty ())
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
115 {
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
116 try
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
117 {
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
118 run_first ();
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
119 }
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
120 catch (...) // Yes, the black hole. Remember we're in a dtor.
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
121 {
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
122 warn_unhandled_exception ();
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
123 }
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
124 }
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
125 }
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
126 };
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
127 }
0b4d1575a2e2 move action_container and event_queue classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
128
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 #endif