Mercurial > octave
comparison src/graphics.h.in @ 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 | 3cb8f1fe108c |
children | e1f76bfe0452 |
comparison
equal
deleted
inserted
replaced
13984:1126c2907878 | 13985:43cc49c7abd1 |
---|---|
40 #include "lo-ieee.h" | 40 #include "lo-ieee.h" |
41 | 41 |
42 #include "gripes.h" | 42 #include "gripes.h" |
43 #include "oct-map.h" | 43 #include "oct-map.h" |
44 #include "oct-mutex.h" | 44 #include "oct-mutex.h" |
45 #include "oct-refcount.h" | |
45 #include "ov.h" | 46 #include "ov.h" |
46 #include "txt-eng-ft.h" | 47 #include "txt-eng-ft.h" |
47 | 48 |
48 // FIXME -- maybe this should be a configure option? | 49 // FIXME -- maybe this should be a configure option? |
49 // Matlab defaults to "Helvetica", but that causes problems for many | 50 // Matlab defaults to "Helvetica", but that causes problems for many |
480 typedef std::map<listener_mode, octave_value_list>::iterator listener_map_iterator; | 481 typedef std::map<listener_mode, octave_value_list>::iterator listener_map_iterator; |
481 typedef std::map<listener_mode, octave_value_list>::const_iterator listener_map_const_iterator; | 482 typedef std::map<listener_mode, octave_value_list>::const_iterator listener_map_const_iterator; |
482 | 483 |
483 private: | 484 private: |
484 int id; | 485 int id; |
485 int count; | 486 octave_refcount<int> count; |
486 std::string name; | 487 std::string name; |
487 graphics_handle parent; | 488 graphics_handle parent; |
488 bool hidden; | 489 bool hidden; |
489 listener_map listeners; | 490 listener_map listeners; |
490 }; | 491 }; |
1908 rep->count++; | 1909 rep->count++; |
1909 } | 1910 } |
1910 | 1911 |
1911 ~property (void) | 1912 ~property (void) |
1912 { | 1913 { |
1913 if (--rep->count <= 0) | 1914 if (--rep->count == 0) |
1914 delete rep; | 1915 delete rep; |
1915 } | 1916 } |
1916 | 1917 |
1917 bool ok (void) const | 1918 bool ok (void) const |
1918 { return rep->ok (); } | 1919 { return rep->ok (); } |
1963 return *this; | 1964 return *this; |
1964 } | 1965 } |
1965 | 1966 |
1966 property& operator = (const property& p) | 1967 property& operator = (const property& p) |
1967 { | 1968 { |
1968 if (rep && --rep->count <= 0) | 1969 if (rep && --rep->count == 0) |
1969 delete rep; | 1970 delete rep; |
1970 | 1971 |
1971 rep = p.rep; | 1972 rep = p.rep; |
1972 rep->count++; | 1973 rep->count++; |
1973 | 1974 |
2131 | 2132 |
2132 void finalize (const graphics_handle&); | 2133 void finalize (const graphics_handle&); |
2133 | 2134 |
2134 private: | 2135 private: |
2135 std::string name; | 2136 std::string name; |
2136 int count; | 2137 octave_refcount<int> count; |
2137 | 2138 |
2138 private: | 2139 private: |
2139 void gripe_invalid (const std::string& fname) const | 2140 void gripe_invalid (const std::string& fname) const |
2140 { | 2141 { |
2141 if (! is_valid ()) | 2142 if (! is_valid ()) |
2737 get_toolkit ().update (go, id); | 2738 get_toolkit ().update (go, id); |
2738 } | 2739 } |
2739 | 2740 |
2740 protected: | 2741 protected: |
2741 // A reference count. | 2742 // A reference count. |
2742 int count; | 2743 octave_refcount<int> count; |
2743 | 2744 |
2744 // A flag telling whether this object is a valid object | 2745 // A flag telling whether this object is a valid object |
2745 // in the backend context. | 2746 // in the backend context. |
2746 bool toolkit_flag; | 2747 bool toolkit_flag; |
2747 | 2748 |
5095 virtual ~base_graphics_event (void) { } | 5096 virtual ~base_graphics_event (void) { } |
5096 | 5097 |
5097 virtual void execute (void) = 0; | 5098 virtual void execute (void) = 0; |
5098 | 5099 |
5099 private: | 5100 private: |
5100 int count; | 5101 octave_refcount<int> count; |
5101 }; | 5102 }; |
5102 | 5103 |
5103 class | 5104 class |
5104 graphics_event | 5105 graphics_event |
5105 { | 5106 { |