Skip to content

Commit

Permalink
[max] Add a missing mutex to protect param_locks
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Mar 22, 2022
1 parent 373e02d commit f0ab85d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 14 additions & 5 deletions src/ossia-max/src/object_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace ossia
namespace max_binding
{

ossia::safe_set<ossia::net::parameter_base*> object_base::param_locks;

object_base::object_base()
{
create_patcher_hierarchy();
Expand Down Expand Up @@ -742,13 +740,24 @@ void object_base::lock_and_touch(object_base* x, t_symbol* s)
x->m_lock = false;
}

static std::mutex param_locks_mutex;
static std::atomic_int64_t param_locks_counter{};
static ossia::small_vector<std::pair<int64_t, ossia::net::parameter_base*>, 64> param_locks;
void object_base::push_parameter_value(ossia::net::parameter_base* param, const ossia::value& val)
{
if(!param_locks.contains(param))
std::unique_lock<std::mutex> param_locks_mutex;
auto it = ossia::find_if(param_locks, [param] (auto& p) { return p.second == param; });
if(it == param_locks.end())
{
param_locks.push_back(param);
int64_t r = param_locks_counter++;
param_locks.emplace_back(r, param);
param_locks_mutex.unlock();

param->push_value(val);
param_locks.remove_all(param);

param_locks_mutex.lock();
auto rm_it = ossia::find_if(param_locks, [r] (auto& p) { return p.first == r; });
param_locks.erase(rm_it);
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/ossia-max/src/object_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ struct object_base

std::map<std::string, ossia::value> m_value_map{};

static ossia::safe_set<ossia::net::parameter_base*> param_locks;

private:
std::vector<std::shared_ptr<matcher>> find_parent_nodes();
void create_patcher_hierarchy();
Expand Down

0 comments on commit f0ab85d

Please sign in to comment.