History

Basic implementation of Sys module functions - Sys.create, Sys.open, Sys.read, Sys.write - Sys.tokenize

Code analysis violations Bug in scheduler - race during with worker thread shutdown.

arr committed 10 years ago

Commit 992a33f1 parent 6d77c2d18 files · +695 −243Browse files

Showing the changes to src/vm/list.cpp (1 of 18 files). Show all

Unified · Split

src/vm/list.cpp+19−13
@@ -5,6 +5,7 @@ · 4 unmodified lines
55 //
66
77 #include <runtime.h>
8+#include <exceptions.h>
89 #include <vm_memory.h>
910 #include <debug.h>
1011
@@ -21,14 +22,10 @@ vm_list_t::vm_list_t(std::shared_ptr<const type_descriptor_t> td, vm_list_t *tai · 10 unmodified lines
2122 , _element_type{ td }
2223 , _is_alloc{ sizeof(_mem) < td->size_in_bytes }
2324 , _mem{}
24− , _tail{ tail }
25+ , _tail{ nullptr }
2526 {
2627 assert(_element_type != nullptr);
27− if (_tail != nullptr)
28− {
29− assert(tail->get_element_type() == _element_type);
30− _tail->add_ref();
31− }
28+ set_tail(tail);
3229
3330 // If the default list element storage is not enough, allocate more memory.
3431 if (_is_alloc)
@@ -41,14 +38,15 @@ vm_list_t::vm_list_t(std::shared_ptr<const type_descriptor_t> td, vm_list_t *tai · 6 unmodified lines
4138 init_memory(*_element_type, &_mem.local);
4239 }
4340
44− debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm list: new\n");
41+ if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())
42+ debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm list\n");
4543 }
4644
4745 vm_list_t::~vm_list_t()
4846 {
4947 // Remove tail
5048 dec_ref_count_and_free(_tail);
51− _tail = nullptr;
49+ debug::assign_debug_pointer(&_tail);
5250
5351 // Destroy and free the list element, if default element size was surpassed.
5452 if (_is_alloc)
@@ -88,12 +86,20 @@ vm_list_t *vm_list_t::get_tail() const · 33 unmodified lines
8886 return _tail;
8987 }
9088
91−vm_list_t *vm_list_t::drop_tail()
89+void vm_list_t::set_tail(vm_list_t *new_tail)
9290 {
93− auto tail = _tail;
94− _tail = nullptr;
95− tail->release();
96− return tail;
91+ if (new_tail != nullptr)
92+ {
93+ if (new_tail->get_element_type() != _element_type)
94+ throw type_violation{};
95+
96+ new_tail->add_ref();
97+ }
98+
99+ auto prev_tail = _tail;
100+ _tail = new_tail;
101+
102+ dec_ref_count_and_free(prev_tail);
97103 }
98104
99105 pointer_t vm_list_t::value() const