Skip to content

Commit

Permalink
Review code
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed Sep 14, 2023
1 parent 56ea017 commit 6b7f5d8
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/xtd.core/src/xtd/threading/monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ class monitor::critical_section {
public:
critical_section() : handle_(std::make_shared<intptr>(native::critical_section::create())) {}
critical_section(const critical_section&) = default;
critical_section& operator =(const critical_section&) = default;
critical_section& operator =(const critical_section& other) {
native::critical_section::destroy(*handle_);
handle_ = other.handle_;
return *this;
}
critical_section(critical_section&&) = default;
~critical_section() {if (handle_.use_count() == 1) native::critical_section::destroy(*handle_);}

Expand Down Expand Up @@ -52,7 +56,11 @@ class monitor::condition_variable {
public:
condition_variable() : handle_(std::make_shared<intptr>(native::condition_variable::create())) {}
condition_variable(const condition_variable&) = default;
condition_variable& operator =(const condition_variable&) = default;
condition_variable& operator =(const condition_variable& other) {
native::critical_section::destroy(*handle_);
handle_ = other.handle_;
return *this;
}
condition_variable(condition_variable&&) = default;
~condition_variable() {if (handle_.use_count() == 1) native::condition_variable::destroy(*handle_);}

Expand Down Expand Up @@ -98,17 +106,15 @@ void monitor::exit_ptr(object_ptr obj) {
throw synchronization_lock_exception {csf_};
}

item saved;
item* monitor_data = &get_static_data().monitor_items[obj.first];
monitor_data->thread_id = thread::invalid_thread_id;
monitor_data->critical_section.leave();
get_static_data().monitor_items_critical_section.leave();

if (interlocked::decrement(monitor_data->used_counter) == 0) {
saved = get_static_data().monitor_items[obj.first];
if (obj.second) delete reinterpret_cast<const ustring*>(obj.first);
get_static_data().monitor_items.erase(obj.first);
monitor_data = &saved;
}
monitor_data->thread_id = thread::invalid_thread_id;
monitor_data->critical_section.leave();
get_static_data().monitor_items_critical_section.leave();
}

intptr monitor::get_ustring_ptr(const ustring& str) {
Expand Down

0 comments on commit 6b7f5d8

Please sign in to comment.