annotate libinterp/corefcn/event-queue.h @ 20595:c1a6c31ac29a

eliminate more simple uses of error_state * ov-classdef.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Tue, 06 Oct 2015 00:20:02 -0400
parents c547458dc10e
children
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
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
3 Copyright (C) 2012-2015 John W. Eaton
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 This file is part of Octave.
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 option) any later version.
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 for more details.
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 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
18 along with Octave; see the file COPYING. If not, see
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
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 */
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 #if !defined (octave_event_queue_h)
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 #define octave_event_queue_h 1
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 #include <queue>
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #include <memory>
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include "action-container.h"
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 class
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 event_queue : public action_container
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 {
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 public:
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 event_queue (void) : fifo () { }
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 // Destructor should not raise an exception, so all actions
20577
c547458dc10e eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
39 // registered should be exception-safe. If you're not sure, see
c547458dc10e eliminate error_state from most header files
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
40 // event_queue_safe.
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 ~event_queue (void) { run (); }
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 void add (elem *new_elem)
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 {
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 fifo.push (new_elem);
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 }
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 void run_first (void)
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 {
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 if (! empty ())
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 {
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 // No leak on exception!
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 std::auto_ptr<elem> ptr (fifo.front ());
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 fifo.pop ();
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 ptr->run ();
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 }
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 }
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 void discard_first (void)
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 {
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 if (! empty ())
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 {
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 elem *ptr = fifo.front ();
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 fifo.pop ();
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 delete ptr;
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 }
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 }
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 size_t size (void) const { return fifo.size (); }
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 protected:
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 std::queue<elem *> fifo;
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 private:
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 // No copying!
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 event_queue (const event_queue&);
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 event_queue& operator = (const event_queue&);
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 };
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 // Like event_queue, but this one will guard against the
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 // possibility of seeing an exception (or interrupt) in the cleanup
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 // actions. Not that we can do much about it, but at least we won't
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 // crash.
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 class
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 event_queue_safe : public event_queue
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 {
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 private:
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 static void gripe_exception (void);
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 public:
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 event_queue_safe (void) : event_queue () { }
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 ~event_queue_safe (void)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
102 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
103 while (! empty ())
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
104 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
105 try
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
106 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
107 run_first ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
108 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
109 catch (...) // Yes, the black hole. Remember we're in a dtor.
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
110 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
111 gripe_exception ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
112 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
113 }
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
114 }
15396
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116 private:
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 // No copying!
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 event_queue_safe (const event_queue_safe&);
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 event_queue_safe& operator = (const event_queue_safe&);
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 };
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124
1054ab58cd58 abstract unwind_protect
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 #endif