Mercurial > hg > octave-nkf
annotate src/debug.h @ 13985:43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
* configure.ac: New --enable-atomic-refcount argument.
(octave_allocator): Fix USE_OCTAVE_ALLOCATOR variable assignment.
(OCTAVE_CONFIG_INCLUDED): New macro in config.h.
* oct-refcount.h (OCTREFCOUNT_ATOMIC_INCREMENT,
OCTREFCOUNT_ATOMIC_INCREMENT_POST, OCTREFCOUNT_ATOMIC_DECREMENT,
OCTREFCOUNT_ATOMIC_DECREMENT_POST): New macro, defined for MSVC and GCC
when USE_ATOMIC_REFCOUNT is defined.
(octave_refcount:operator++, octave_refcount::operator--): Use them.
(octave_refcount::operator count_type): Cast returned value to volatile.
(octave_refcount::direct): Remove unsafe member.
* Array.h (Array::make_unique): Delete rep if refcount reaches 0.
* Sparse.h (Sparse::make_unique): Delete rep if refcount reaches 0.
* Array.h (Array:~Array, Array::operator=): Delete rep only when refcount is
excatly 0.
* Array.cc (Array::clear): Likewise.
* Sparse.cc (Sparse::~Sparse, Sparse::operator=): Likewise.
* SparseCmplxQR.h (SparseCmplxQR::~SparseCmplxQR, SparseCmplxQR::operator=):
Likewise.
* SparseQR.h (SparseQR::~SparseQR, SparseQR::operator=): Likewise.
* sparse-base-chol.h (sparse_base_chol::~sparse_base_chol,
sparse_base_chol::operator): Likewise.
* dim-vector.h (oct-refcount.h): New included header.
(dim_vector::make_unique, dim_vector::resize): Use OCTREFCOUNT_ATOMIC_DECREMENT
macro and delete rep when refcount reaches 0.
(dim_vector::dim_vector): Use OCTREFCOUNT_ATOMIC_INCREMENT.
(dim_vector::operator=): Use OCTREFCOUNT_ATOMIC_INCREMENT and
OCTREFCOUNT_ATOMIC_DECREMENT.
(dim_vector::~dim_vector): Use OCTREFCOUNT_ATOMIC_DECREMENT.
* oct-mutex.h (oct-refcount.h): New included header.
(octave_base_mutex::count): Use octave_refcount class.
* gl-render.cc (oct-refcount.h): New included header.
* graphics.h.in (oct-refcount.h): Likewise.
(base_property::count, base_graphics_toolkit::count,
base_graphics_object::count, base_graphics_event::count): Use octave_refcount.
(property::~property, property::operator=): Delete rep only when refcountn is
excatly 0.
* oct-map.h (octave_fields::make_unique): Delete rep when refcount reaches 0.
* oct-stream.h (oct-refcount.h): New included header.
(octave_base_stream::count): Use octave_refcount class.
* ov.h (octave_value::make_unique): Delete rep when refcount reaches 0.
* symtab.h (oct-refcount.h): New included header.
(symbol_record_rep::count, fcn_info_rep::count): Use octave_refcount class.
* DLD-FUNCTIONS/urlwrite.cc (oct-refcount.h): New included header.
(curl_handle_rep::count): Use octave_refcount class.
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Sat, 03 Dec 2011 15:19:42 +0000 |
parents | 7dd7cccf0757 |
children | 72c96de7a403 |
rev | line source |
---|---|
7084 | 1 /* |
2 | |
11523 | 3 Copyright (C) 2001-2011 Ben Sapp |
7084 | 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 (octave_debug_h) | |
24 #define octave_debug_h 1 | |
25 | |
26 #include <map> | |
9183
94ae487acd1b
use set instead of map to keep track of debugger breakpoints
jpswensen@compsci34-754-2010.compscidhcp.jhu.edu
parents:
8920
diff
changeset
|
27 #include <set> |
7084 | 28 #include "ov.h" |
29 #include "dRowVector.h" | |
30 | |
31 class octave_value_list; | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7084
diff
changeset
|
32 class octave_user_code; |
7084 | 33 |
34 // Interface to breakpoints,. | |
35 | |
9237
3c1762c7e787
Add missing xxx_API decoration and remove misplaced ones
Michael Goffioul <michael.goffioul@gmail.com>
parents:
9183
diff
changeset
|
36 class |
3c1762c7e787
Add missing xxx_API decoration and remove misplaced ones
Michael Goffioul <michael.goffioul@gmail.com>
parents:
9183
diff
changeset
|
37 OCTINTERP_API |
3c1762c7e787
Add missing xxx_API decoration and remove misplaced ones
Michael Goffioul <michael.goffioul@gmail.com>
parents:
9183
diff
changeset
|
38 bp_table |
7084 | 39 { |
40 private: | |
41 | |
11584
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11523
diff
changeset
|
42 bp_table (void) : bp_set () { } |
7084 | 43 |
44 ~bp_table (void) { } | |
45 | |
46 public: | |
47 | |
48 typedef std::map<int, int> intmap; | |
49 | |
50 typedef intmap::const_iterator const_intmap_iterator; | |
51 typedef intmap::iterator intmap_iterator; | |
52 | |
53 typedef std::map <std::string, intmap> fname_line_map; | |
54 | |
55 typedef fname_line_map::const_iterator const_fname_line_map_iterator; | |
56 typedef fname_line_map::iterator fname_line_map_iterator; | |
57 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
58 static bool instance_ok (void); |
7084 | 59 |
60 // Add a breakpoint at the nearest executable line. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
61 static intmap add_breakpoint (const std::string& fname = "", |
10313 | 62 const intmap& lines = intmap ()) |
7084 | 63 { |
64 return instance_ok () | |
65 ? instance->do_add_breakpoint (fname, lines) : intmap (); | |
66 } | |
67 | |
68 // Remove a breakpoint from a line in file. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
69 static int remove_breakpoint (const std::string& fname = "", |
10313 | 70 const intmap& lines = intmap ()) |
7084 | 71 { |
72 return instance_ok () | |
73 ? instance->do_remove_breakpoint (fname, lines) : 0; | |
74 } | |
75 | |
76 // Remove all the breakpoints in a specified file. | |
8123
eb2beef9a9ff
clear breakpoints is function found to be out of date
David Bateman <dbateman@free.fr>
parents:
7719
diff
changeset
|
77 static intmap remove_all_breakpoints_in_file (const std::string& fname, |
10313 | 78 bool silent = false) |
7084 | 79 { |
80 return instance_ok () | |
8123
eb2beef9a9ff
clear breakpoints is function found to be out of date
David Bateman <dbateman@free.fr>
parents:
7719
diff
changeset
|
81 ? instance->do_remove_all_breakpoints_in_file (fname, silent) : intmap (); |
7084 | 82 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
83 |
7084 | 84 // Remove all the breakpoints registered with octave. |
85 static void remove_all_breakpoints (void) | |
86 { | |
87 if (instance_ok ()) | |
88 instance->do_remove_all_breakpoints (); | |
89 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
90 |
7084 | 91 // Return all breakpoints. Each element of the map is a vector |
92 // containing the breakpoints corresponding to a given function name. | |
93 static fname_line_map | |
94 get_breakpoint_list (const octave_value_list& fname_list) | |
95 { | |
96 return instance_ok () | |
97 ? instance->do_get_breakpoint_list (fname_list) : fname_line_map (); | |
98 } | |
99 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
100 static bool |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
101 have_breakpoints (void) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
102 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
103 return instance_ok () ? instance->do_have_breakpoints () : 0; |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
104 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
105 |
7084 | 106 private: |
107 | |
9183
94ae487acd1b
use set instead of map to keep track of debugger breakpoints
jpswensen@compsci34-754-2010.compscidhcp.jhu.edu
parents:
8920
diff
changeset
|
108 typedef std::set<std::string>::const_iterator const_bp_set_iterator; |
94ae487acd1b
use set instead of map to keep track of debugger breakpoints
jpswensen@compsci34-754-2010.compscidhcp.jhu.edu
parents:
8920
diff
changeset
|
109 typedef std::set<std::string>::iterator bp_set_iterator; |
7084 | 110 |
9183
94ae487acd1b
use set instead of map to keep track of debugger breakpoints
jpswensen@compsci34-754-2010.compscidhcp.jhu.edu
parents:
8920
diff
changeset
|
111 // Set of function names containing at least one breakpoint. |
94ae487acd1b
use set instead of map to keep track of debugger breakpoints
jpswensen@compsci34-754-2010.compscidhcp.jhu.edu
parents:
8920
diff
changeset
|
112 std::set<std::string> bp_set; |
7084 | 113 |
114 static bp_table *instance; | |
115 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
116 static void cleanup_instance (void) { delete instance; instance = 0; } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
117 |
7084 | 118 intmap do_add_breakpoint (const std::string& fname, const intmap& lines); |
119 | |
120 int do_remove_breakpoint (const std::string&, const intmap& lines); | |
121 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
122 intmap do_remove_all_breakpoints_in_file (const std::string& fname, |
10313 | 123 bool silent); |
7084 | 124 |
125 void do_remove_all_breakpoints (void); | |
126 | |
127 fname_line_map do_get_breakpoint_list (const octave_value_list& fname_list); | |
128 | |
9183
94ae487acd1b
use set instead of map to keep track of debugger breakpoints
jpswensen@compsci34-754-2010.compscidhcp.jhu.edu
parents:
8920
diff
changeset
|
129 bool do_have_breakpoints (void) { return (! bp_set.empty ()); } |
7084 | 130 }; |
131 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
132 std::string get_file_line (const std::string& fname, size_t line); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
133 |
7084 | 134 #endif |