Skip to content

Commit

Permalink
less strict locking
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverIce committed Mar 15, 2016
1 parent c14aa07 commit 2fe9e35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
14 changes: 9 additions & 5 deletions JContainers/src/collections/dyn_form_watcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,15 @@ namespace collections {
auto itr = _watched_forms.find(formId);
if (itr != _watched_forms.end()) {

std::lock_guard<boost::detail::spinlock> guard{ spinlock_for(formId) };
auto watched = itr->second.lock();

if (watched) {
watched->set_deleted();
itr->second.reset();

{
// the only unsafe piece of code here
std::lock_guard<boost::detail::spinlock> guard{ spinlock_for(formId) };
itr->second.reset();
}
log("flagged form-entry %" PRIX32 " as deleted", formId);
}
}
Expand Down Expand Up @@ -256,12 +258,14 @@ namespace collections {
}

{
std::lock_guard<boost::detail::spinlock> guard{ spinlock_for(fId) };

auto itr = _watched_forms.find(fId);

std::lock_guard<boost::detail::spinlock> guard{ spinlock_for(fId) };

if (itr != _watched_forms.end()) {
auto watched = itr->second.lock();
if (!watched) {
if (!watched || watched->is_deleted()) {
// form-entry and real form has been deleted (recently)
// watch the form again, create entry, assuming that a new form with such ID exists

Expand Down
5 changes: 3 additions & 2 deletions JContainers/src/collections/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ namespace collections {
else if (auto val = boost::get<item::Real>(&_var)) {
return *val;
}
else if (auto val = boost::get<form_ref>(&_var)) {
// ability to read forms as integer values. likely not needed anymore
/*else if (auto val = boost::get<form_ref>(&_var)) {
return static_cast<SInt32>(val->get_raw());
}
}*/
return 0;
}

Expand Down

0 comments on commit 2fe9e35

Please sign in to comment.