diff --git a/src/laybasic/laybasic/layDitherPattern.cc b/src/laybasic/laybasic/layDitherPattern.cc index 019ef76a5..53b14d052 100644 --- a/src/laybasic/laybasic/layDitherPattern.cc +++ b/src/laybasic/laybasic/layDitherPattern.cc @@ -462,6 +462,8 @@ static const char *dither_strings [] = { // --------------------------------------------------------------------- // DitherPatternInfo implementation +static tl::Mutex s_mutex; + DitherPatternInfo::DitherPatternInfo () : m_width (1), m_height (1), m_order_index (0) { @@ -482,23 +484,31 @@ DitherPatternInfo & DitherPatternInfo::operator= (const DitherPatternInfo &d) { if (&d != this) { - - m_order_index = d.m_order_index; - m_name = d.m_name; - m_width = d.m_width; - m_pattern_stride = d.m_pattern_stride; - m_height = d.m_height; - - for (size_t i = 0; i < sizeof (m_pattern) / sizeof (m_pattern [0]); ++i) { - m_pattern [i] = &m_buffer [0] + (d.m_pattern [i] - d.m_buffer); - } - memcpy (m_buffer, d.m_buffer, sizeof (m_buffer)); + tl::MutexLocker locker (& s_mutex); + assign_no_lock (d); } return *this; } -bool +void +DitherPatternInfo::assign_no_lock (const DitherPatternInfo &d) +{ + m_scaled_pattern.reset (); + + m_order_index = d.m_order_index; + m_name = d.m_name; + m_width = d.m_width; + m_pattern_stride = d.m_pattern_stride; + m_height = d.m_height; + + for (size_t i = 0; i < sizeof (m_pattern) / sizeof (m_pattern [0]); ++i) { + m_pattern [i] = &m_buffer [0] + (d.m_pattern [i] - d.m_buffer); + } + memcpy (m_buffer, d.m_buffer, sizeof (m_buffer)); +} + +bool DitherPatternInfo::same_bitmap (const DitherPatternInfo &d) const { if (m_width != d.m_width || m_height != d.m_height) { @@ -597,15 +607,11 @@ DitherPatternInfo::get_bitmap (int width, int height, int frame_width) const #endif -static tl::Mutex s_mutex; - void DitherPatternInfo::set_pattern (const uint32_t *pt, unsigned int w, unsigned int h) { - { - tl::MutexLocker locker (& s_mutex); - m_scaled_pattern.reset (0); - } + tl::MutexLocker locker (& s_mutex); + m_scaled_pattern.reset (0); set_pattern_impl (pt, w, h); } @@ -669,10 +675,8 @@ DitherPatternInfo::set_pattern_impl (const uint32_t *pt, unsigned int w, unsigne void DitherPatternInfo::set_pattern (const uint64_t *pt, unsigned int w, unsigned int h) { - { - tl::MutexLocker locker (& s_mutex); - m_scaled_pattern.reset (0); - } + tl::MutexLocker locker (& s_mutex); + m_scaled_pattern.reset (0); set_pattern_impl (pt, w, h); } @@ -752,7 +756,7 @@ DitherPatternInfo::scaled (unsigned int n) const } DitherPatternInfo &sp = (*m_scaled_pattern) [n]; - sp = *this; + sp.assign_no_lock (*this); sp.scale_pattern (n); return sp; } diff --git a/src/laybasic/laybasic/layDitherPattern.h b/src/laybasic/laybasic/layDitherPattern.h index 258180c08..1fac7169c 100644 --- a/src/laybasic/laybasic/layDitherPattern.h +++ b/src/laybasic/laybasic/layDitherPattern.h @@ -243,6 +243,7 @@ private: void set_pattern_impl (const uint32_t *pattern, unsigned int w, unsigned int h); void set_pattern_impl (const uint64_t *pattern, unsigned int w, unsigned int h); + void assign_no_lock (const DitherPatternInfo &other); }; /** diff --git a/src/laybasic/laybasic/layLineStyles.cc b/src/laybasic/laybasic/layLineStyles.cc index df9fb3bc4..a4a3856f8 100644 --- a/src/laybasic/laybasic/layLineStyles.cc +++ b/src/laybasic/laybasic/layLineStyles.cc @@ -75,6 +75,8 @@ static const char *style_strings [] = { // --------------------------------------------------------------------- // LineStyleInfo implementation +static tl::Mutex s_mutex; + LineStyleInfo::LineStyleInfo () : m_width (0), m_order_index (0) { @@ -92,19 +94,26 @@ LineStyleInfo & LineStyleInfo::operator= (const LineStyleInfo &d) { if (&d != this) { - - m_order_index = d.m_order_index; - m_name = d.m_name; - m_width = d.m_width; - m_pattern_stride = d.m_pattern_stride; - - memcpy (m_pattern, d.m_pattern, sizeof (m_pattern)); - + tl::MutexLocker locker (& s_mutex); + assign_no_lock (d); } return *this; } -bool +void +LineStyleInfo::assign_no_lock (const LineStyleInfo &d) +{ + m_scaled_pattern.reset (0); + + m_order_index = d.m_order_index; + m_name = d.m_name; + m_width = d.m_width; + m_pattern_stride = d.m_pattern_stride; + + memcpy (m_pattern, d.m_pattern, sizeof (m_pattern)); +} + +bool LineStyleInfo::same_bits (const LineStyleInfo &d) const { if (m_width != d.m_width) { @@ -201,15 +210,11 @@ LineStyleInfo::get_bitmap (int width, int height) const } #endif -static tl::Mutex s_mutex; - void LineStyleInfo::set_pattern (uint32_t pt, unsigned int w) { - { - tl::MutexLocker locker (& s_mutex); - m_scaled_pattern.reset (0); - } + tl::MutexLocker locker (& s_mutex); + m_scaled_pattern.reset (0); memset (m_pattern, 0, sizeof (m_pattern)); @@ -271,7 +276,7 @@ LineStyleInfo::scaled (unsigned int n) const } LineStyleInfo &sp = (*m_scaled_pattern) [n]; - sp = *this; + sp.assign_no_lock (*this); sp.scale_pattern (n); return sp; } diff --git a/src/laybasic/laybasic/layLineStyles.h b/src/laybasic/laybasic/layLineStyles.h index 6f54ee981..b29dbcb6e 100644 --- a/src/laybasic/laybasic/layLineStyles.h +++ b/src/laybasic/laybasic/layLineStyles.h @@ -216,6 +216,8 @@ private: unsigned int m_order_index; std::string m_name; mutable std::unique_ptr > m_scaled_pattern; + + void assign_no_lock (const LineStyleInfo &other); }; /**