synchronize model and data operations which require holding the mutex, prevents racing with physics thread
| 2035 | // synchronize model and data |
| 2036 | // operations which require holding the mutex, prevents racing with physics thread |
| 2037 | void Simulate::Sync() |
| 2038 | { |
| 2039 | MutexLock lock(this->mtx); |
| 2040 | |
| 2041 | if (!m_) |
| 2042 | { |
| 2043 | return; |
| 2044 | } |
| 2045 | if (this->exitrequest.load()) |
| 2046 | { |
| 2047 | return; |
| 2048 | } |
| 2049 | |
| 2050 | bool update_profiler = this->profiler && (this->pause_update || this->run); |
| 2051 | bool update_sensor = this->sensor && (this->pause_update || this->run); |
| 2052 | |
| 2053 | for (int i = 0; i < m_->njnt; ++i) |
| 2054 | { |
| 2055 | std::optional<std::pair<mjtNum, mjtNum>> range; |
| 2056 | if (m_->jnt_limited[i]) |
| 2057 | { |
| 2058 | range.emplace(m_->jnt_range[2 * i], m_->jnt_range[2 * i + 1]); |
| 2059 | } |
| 2060 | if (jnt_range_[i] != range) |
| 2061 | { |
| 2062 | pending_.ui_update_joint = true; |
| 2063 | jnt_range_[i].swap(range); |
| 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | for (int i = 0; i < m_->nu; ++i) |
| 2068 | { |
| 2069 | std::optional<std::pair<mjtNum, mjtNum>> range; |
| 2070 | if (m_->actuator_ctrllimited[i]) |
| 2071 | { |
| 2072 | range.emplace(m_->actuator_ctrlrange[2 * i], m_->actuator_ctrlrange[2 * i + 1]); |
| 2073 | } |
| 2074 | if (actuator_ctrlrange_[i] != range) |
| 2075 | { |
| 2076 | pending_.ui_remake_ctrl = true; |
| 2077 | actuator_ctrlrange_[i].swap(range); |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | for (int i = 0; i < m_->nq; ++i) |
| 2082 | { |
| 2083 | if (qpos_[i] != qpos_prev_[i]) |
| 2084 | { |
| 2085 | d_->qpos[i] = qpos_[i]; |
| 2086 | } |
| 2087 | else |
| 2088 | { |
| 2089 | qpos_[i] = d_->qpos[i]; |
| 2090 | } |
| 2091 | if (qpos_prev_[i] != qpos_[i]) |
| 2092 | { |
| 2093 | pending_.ui_update_joint = true; |
| 2094 | qpos_prev_[i] = qpos_[i]; |
nothing calls this directly
no test coverage detected