chore: renamed ReadWrite mtx to Shared mutex
This commit is contained in:
parent
811970a306
commit
51fe41eda0
2 changed files with 36 additions and 36 deletions
|
|
@ -95,30 +95,30 @@ TerrainModifier::BlendMode TerrainModifier::get_blend_mode() const {
|
|||
|
||||
String const TerrainModifier::sig_changed{ "changed" };
|
||||
|
||||
void ReadWriteMutex::lock_read() {
|
||||
this->read_lock.lock();
|
||||
this->read_count++;
|
||||
this->read_lock.unlock();
|
||||
void SharedMutex::lock_shared() {
|
||||
this->lock.lock();
|
||||
this->shared_count++;
|
||||
this->lock.unlock();
|
||||
}
|
||||
|
||||
void ReadWriteMutex::unlock_read() {
|
||||
this->read_lock.lock();
|
||||
this->read_count--;
|
||||
this->read_lock.unlock();
|
||||
void SharedMutex::unlock_shared() {
|
||||
this->lock.lock();
|
||||
this->shared_count--;
|
||||
this->lock.unlock();
|
||||
}
|
||||
|
||||
void ReadWriteMutex::lock_write() {
|
||||
void SharedMutex::lock_exclusive() {
|
||||
while (true) {
|
||||
this->read_lock.lock();
|
||||
if (this->read_count == 0) {
|
||||
this->lock.lock();
|
||||
if (this->shared_count == 0) {
|
||||
return;
|
||||
}
|
||||
this->read_lock.unlock();
|
||||
this->lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void ReadWriteMutex::unlock_write() {
|
||||
this->read_lock.unlock();
|
||||
void SharedMutex::unlock_exclusive() {
|
||||
this->lock.unlock();
|
||||
}
|
||||
|
||||
void TerrainModifierDistance::_bind_methods() {
|
||||
|
|
@ -127,14 +127,14 @@ void TerrainModifierDistance::_bind_methods() {
|
|||
}
|
||||
|
||||
void TerrainModifierDistance::curves_changed() {
|
||||
this->lock.lock_write();
|
||||
this->lock.lock_shared();
|
||||
if (this->distance_height_curve.is_valid()) {
|
||||
this->distance_height_curve->bake();
|
||||
}
|
||||
if (this->distance_weight_curve.is_valid()) {
|
||||
this->distance_weight_curve->bake();
|
||||
}
|
||||
this->lock.unlock_write();
|
||||
this->lock.unlock_shared();
|
||||
changed();
|
||||
}
|
||||
|
||||
|
|
@ -144,14 +144,14 @@ float TerrainModifierDistance::distance_at(Vector2 const &world_coordinate) {
|
|||
}
|
||||
|
||||
float TerrainModifierDistance::evaluate_at(Vector2 world_coordinate, float before) {
|
||||
this->lock.lock_read();
|
||||
this->lock.lock_shared();
|
||||
if (this->distance_weight_curve.is_null() || this->distance_height_curve.is_null()) {
|
||||
this->lock.unlock_read();
|
||||
this->lock.unlock_shared();
|
||||
return before;
|
||||
}
|
||||
float const distance{ distance_at(world_coordinate) };
|
||||
if (distance >= this->distance_weight_curve->get_max_domain()) {
|
||||
this->lock.unlock_read();
|
||||
this->lock.unlock_shared();
|
||||
return before;
|
||||
}
|
||||
float const weight_offset{
|
||||
|
|
@ -160,16 +160,16 @@ float TerrainModifierDistance::evaluate_at(Vector2 world_coordinate, float befor
|
|||
float const height_offset{
|
||||
std::clamp(distance, this->distance_height_curve->get_min_domain(), this->distance_height_curve->get_max_domain())
|
||||
};
|
||||
this->lock.unlock_read();
|
||||
this->lock.unlock_shared();
|
||||
|
||||
this->lock.lock_write();
|
||||
this->lock.lock_exclusive();
|
||||
float const weight{ this->distance_weight_curve->sample_baked(weight_offset) };
|
||||
float const height{ this->distance_height_curve->sample_baked(height_offset) };
|
||||
this->lock.unlock_write();
|
||||
this->lock.unlock_exclusive();
|
||||
|
||||
this->lock.lock_read();
|
||||
this->lock.lock_shared();
|
||||
float out{ weight <= 0.f ? before : Math::lerp(before, blend(before, height + get_thread_safe_global_position().y), weight) };
|
||||
this->lock.unlock_read();
|
||||
this->lock.unlock_shared();
|
||||
|
||||
return out;
|
||||
}
|
||||
|
|
@ -186,7 +186,7 @@ PackedStringArray TerrainModifierDistance::get_configuration_warnings() const {
|
|||
}
|
||||
|
||||
void TerrainModifierDistance::set_distance_weight_curve(Ref<Curve> curve) {
|
||||
this->lock.lock_write();
|
||||
this->lock.lock_exclusive();
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
if (this->distance_weight_curve.is_valid()) {
|
||||
this->distance_weight_curve->disconnect_changed(callable_mp(this, &self_type::curves_changed));
|
||||
|
|
@ -196,7 +196,7 @@ void TerrainModifierDistance::set_distance_weight_curve(Ref<Curve> curve) {
|
|||
}
|
||||
}
|
||||
this->distance_weight_curve = curve;
|
||||
this->lock.unlock_write();
|
||||
this->lock.unlock_exclusive();
|
||||
curves_changed();
|
||||
update_configuration_warnings();
|
||||
}
|
||||
|
|
@ -206,7 +206,7 @@ Ref<Curve> TerrainModifierDistance::get_distance_weight_curve() const {
|
|||
}
|
||||
|
||||
void TerrainModifierDistance::set_distance_height_curve(Ref<Curve> curve) {
|
||||
this->lock.lock_write();
|
||||
this->lock.lock_exclusive();
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
if (this->distance_height_curve.is_valid()) {
|
||||
this->distance_height_curve->disconnect_changed(callable_mp(this, &self_type::curves_changed));
|
||||
|
|
@ -216,7 +216,7 @@ void TerrainModifierDistance::set_distance_height_curve(Ref<Curve> curve) {
|
|||
}
|
||||
}
|
||||
this->distance_height_curve = curve;
|
||||
this->lock.unlock_write();
|
||||
this->lock.unlock_exclusive();
|
||||
curves_changed();
|
||||
update_configuration_warnings();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,15 +41,15 @@ public:
|
|||
|
||||
MAKE_TYPE_INFO(TerrainModifier::BlendMode, Variant::INT);
|
||||
|
||||
struct ReadWriteMutex {
|
||||
void lock_read();
|
||||
void unlock_read();
|
||||
void lock_write();
|
||||
void unlock_write();
|
||||
struct SharedMutex {
|
||||
void lock_shared();
|
||||
void unlock_shared();
|
||||
void lock_exclusive();
|
||||
void unlock_exclusive();
|
||||
|
||||
private:
|
||||
Mutex read_lock{};
|
||||
int read_count{};
|
||||
Mutex lock{};
|
||||
int shared_count{};
|
||||
};
|
||||
|
||||
class TerrainModifierDistance : public TerrainModifier {
|
||||
|
|
@ -65,7 +65,7 @@ public:
|
|||
PackedStringArray get_configuration_warnings() const override;
|
||||
|
||||
private:
|
||||
ReadWriteMutex lock{};
|
||||
SharedMutex lock{};
|
||||
Ref<Curve> distance_weight_curve{};
|
||||
Ref<Curve> distance_height_curve{};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue