diff --git a/ETL/ETL/CMakeLists.txt b/ETL/ETL/CMakeLists.txt index 34a962b..89d1b83 100644 --- a/ETL/ETL/CMakeLists.txt +++ b/ETL/ETL/CMakeLists.txt @@ -13,7 +13,6 @@ set(ETL_HEADERS "${CMAKE_CURRENT_LIST_DIR}/hermite" "${CMAKE_CURRENT_LIST_DIR}/fixed" "${CMAKE_CURRENT_LIST_DIR}/surface" - "${CMAKE_CURRENT_LIST_DIR}/thread" "${CMAKE_CURRENT_LIST_DIR}/clock" "${CMAKE_CURRENT_LIST_DIR}/stringf" "${CMAKE_CURRENT_LIST_DIR}/boxblur" @@ -26,25 +25,19 @@ set(ETL_HEADERS "${CMAKE_CURRENT_LIST_DIR}/angle" "${CMAKE_CURRENT_LIST_DIR}/bezier" "${CMAKE_CURRENT_LIST_DIR}/gaussian" - "${CMAKE_CURRENT_LIST_DIR}/mutex" "${CMAKE_CURRENT_LIST_DIR}/handle" # PRIVATE "${CMAKE_CURRENT_LIST_DIR}/_ref_count.h" - "${CMAKE_CURRENT_LIST_DIR}/_mutex_win32.h" "${CMAKE_CURRENT_LIST_DIR}/_trivial.h" "${CMAKE_CURRENT_LIST_DIR}/_smach.h" - "${CMAKE_CURRENT_LIST_DIR}/_rwlock.h" "${CMAKE_CURRENT_LIST_DIR}/_surface.h" "${CMAKE_CURRENT_LIST_DIR}/_smart_ptr.h" "${CMAKE_CURRENT_LIST_DIR}/_pen.h" "${CMAKE_CURRENT_LIST_DIR}/_bezier_angle.h" - "${CMAKE_CURRENT_LIST_DIR}/_thread.h" "${CMAKE_CURRENT_LIST_DIR}/_boxblur.h" "${CMAKE_CURRENT_LIST_DIR}/_rect.h" - "${CMAKE_CURRENT_LIST_DIR}/_mutex_pthreads.h" "${CMAKE_CURRENT_LIST_DIR}/_angle.h" "${CMAKE_CURRENT_LIST_DIR}/_clock_base.h" - "${CMAKE_CURRENT_LIST_DIR}/_mutex_null.h" "${CMAKE_CURRENT_LIST_DIR}/_clock_win32hpcount.h" "${CMAKE_CURRENT_LIST_DIR}/_bspline.h" "${CMAKE_CURRENT_LIST_DIR}/_clock_gettimeofday.h" @@ -55,7 +48,6 @@ set(ETL_HEADERS "${CMAKE_CURRENT_LIST_DIR}/_hermite.h" "${CMAKE_CURRENT_LIST_DIR}/_clock_system.h" "${CMAKE_CURRENT_LIST_DIR}/_fixed.h" - "${CMAKE_CURRENT_LIST_DIR}/_mutex_pthreads_simple.h" "${CMAKE_CURRENT_LIST_DIR}/_bezier.h" "${CMAKE_CURRENT_LIST_DIR}/_curve_func.h" "${CMAKE_CURRENT_LIST_DIR}/_value.h" diff --git a/ETL/ETL/Makefile.am b/ETL/ETL/Makefile.am index fa22b67..27a9eb6 100644 --- a/ETL/ETL/Makefile.am +++ b/ETL/ETL/Makefile.am @@ -20,7 +20,6 @@ etl_HEADERS = \ _ref_count.h \ angle \ handle \ - thread \ fixed \ clock \ hermite \ @@ -31,7 +30,6 @@ etl_HEADERS = \ _stringf.h \ _bspline.h \ _calculus.h \ - _mutex_null.h \ _hermite.h \ _curve_func.h \ _clock_base.h \ @@ -39,10 +37,6 @@ etl_HEADERS = \ _clock_gettimeofday.h \ _angle.h \ _handle.h \ - _thread.h \ - _mutex_pthreads.h \ - _mutex_win32.h \ - _rwlock.h \ smach \ _smach.h \ _trivial.h \ @@ -62,9 +56,7 @@ etl_HEADERS = \ _surface.h \ smart_ptr \ _smart_ptr.h \ - _clock_win32hpcount.h \ - mutex \ - _mutex_pthreads_simple.h + _clock_win32hpcount.h $(top_builddir)/ETL/etl_profile.h:$(top_builddir)/ETL/etl_profile_.h diff --git a/ETL/ETL/_mutex_null.h b/ETL/ETL/_mutex_null.h deleted file mode 100644 index 258c29e..0000000 --- a/ETL/ETL/_mutex_null.h +++ /dev/null @@ -1,71 +0,0 @@ -/*! ======================================================================== -** Extended Template and Library -** NULL Mutex Abstraction Class Implementation -** $Id$ -** -** Copyright (c) 2002 Robert B. Quattlebaum Jr. -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** -** === N O T E S =========================================================== -** -** This is an internal header file, included by other ETL headers. -** You should not attempt to use it directly. -** -** ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __ETL__MUTEX_NULL_H_ -#define __ETL__MUTEX_NULL_H_ - -/* === H E A D E R S ======================================================= */ -/* === M A C R O S ========================================================= */ - -/* === C L A S S E S & S T R U C T S ======================================= */ - -namespace etl { - -class mutex_null -{ -public: - - mutex_null(){} - ~mutex_null(){} - //! Exception-safe mutex lock class -/* - class lock - { - mutex *_mtx; - public: - lock(mutex &x):_mtx(&x) { _mtx->lock_mutex(); } - ~lock() { _mtx->unlock_mutex(); } - mutex &get() { return *_mtx; } - }; -*/ - class lock - { - public: - lock(mutex_null &/*x*/) { } - }; - - void lock_mutex(){} - bool try_lock_mutex(){return true;} - void unlock_mutex(){} -}; - -}; - -/* === E X T E R N S ======================================================= */ - -/* === E N D =============================================================== */ - -#endif diff --git a/ETL/ETL/_mutex_pthreads.h b/ETL/ETL/_mutex_pthreads.h deleted file mode 100644 index d358b2e..0000000 --- a/ETL/ETL/_mutex_pthreads.h +++ /dev/null @@ -1,116 +0,0 @@ -/*! ======================================================================== -** Extended Template and Library -** Mutex Abstraction Class Implementation -** $Id$ -** -** Copyright (c) 2002 Robert B. Quattlebaum Jr. -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** -** === N O T E S =========================================================== -** -** This is an internal header file, included by other ETL headers. -** You should not attempt to use it directly. -** -** ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __ETL__MUTEX_PTHREADS_H_ -#define __ETL__MUTEX_PTHREADS_H_ - -/* === H E A D E R S ======================================================= */ - -#define __USE_GNU - -#include - -#ifdef HAVE_SCHED_H -# include -#endif - -/* === M A C R O S ========================================================= */ - -/* === C L A S S E S & S T R U C T S ======================================= */ - -namespace etl { - -class mutex -{ - pthread_mutex_t mtx; - pthread_t locker; - int depth; -public: - - mutex() - { - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - //#ifdef PTHREAD_PRIO_INHERIT - //pthread_mutexattr_setprioceiling(&attr,PTHREAD_PRIO_INHERIT); - //#endif - #ifdef PTHREAD_MUTEX_RECURSIVE - pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE); - #endif - pthread_mutex_init(&mtx,&attr); - pthread_mutexattr_destroy(&attr); - locker=0; - depth=0; - } - - ~mutex() - { pthread_mutex_destroy(&mtx); } - - - //! Exception-safe mutex lock class - class lock - { - mutex *_mtx; - public: - lock(mutex &x):_mtx(&x) { _mtx->lock_mutex(); } - ~lock() { _mtx->unlock_mutex(); } - mutex &get() { return *_mtx; } - }; - - void lock_mutex(void) - { - if(!locker || locker!=pthread_self()) - { - pthread_mutex_lock(&mtx); - locker=pthread_self(); - depth=0; - return; - } - depth++; - } - - bool try_lock_mutex(void) - { return !(bool) pthread_mutex_trylock(&mtx); } - - void unlock_mutex(void) - { - if(depth) - { - depth--; - return; - } - pthread_mutex_unlock(&mtx); - locker=0; - } -}; - -}; - -/* === E X T E R N S ======================================================= */ - -/* === E N D =============================================================== */ - -#endif diff --git a/ETL/ETL/_mutex_pthreads_simple.h b/ETL/ETL/_mutex_pthreads_simple.h deleted file mode 100644 index 18b0a98..0000000 --- a/ETL/ETL/_mutex_pthreads_simple.h +++ /dev/null @@ -1,64 +0,0 @@ -/*! ======================================================================== -** Extended Template and Library -** Mutex Abstraction Class Implementation -** $Id$ -** -** Copyright (c) 2002 Robert B. Quattlebaum Jr. -** Copyright (c) 2008 Chris Moore -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** -** === N O T E S =========================================================== -** -** This is an internal header file, included by other ETL headers. -** You should not attempt to use it directly. -** -** ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __ETL__MUTEX_PTHREADS_SIMPLE_H_ -#define __ETL__MUTEX_PTHREADS_SIMPLE_H_ - -/* === H E A D E R S ======================================================= */ - -#include - -/* === M A C R O S ========================================================= */ - -/* === C L A S S E S & S T R U C T S ======================================= */ - -namespace etl { - -class mutex -{ - pthread_mutex_t mtx; -public: - mutex() { pthread_mutex_init(&mtx,NULL); } - ~mutex() { pthread_mutex_destroy(&mtx); } - void lock_mutex() { pthread_mutex_lock(&mtx); } - void unlock_mutex() { pthread_mutex_unlock(&mtx); } - - //! Exception-safe mutex lock class - class lock - { - mutex *_mtx; - public: - lock(mutex &x):_mtx(&x) { _mtx->lock_mutex(); } - ~lock() { _mtx->unlock_mutex(); } - }; -}; - -}; - -/* === E N D =============================================================== */ - -#endif diff --git a/ETL/ETL/_mutex_win32.h b/ETL/ETL/_mutex_win32.h deleted file mode 100644 index 5b8e885..0000000 --- a/ETL/ETL/_mutex_win32.h +++ /dev/null @@ -1,82 +0,0 @@ -/*! ======================================================================== -** Extended Template and Library -** Mutex Abstraction Class Implementation -** $Id$ -** -** Copyright (c) 2002 Robert B. Quattlebaum Jr. -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** -** === N O T E S =========================================================== -** -** This is an internal header file, included by other ETL headers. -** You should not attempt to use it directly. -** -** ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __ETL__MUTEX_WIN32_H_ -#define __ETL__MUTEX_WIN32_H_ - -/* === H E A D E R S ======================================================= */ - -#include -// extern HANDLE CreateMutex(NULL, FALSE, NULL); -// extern CloseHandle(handle); -// extern WaitForSingleObject(handle, INFINITE); -// extern ReleaseMutex(handle); - -/* === M A C R O S ========================================================= */ - - -/* === C L A S S E S & S T R U C T S ======================================= */ - -namespace etl { - -class mutex -{ - HANDLE handle; -public: - - mutex() - { handle = CreateMutex(NULL, FALSE, NULL); } - - ~mutex() - { CloseHandle(handle); } - - //! Exception-safe mutex lock class - class lock - { - mutex *_mtx; - public: - lock(mutex &x):_mtx(&x) { _mtx->lock_mutex(); } - ~lock() { _mtx->unlock_mutex(); } - mutex &get() { return *_mtx; } - }; - - void lock_mutex(void) - { WaitForSingleObject(handle, INFINITE); } - - bool try_lock_mutex(void) - { return WaitForSingleObject(handle, INFINITE)==WAIT_FAILED; } - - void unlock_mutex(void) - { ReleaseMutex(handle); } -}; - -}; - -/* === E X T E R N S ======================================================= */ - -/* === E N D =============================================================== */ - -#endif diff --git a/ETL/ETL/_rwlock.h b/ETL/ETL/_rwlock.h deleted file mode 100644 index cd6a89a..0000000 --- a/ETL/ETL/_rwlock.h +++ /dev/null @@ -1,93 +0,0 @@ -/*! ======================================================================== -** Extended Template and Library -** Mutex Abstraction Class Implementation -** $Id$ -** -** Copyright (c) 2002 Robert B. Quattlebaum Jr. -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** -** === N O T E S =========================================================== -** -** This is an internal header file, included by other ETL headers. -** You should not attempt to use it directly. -** -** ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __ETL__RWLOCK_H_ -#define __ETL__RWLOCK_H_ - -/* === H E A D E R S ======================================================= */ - -/* === M A C R O S ========================================================= */ - -/* === C L A S S E S & S T R U C T S ======================================= */ - -namespace etl { - -class read_write_lock : private Mutex -{ -public: - - read_write_lock() - { } - - ~read_write_lock() - { } - - //! Exception-safe read-lock class - class read_lock - { - read_write_lock *_mtx; - public: - read_lock(read_write_lock &x):_mtx(&x) { _mtx->lock_read(); } - ~read_lock() { _mtx->unlock_read(); } - read_write_lock &get() { return *_mtx; } - }; - - //! Exception-safe write-lock class - class write_lock - { - read_write_lock *_mtx; - public: - write_lock(read_write_lock &x):_mtx(&x) { _mtx->lock_write(); } - ~read_lock() { _mtx->unlock_write(); } - read_write_lock &get() { return *_mtx; } - }; - - void lock_read(void) - { lock_mutex(); } - - void lock_write(void) - { lock_mutex(); } - - bool try_lock_read(void) - { return try_lock_mutex(); } - - bool try_lock_write(void) - { return try_lock_mutex(); } - - void unlock_write(void) - { unlock_mutex(); } - - void unlock_read(void) - { unlock_mutex(); } -}; - -}; - -/* === E X T E R N S ======================================================= */ - -/* === E N D =============================================================== */ - -#endif diff --git a/ETL/ETL/_smach.h b/ETL/ETL/_smach.h index 60ea109..e1e1af9 100644 --- a/ETL/ETL/_smach.h +++ b/ETL/ETL/_smach.h @@ -30,7 +30,6 @@ #include #include #include -#include "_mutex_null.h" #include "_misc.h" /* === M A C R O S ========================================================= */ @@ -42,9 +41,6 @@ #pragma warning (disable:4290) // MSVC6 doesn't like function declarations with exception specs #endif -//#define ETL_MUTEX_LOCK() _mutex::lock lock(mutex) -#define ETL_MUTEX_LOCK() - /* === T Y P E D E F S ===================================================== */ /* === C L A S S E S & S T R U C T S ======================================= */ @@ -57,13 +53,12 @@ namespace etl { ** ** A more detailed description needs to be written. */ -template +template class smach { public: typedef K event_key; - typedef M _mutex; typedef CON context_type; @@ -283,10 +278,6 @@ private: const state_base* default_state; void* default_context; -#ifdef ETL_MUTEX_LOCK - _mutex mutex; -#endif - //! State stack data const state_base* state_stack[SMACH_STATE_STACK_SIZE]; void* state_context_stack[SMACH_STATE_STACK_SIZE]; @@ -298,9 +289,6 @@ public: const char * get_state_name()const { -#ifdef ETL_MUTEX_LOCK - ETL_MUTEX_LOCK(); -#endif if(curr_state) return curr_state->get_name(); if(default_state) @@ -318,9 +306,6 @@ public: bool set_default_state(const state_base *nextstate) { -#ifdef ETL_MUTEX_LOCK - ETL_MUTEX_LOCK(); -#endif // Keep track of the current state unless // the state switch fails const state_base *prev_state=default_state; @@ -363,10 +348,6 @@ public: bool egress() { -#ifdef ETL_MUTEX_LOCK - ETL_MUTEX_LOCK(); -#endif - // Pop all states off the state stack while(states_on_stack) pop_state(); @@ -395,10 +376,6 @@ public: bool enter(const state_base *nextstate) { -#ifdef ETL_MUTEX_LOCK - ETL_MUTEX_LOCK(); -#endif - // Keep track of the current state unless // the state switch fails const state_base *prev_state=curr_state; @@ -440,10 +417,6 @@ public: bool push_state(const state_base *nextstate) { -#ifdef ETL_MUTEX_LOCK - ETL_MUTEX_LOCK(); -#endif - // If there are not enough slots, then throw something. if(states_on_stack==SMACH_STATE_STACK_SIZE) throw(std::overflow_error("smach<>::push_state(): state stack overflow!")); @@ -476,10 +449,6 @@ public: void pop_state() { -#ifdef ETL_MUTEX_LOCK - ETL_MUTEX_LOCK(); -#endif - // If we aren't in a state, then there is nothing // to do. if(!curr_state) @@ -530,9 +499,6 @@ public: object has its own state machine. */ void set_child(smach *x) { -#ifdef ETL_MUTEX_LOCK - ETL_MUTEX_LOCK(); -#endif child=x; } @@ -548,10 +514,6 @@ public: event_result process_event(const event& id) { -#ifdef ETL_MUTEX_LOCK - ETL_MUTEX_LOCK(); -#endif - event_result ret(RESULT_OK); // Check for child machine diff --git a/ETL/ETL/_thread.h b/ETL/ETL/_thread.h deleted file mode 100644 index 8f70be8..0000000 --- a/ETL/ETL/_thread.h +++ /dev/null @@ -1,515 +0,0 @@ -/*! ======================================================================== -** Extended Template and Library -** Thread Abstraction Class Implementation -** $Id$ -** -** Copyright (c) 2002 Robert B. Quattlebaum Jr. -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** -** === N O T E S =========================================================== -** -** This is an internal header file, included by other ETL headers. -** You should not attempt to use it directly. -** -** ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __ETL__THREAD_H_ -#define __ETL__THREAD_H_ - -/* === H E A D E R S ======================================================= */ - -#define __USE_GNU - -#ifdef HAVE_PTHREAD_H -# include -#endif - -#ifdef HAVE_SCHED_H -# include -#endif - -#ifdef HAVE_CREATETHREAD -# include -#endif - -/* === M A C R O S ========================================================= */ - -#if ( defined (HAVE_PTHREAD_CREATE) || defined (HAVE_CLONE) || defined (HAVE_CREATETHREAD) ) && !defined (NO_THREADS) -# define CALLISTO_THREADS -#endif - -#define THREAD_ENTRYPOINT - -/* === C L A S S E S & S T R U C T S ======================================= */ - -#if defined(CALLISTO_THREADS) && defined(HAVE_PTHREAD_CREATE) -static inline void Yield(void) -{ - sched_yield(); - pthread_testcancel(); -} -#else -#ifdef Yield - #undef Yield -#endif -inline void Yield(void) { } -#endif - -#ifdef CALLISTO_THREADS - -#ifdef HAVE_PTHREAD_CREATE - -class Thread -{ -public: - typedef void* entrypoint_return; -private: - - pthread_t thread; - int *references; - entrypoint_return (*entrypoint)(void *); - void *context; -public: - Thread(void *(*ep)(void *)=NULL,void *context=NULL): - references(NULL),entrypoint(ep),context(context) { } - Thread(const Thread &t) - { - thread=t.thread; - references=t.references; - entrypoint=t.entrypoint; - context=t.context; - if(references) - (*references)++; - } - const Thread &operator=(const Thread &rhs) - { - if(references) - { - (*references)--; - if(*references==0) - stop(); - } - thread=rhs.thread; - references=rhs.references; - entrypoint=rhs.entrypoint; - context=rhs.context; - if(references) - (*references)++; - return *this; - } - - void start(void) - { - references = new int; - *references = 1; - pthread_create(&thread,NULL,entrypoint,context); -// pthread_detach(thread); - } - - void stop(void) - { - delete references; - references=NULL; - void *exit_status; - pthread_cancel(thread); - pthread_join(thread,&exit_status); - } - - static void TestStop() - { - pthread_testcancel(); - } - - static void SyncStop() - { - int i; - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,&i); - } - - static void AsyncStop() - { - int i; - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,&i); - } - - ~Thread() - { - if(references) - { - (*references)--; - if(*references==0) - stop(); - } - } -}; - -class Mutex -{ - pthread_mutex_t mutex; - pthread_t locker; - int depth; -public: - - Mutex() - { - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - //#ifdef PTHREAD_PRIO_INHERIT - //pthread_mutexattr_setprioceiling(&attr,PTHREAD_PRIO_INHERIT); - //#endif - #ifdef PTHREAD_MUTEX_RECURSIVE - pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE); - #endif - pthread_mutex_init(&mutex,&attr); - pthread_mutexattr_destroy(&attr); - locker=0; - depth=0; - } - - ~Mutex() - { pthread_mutex_destroy(&mutex); } - - void Lock(void) - { - if(!locker || locker!=pthread_self()) - { - pthread_mutex_lock(&mutex); - locker=pthread_self(); - depth=0; - return; - } - depth++; - } - - bool TryLock(void) - { return !(bool) pthread_mutex_trylock(&mutex); } - - void UnLock(void) - { - if(depth) - { - depth--; - return; - } - pthread_mutex_unlock(&mutex); - locker=0; - } -}; - -#ifdef HAVE_PTHREAD_RW_LOCK_INIT -class ReadWriteLock -{ - pthread_rwlock_t rwlock; -public: - - ReadWriteLock() - { pthread_rwlock_init(&rwlock,NULL); } - - ~ReadWriteLock() - { pthread_rwlock_destroy(&rwlock); } - - void LockRead(void) - { pthread_rwlock_rdlock(&rwlock); } - - void LockWrite(void) - { pthread_rwlock_wrlock(&rwlock); } - - bool TryLockRead(void) - { return !(bool)pthread_rwlock_tryrdlock(&rwlock); } - - bool TryLockWrite(void) - { return !(bool)pthread_rwlock_trywrlock(&rwlock); } - - void UnLockWrite(void) - { pthread_rwlock_unlock(&rwlock); } - - void UnLockRead(void) - { pthread_rwlock_unlock(&rwlock); } -}; -#else -//* -class ReadWriteLock : public Mutex -{ -public: - - ReadWriteLock() - { } - - ~ReadWriteLock() - { } - - void LockRead(void) - { Lock(); } - - void LockWrite(void) - { Lock(); } - - bool TryLockRead(void) - { return TryLock(); } - - bool TryLockWrite(void) - { return TryLock(); } - - void UnLockWrite(void) - { UnLock(); } - - void UnLockRead(void) - { UnLock(); } -}; -#endif - -/* -class Condition -{ - pthread_cond_t cond; - pthread_mutex_t mutex; -public: - Condition() - { pthread_cond_init(&cond,NULL); pthread_mutex_init(&mutex,NULL); } - ~Condition() - { pthread_cond_destroy(&cond); pthread_mutex_destroy(&mutex);} - void operator()(void) - { pthread_cond_signal(&cond); } - void Wait(void) - { - pthread_mutex_lock(&mutex); - pthread_cond_wait(&cond,&mutex); - pthread_mutex_unlock(&mutex); - } -}; -*/ - -#else // if defined HAVE_PTHREAD -#ifdef HAVE_CREATETHREAD - - -#ifdef THREAD_ENTRYPOINT -#undef THREAD_ENTRYPOINT -#endif -#define THREAD_ENTRYPOINT __stdcall -class Thread -{ -public: - typedef unsigned long entrypoint_return; -private: - - unsigned long thread; - HANDLE handle; - int *references; - - entrypoint_return (THREAD_ENTRYPOINT *entrypoint)(void *); - - void *context; - - HDC hdc; - HGLRC hglrc; - - static entrypoint_return THREAD_ENTRYPOINT thread_prefix(void*data) - { - Thread *thread=(Thread *)data; - - if(thread->hglrc) - wglMakeCurrent(thread->hdc, thread->hglrc); - - return thread->entrypoint(thread->context); - } - -public: - Thread(entrypoint_return (THREAD_ENTRYPOINT *ep)(void *)=NULL,void *context=NULL): - references(NULL),entrypoint(ep),context(context) { } - Thread(const Thread &t) - { - thread=t.thread; - handle=t.handle; - references=t.references; - entrypoint=t.entrypoint; - context=t.context; - handle=NULL; - if(references) - (*references)++; - } - const Thread &operator=(const Thread &rhs) - { - if(references) - { - (*references)--; - if(*references==0) - stop(); - } - thread=rhs.thread; - handle=rhs.handle; - references=rhs.references; - entrypoint=rhs.entrypoint; - context=rhs.context; - if(references) - (*references)++; - return *this; - } - - void start(void) - { - references = new int; - *references = 1; - - hglrc=wglGetCurrentContext(); - hdc=wglGetCurrentDC(); - - handle=CreateThread( - NULL, // Security stuff - 0, // STACK - thread_prefix, // thread function - (void*)this, // thread argument - 0, // creation option - &thread // thread identifier - ); - } - - void stop(void) - { - delete references; - references=NULL; - - TerminateThread(handle, FALSE); - } - - int wait(void) - { - if(handle) - { - WaitForSingleObject(handle, INFINITE); - CloseHandle(handle); - } - return 0; - } - - static void TestStop() - { - } - - static void SyncStop() - { - } - - static void AsyncStop() - { - } - - ~Thread() - { - if(references) - { - (*references)--; - if(*references==0) - stop(); - } - } -}; - -class Mutex -{ - HANDLE handle; -public: - - Mutex() - { - handle = CreateMutex(NULL, FALSE, NULL); - } - - ~Mutex() - { - CloseHandle(handle); - } - - void Lock(void) - { - WaitForSingleObject(handle, INFINITE); - } - - bool TryLock(void) - { - return WaitForSingleObject(handle, INFINITE)==WAIT_FAILED; - } - - void UnLock(void) - { - ReleaseMutex(handle); - } -}; - - -#endif // if defined HAVE_CREATETHREAD -#endif // if defined HAVE_PTHREAD_CREATE -#endif // if defined CALLISTO_THREADS - - -#if !defined(CALLISTO_THREADS) -// Dummy object used when not threading -class ReadWriteLock -{ -public: - - ReadWriteLock() {} - ~ReadWriteLock() {} - void LockRead(void) {} - void LockWrite(void) {} - bool TryLockRead(void) {return true;} - bool TryLockWrite(void) {return true;} - void UnLockRead(void) {} - void UnLockWrite(void) {} -}; - -class Mutex -{ -public: - - Mutex(){} - ~Mutex(){} - void Lock(void){} - bool TryLock(void){return true;} - void UnLock(void){} -}; - -#endif - -class Condition : private Mutex -{ - bool flag; -public: - Condition() - { flag=false; } - ~Condition() - { } - void operator()(void) - { flag=true; } - void Wait(void) - { - Lock(); - while(!flag)Yield(); - flag=false; - UnLock(); - } - void WaitNext(void) - { - Lock(); - flag=false; - while(!flag)Yield(); - UnLock(); - } -}; - -/* === E X T E R N S ======================================================= */ - -/* === E N D =============================================================== */ - -#endif diff --git a/ETL/ETL/mutex b/ETL/ETL/mutex deleted file mode 100644 index f4d1263..0000000 --- a/ETL/ETL/mutex +++ /dev/null @@ -1,42 +0,0 @@ -// -*- C++ -*- -/*! ======================================================================== -** Extended Template and Library -** Mutex Classes -** $Id$ -** -** Copyright (c) 2008 Chris Moore -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** -** === N O T E S =========================================================== -** -** ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __ETL__MUTEX__ -#define __ETL__MUTEX__ - -/* === H E A D E R S ======================================================= */ - -#include "etl_config.h" - -#ifdef HAVE_LIBPTHREAD -# include "_mutex_pthreads_simple.h" -#else -#ifdef _WIN32 -# include "_mutex_win32.h" -#endif -#endif - -/* === E N D =============================================================== */ - -#endif diff --git a/ETL/ETL/thread b/ETL/ETL/thread deleted file mode 100644 index 500f496..0000000 --- a/ETL/ETL/thread +++ /dev/null @@ -1,36 +0,0 @@ -// -*- C++ -*- -/*! ======================================================================== -** Extended Template and Library -** Thread Abstraction Class -** $Id$ -** -** Copyright (c) 2002 Robert B. Quattlebaum Jr. -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** -** === N O T E S =========================================================== -** -** ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __ETL__THREAD__ -#define __ETL__THREAD__ - -/* === H E A D E R S ======================================================= */ - -#include "etl_config.h" - -#include "_thread.h" - -/* === E N D =============================================================== */ - -#endif diff --git a/ETL/m4/ETL.m4 b/ETL/m4/ETL.m4 index 66b22a6..f7f61b7 100644 --- a/ETL/m4/ETL.m4 +++ b/ETL/m4/ETL.m4 @@ -8,21 +8,10 @@ AC_DEFUN([ETL_DEPS], [ AC_CHECK_LIB(user32, main) - AC_CHECK_LIB([kernel32], [CreateMutex]) - AC_CHECK_LIB([pthread], [pthread_mutex_init]) - # This macro is obsolescent, as current systems have conforming header files. New programs need not use this macro. - #AC_HEADER_STDC - - AC_CHECK_HEADERS(pthread.h) - AC_CHECK_HEADERS(sched.h) AC_CHECK_HEADERS(sys/time.h) AC_CHECK_HEADERS(unistd.h) AC_CHECK_HEADERS(windows.h) - AC_CHECK_FUNCS([pthread_create]) - AC_CHECK_FUNCS([pthread_rwlock_init]) - AC_CHECK_FUNCS([sched_yield]) - AC_CHECK_FUNCS([CreateThread]) AC_CHECK_FUNCS([QueryPerformanceCounter]) AC_CHECK_FUNCS([gettimeofday]) diff --git a/synfig-core/m4/ETL.m4 b/synfig-core/m4/ETL.m4 index b1aaa8f..06355d9 100644 --- a/synfig-core/m4/ETL.m4 +++ b/synfig-core/m4/ETL.m4 @@ -10,22 +10,11 @@ AC_DEFUN([ETL_DEPS], AC_C_BIGENDIAN AC_CHECK_LIB(user32, main) - AC_CHECK_LIB([kernel32], [CreateMutex]) - AC_CHECK_LIB([pthread], [pthread_mutex_init]) - - AC_HEADER_STDC - AC_CHECK_HEADERS(pthread.h) - AC_CHECK_HEADERS(sched.h) AC_CHECK_HEADERS(sys/times.h) AC_CHECK_HEADERS(sys/time.h) AC_CHECK_HEADERS(unistd.h) AC_CHECK_HEADERS(windows.h) - AC_CHECK_FUNCS([pthread_create]) - AC_CHECK_FUNCS([pthread_rwlock_init]) - AC_CHECK_FUNCS([pthread_yield]) - AC_CHECK_FUNCS([sched_yield]) - AC_CHECK_FUNCS([CreateThread]) AC_CHECK_FUNCS([__clone]) AC_CHECK_FUNCS([QueryPerformanceCounter]) diff --git a/synfig-core/src/modules/lyr_freetype/lyr_freetype.cpp b/synfig-core/src/modules/lyr_freetype/lyr_freetype.cpp index 1893f0b..49eee8b 100644 --- a/synfig-core/src/modules/lyr_freetype/lyr_freetype.cpp +++ b/synfig-core/src/modules/lyr_freetype/lyr_freetype.cpp @@ -481,7 +481,7 @@ Layer_Freetype::new_face(const String &newfont) bool Layer_Freetype::set_param(const String & param, const ValueBase &value) { - Mutex::Lock lock(mutex); + std::lock_guard lock(mutex_); /* if(param=="font" && value.same_type_as(font)) { @@ -715,7 +715,7 @@ Layer_Freetype::accelerated_render(Context context,Surface *surface,int quality, synfig::Point origin=param_origin.get(Point()); synfig::Vector orient=param_orient.get(Vector()); - static synfig::RecMutex freetype_mutex; + static std::recursive_mutex freetype_mutex; if(needs_sync_) const_cast(this)->sync(); @@ -762,7 +762,7 @@ Layer_Freetype::accelerated_render(Context context,Surface *surface,int quality, return true; } - synfig::RecMutex::Lock lock(freetype_mutex); + std::lock_guard lock(freetype_mutex); #define CHAR_RESOLUTION (64) error = FT_Set_Char_Size( diff --git a/synfig-core/src/modules/lyr_freetype/lyr_freetype.h b/synfig-core/src/modules/lyr_freetype/lyr_freetype.h index 9b94688..bc9e4c3 100644 --- a/synfig-core/src/modules/lyr_freetype/lyr_freetype.h +++ b/synfig-core/src/modules/lyr_freetype/lyr_freetype.h @@ -150,7 +150,7 @@ private: synfig::Color color_func(const synfig::Point &x, int quality=10, synfig::ColorReal supersample=0)const; - mutable synfig::Mutex mutex; + mutable std::mutex mutex_; public: Layer_Freetype(); diff --git a/synfig-core/src/modules/mod_particle/plant.cpp b/synfig-core/src/modules/mod_particle/plant.cpp index d8066c4..7221d48 100644 --- a/synfig-core/src/modules/mod_particle/plant.cpp +++ b/synfig-core/src/modules/mod_particle/plant.cpp @@ -223,7 +223,7 @@ Plant::sync()const int splits=param_splits.get(int()); bool use_width=param_use_width.get(bool()); - Mutex::Lock lock(mutex); + std::lock_guard lock(mutex_); if (!needs_sync_) return; time_t start_time; time(&start_time); particle_list.clear(); diff --git a/synfig-core/src/modules/mod_particle/plant.h b/synfig-core/src/modules/mod_particle/plant.h index ce4af45..08db880 100644 --- a/synfig-core/src/modules/mod_particle/plant.h +++ b/synfig-core/src/modules/mod_particle/plant.h @@ -104,7 +104,7 @@ private: Real mass; mutable bool needs_sync_; - mutable Mutex mutex; + mutable mutex mutex_; void branch(int n, int depth,float t, float stunt_growth, Point position,Vector velocity)const; void sync()const; diff --git a/synfig-core/src/synfig/CMakeLists.txt b/synfig-core/src/synfig/CMakeLists.txt index 17b05c9..2f78786 100644 --- a/synfig-core/src/synfig/CMakeLists.txt +++ b/synfig-core/src/synfig/CMakeLists.txt @@ -43,7 +43,6 @@ target_sources(synfig "${CMAKE_CURRENT_LIST_DIR}/loadcanvas.cpp" "${CMAKE_CURRENT_LIST_DIR}/main.cpp" "${CMAKE_CURRENT_LIST_DIR}/module.cpp" - "${CMAKE_CURRENT_LIST_DIR}/mutex.cpp" "${CMAKE_CURRENT_LIST_DIR}/node.cpp" "${CMAKE_CURRENT_LIST_DIR}/palette.cpp" "${CMAKE_CURRENT_LIST_DIR}/paramdesc.cpp" diff --git a/synfig-core/src/synfig/Makefile.am b/synfig-core/src/synfig/Makefile.am index 74298a6..2f1aa77 100644 --- a/synfig-core/src/synfig/Makefile.am +++ b/synfig-core/src/synfig/Makefile.am @@ -108,7 +108,6 @@ SYNFIGHEADERS = \ loadcanvas.h \ main.h \ module.h \ - mutex.h \ node.h \ palette.h \ paramdesc.h \ @@ -163,7 +162,6 @@ SYNFIGSOURCES = \ loadcanvas.cpp \ main.cpp \ module.cpp \ - mutex.cpp \ node.cpp \ palette.cpp \ paramdesc.cpp \ diff --git a/synfig-core/src/synfig/context.cpp b/synfig-core/src/synfig/context.cpp index 697c618..027a02e 100644 --- a/synfig-core/src/synfig/context.cpp +++ b/synfig-core/src/synfig/context.cpp @@ -107,7 +107,7 @@ IndependentContext::set_time(Time time, bool force)const Layer::Handle layer(*context); ++context; - RWLock::WriterLock lock(layer->get_rw_lock()); + Glib::Threads::RWLock::WriterLock lock(layer->get_rw_lock()); layer->set_time(context, time); } @@ -125,7 +125,7 @@ IndependentContext::load_resources(Time time, bool /*force*/)const Layer::Handle layer(*context); ++context; - //RWLock::WriterLock lock(layer->get_rw_lock()); + //Glib::Threads::RWLock::WriterLock lock(layer->get_rw_lock()); layer->load_resources(context, time); } @@ -146,7 +146,7 @@ IndependentContext::set_outline_grow(Real outline_grow)const Layer::Handle layer(*context); ++context; - RWLock::WriterLock lock(layer->get_rw_lock()); + Glib::Threads::RWLock::WriterLock lock(layer->get_rw_lock()); layer->set_outline_grow(context, outline_grow); } @@ -171,7 +171,7 @@ Context::get_color(const Point &pos)const // If this layer isn't defined, return alpha if((context)->empty()) return Color::alpha(); - RWLock::ReaderLock lock((*context)->get_rw_lock()); + Glib::Threads::RWLock::ReaderLock lock((*context)->get_rw_lock()); return (*context)->get_color(context.get_next(), pos); } @@ -197,7 +197,7 @@ Context::get_cairocolor(const Point &pos)const // If this layer isn't defined, return alpha if((context)->empty()) return CairoColor::alpha(); - RWLock::ReaderLock lock((*context)->get_rw_lock()); + Glib::Threads::RWLock::ReaderLock lock((*context)->get_rw_lock()); return (*context)->get_cairocolor(context.get_next(), pos); } @@ -364,7 +364,7 @@ Context::accelerated_render(Surface *surface,int quality, const RendDesc &rendde try { // lock the context for reading - RWLock::ReaderLock lock((*context)->get_rw_lock()); + Glib::Threads::RWLock::ReaderLock lock((*context)->get_rw_lock()); #ifdef SYNFIG_PROFILE_LAYERS //go down one layer :P depth++; @@ -466,7 +466,7 @@ Context::accelerated_cairorender(cairo_t *cr,int quality, const RendDesc &rendde try { // lock the context for reading - RWLock::ReaderLock lock((*context)->get_rw_lock()); + Glib::Threads::RWLock::ReaderLock lock((*context)->get_rw_lock()); #ifdef SYNFIG_PROFILE_LAYERS //go down one layer :P depth++; diff --git a/synfig-core/src/synfig/debug/log.cpp b/synfig-core/src/synfig/debug/log.cpp index a24c380..33cde88 100644 --- a/synfig-core/src/synfig/debug/log.cpp +++ b/synfig-core/src/synfig/debug/log.cpp @@ -53,11 +53,11 @@ using namespace debug; /* === M E T H O D S ======================================================= */ -Mutex Log::mutex; +std::mutex Log::mutex_; void Log::append_line_to_file(const String &logfile, const String &str) { - Mutex::Lock lock(mutex); + std::lock_guard lock(mutex_); std::ofstream f(logfile.c_str(), std::ios_base::app); f << str << std::endl; } diff --git a/synfig-core/src/synfig/debug/log.h b/synfig-core/src/synfig/debug/log.h index 1415d3e..272172b 100644 --- a/synfig-core/src/synfig/debug/log.h +++ b/synfig-core/src/synfig/debug/log.h @@ -28,8 +28,8 @@ /* === H E A D E R S ======================================================= */ #include -#include #include +#include /* === M A C R O S ========================================================= */ @@ -44,7 +44,7 @@ namespace debug { class Log { private: - static Mutex mutex; + static std::mutex mutex_; public: diff --git a/synfig-core/src/synfig/layers/layer_bitmap.cpp b/synfig-core/src/synfig/layers/layer_bitmap.cpp index e90f46b..d8b0fae 100644 --- a/synfig-core/src/synfig/layers/layer_bitmap.cpp +++ b/synfig-core/src/synfig/layers/layer_bitmap.cpp @@ -257,7 +257,7 @@ synfig::Layer_Bitmap::get_color(Context context, const Point &pos)const surface_pos[1]/=br[1]-tl[1]; if(surface_pos[1]<=1.0 && surface_pos[1]>=0.0) { - Mutex::Lock lock(mutex); + std::lock_guard lock(mutex_); if (trimmed) { @@ -364,7 +364,7 @@ Layer_Bitmap::accelerated_render(Context context,Surface *surface,int quality, c { RENDER_TRANSFORMED_IF_NEED(__FILE__, __LINE__) - Mutex::Lock lock(mutex); + std::lock_guard lock(mutex_); Point tl(param_tl.get(Point())); Point br(param_br.get(Point())); diff --git a/synfig-core/src/synfig/layers/layer_bitmap.h b/synfig-core/src/synfig/layers/layer_bitmap.h index 6e78820..ff98b7a 100644 --- a/synfig-core/src/synfig/layers/layer_bitmap.h +++ b/synfig-core/src/synfig/layers/layer_bitmap.h @@ -60,7 +60,7 @@ public: ValueBase param_c; ValueBase param_gamma_adjust; - mutable synfig::Mutex mutex; + mutable std::mutex mutex_; mutable rendering::software::PackedSurface::Reader reader; mutable rendering::SurfaceResource::Handle rendering_surface; mutable bool trimmed; diff --git a/synfig-core/src/synfig/layers/layer_duplicate.cpp b/synfig-core/src/synfig/layers/layer_duplicate.cpp index 08786c5..251f8a2 100644 --- a/synfig-core/src/synfig/layers/layer_duplicate.cpp +++ b/synfig-core/src/synfig/layers/layer_duplicate.cpp @@ -121,7 +121,7 @@ Layer_Duplicate::get_color(Context context, const Point &pos)const float amount(get_amount()); Color color; - Mutex::Lock lock(mutex); + std::lock_guard lock(mutex_); Time time_cur = get_time_mark(); duplicate_param->reset_index(time_cur); do @@ -187,7 +187,7 @@ Layer_Duplicate::accelerated_render(Context context,Surface *surface,int quality Time time_cur = get_time_mark(); int steps = duplicate_param->count_steps(time_cur); - Mutex::Lock lock(mutex); + std::lock_guard lock(mutex_); duplicate_param->reset_index(time_cur); do { @@ -233,7 +233,7 @@ Layer_Duplicate::accelerated_cairorender(Context context, cairo_t *cr, int quali Time time_cur = get_time_mark(); int steps = duplicate_param->count_steps(time_cur); - Mutex::Lock lock(mutex); + std::lock_guard lock(mutex_); duplicate_param->reset_index(time_cur); cairo_save(cr); do @@ -269,7 +269,7 @@ Layer_Duplicate::build_rendering_task_vfunc(Context context) const rendering::Task::Handle task; - Mutex::Lock lock(mutex); + std::lock_guard lock(mutex_); duplicate_param->reset_index(time_cur); do { diff --git a/synfig-core/src/synfig/layers/layer_duplicate.h b/synfig-core/src/synfig/layers/layer_duplicate.h index b2d0944..15caeff 100644 --- a/synfig-core/src/synfig/layers/layer_duplicate.h +++ b/synfig-core/src/synfig/layers/layer_duplicate.h @@ -42,7 +42,7 @@ class Layer_Duplicate : public synfig::Layer_CompositeFork private: mutable ValueBase param_index; - mutable synfig::Mutex mutex; + mutable std::mutex mutex_; public: diff --git a/synfig-core/src/synfig/main.cpp b/synfig-core/src/synfig/main.cpp index e33a2e9..0cef8ec 100644 --- a/synfig-core/src/synfig/main.cpp +++ b/synfig-core/src/synfig/main.cpp @@ -74,8 +74,6 @@ #include "guid.h" -#include "mutex.h" - #include #ifdef HAVE_SIGNAL_H @@ -103,13 +101,13 @@ Main *Main::instance = NULL; class GeneralIOMutexHolder { private: - Mutex mutex; + mutex mutex_; bool initialized; public: GeneralIOMutexHolder(): initialized(true) { } ~GeneralIOMutexHolder() { initialized = false; } - void lock() { if (initialized) mutex.lock(); } - void unlock() { if (initialized) mutex.unlock(); } + void lock() { if (initialized) mutex_.lock(); } + void unlock() { if (initialized) mutex_.unlock(); } }; GeneralIOMutexHolder general_io_mutex; diff --git a/synfig-core/src/synfig/mutex.cpp b/synfig-core/src/synfig/mutex.cpp deleted file mode 100644 index c35bd26..0000000 --- a/synfig-core/src/synfig/mutex.cpp +++ /dev/null @@ -1,306 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file mutex.cpp -** \brief Template File -** -** $Id$ -** -** \legal -** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** \endlegal -*/ -/* ========================================================================= */ - -/* === H E A D E R S ======================================================= */ - -#ifdef USING_PCH -# include "pch.h" -#else -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "mutex.h" - -#ifdef HAVE_LIBPTHREAD -#define USING_PTHREADS 1 -#else -#ifdef _WIN32 -#define USING_WIN32_THREADS 1 -#else -#error Need either libpthread of win32 threads -#endif -#endif - -#ifdef USING_WIN32_THREADS -#include -#endif - -#ifdef USING_PTHREADS -#include -#endif - -#endif - -/* === U S I N G =========================================================== */ - -//using namespace std; -//using namespace etl; -using namespace synfig; - -/* === M A C R O S ========================================================= */ - -/* === G L O B A L S ======================================================= */ - -/* === P R O C E D U R E S ================================================= */ - -/* === M E T H O D S ======================================================= */ - - - - - - -bool -Mutex::is_locked() -{ - if(try_lock()) - { - unlock(); - return false; - } - return true; -} - -void -RecMutex::unlock_all() -{ - while(is_locked()) unlock(); -} - -#ifdef USING_PTHREADS -Mutex::Mutex() -{ - pthread_mutex_t*const mtx_ptr(new pthread_mutex_t); - - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - - //#ifdef PTHREAD_PRIO_INHERIT - //pthread_mutexattr_setprioceiling(&attr,PTHREAD_PRIO_INHERIT); - //#endif - - //#ifdef PTHREAD_MUTEX_RECURSIVE - //pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE); - //#endif - - pthread_mutex_init(mtx_ptr,&attr); - pthread_mutexattr_destroy(&attr); - - blackbox=mtx_ptr; -} - -Mutex::~Mutex() -{ - pthread_mutex_t*const mtx_ptr(static_cast(blackbox)); - pthread_mutex_destroy(mtx_ptr); - delete mtx_ptr; -} - -void -Mutex::lock() -{ - pthread_mutex_t*const mtx_ptr(static_cast(blackbox)); - pthread_mutex_lock(mtx_ptr); -} - -void -Mutex::unlock() -{ - pthread_mutex_t*const mtx_ptr(static_cast(blackbox)); - pthread_mutex_unlock(mtx_ptr); -} - -bool -Mutex::try_lock() -{ - pthread_mutex_t*const mtx_ptr(static_cast(blackbox)); - return !(bool) pthread_mutex_trylock(mtx_ptr); -} - - -RecMutex::RecMutex() -{ - pthread_mutex_t*const mtx_ptr(static_cast(blackbox)); - pthread_mutexattr_t attr; - - // Backtrack and get rid of the non-recursive mutex - pthread_mutex_destroy(mtx_ptr); - - pthread_mutexattr_init(&attr); - - pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE); - - pthread_mutex_init(mtx_ptr,&attr); - pthread_mutexattr_destroy(&attr); -} - - - -RWLock::RWLock() -{ - pthread_rwlock_t*const rwlock_ptr(new pthread_rwlock_t); - - pthread_rwlock_init(rwlock_ptr, NULL); - - blackbox=rwlock_ptr; -} - -RWLock::~RWLock() -{ - pthread_rwlock_t*const rwlock_ptr(static_cast(blackbox)); - - pthread_rwlock_destroy(rwlock_ptr); - - delete rwlock_ptr; -} - -void -RWLock::reader_lock() -{ - pthread_rwlock_t*const rwlock_ptr(static_cast(blackbox)); - - pthread_rwlock_rdlock(rwlock_ptr); -} - -void -RWLock::reader_unlock() -{ - pthread_rwlock_t*const rwlock_ptr(static_cast(blackbox)); - - pthread_rwlock_unlock(rwlock_ptr); -} - -bool -RWLock::reader_trylock() -{ - pthread_rwlock_t*const rwlock_ptr(static_cast(blackbox)); - - return !pthread_rwlock_tryrdlock(rwlock_ptr); -} - -void -RWLock::writer_lock() -{ - pthread_rwlock_t*const rwlock_ptr(static_cast(blackbox)); - - pthread_rwlock_wrlock(rwlock_ptr); -} - -void -RWLock::writer_unlock() -{ - pthread_rwlock_t*const rwlock_ptr(static_cast(blackbox)); - - pthread_rwlock_unlock(rwlock_ptr); -} - -bool -RWLock::writer_trylock() -{ - pthread_rwlock_t*const rwlock_ptr(static_cast(blackbox)); - - return !pthread_rwlock_trywrlock(rwlock_ptr); -} - -#endif - -#ifdef USING_WIN32_THREADS -Mutex::Mutex() -{ - HANDLE& mtx(*reinterpret_cast(&blackbox)); - mtx=CreateMutex(NULL, FALSE, NULL); -} - -Mutex::~Mutex() -{ - HANDLE mtx(reinterpret_cast(blackbox)); - CloseHandle(mtx); -} - -void -Mutex::lock() -{ - HANDLE mtx(reinterpret_cast(blackbox)); - WaitForSingleObject(mtx, INFINITE); -} - -void -Mutex::unlock() -{ - HANDLE mtx(reinterpret_cast(blackbox)); - ReleaseMutex(mtx); -} - -bool -Mutex::try_lock() -{ - HANDLE mtx(reinterpret_cast(blackbox)); - return WaitForSingleObject(mtx, 0)==WAIT_FAILED; -} - - -RecMutex::RecMutex() -{ - // Win32 mutexes are recursive by default. -} - - -RWLock::RWLock() -{ -} - -RWLock::~RWLock() -{ -} - -void -RWLock::reader_lock() -{ -} - -void -RWLock::reader_unlock() -{ -} - -bool -RWLock::reader_trylock() -{ -} - -void -RWLock::writer_lock() -{ -} - -void -RWLock::writer_unlock() -{ -} - -bool -RWLock::writer_trylock() -{ -} - -#endif diff --git a/synfig-core/src/synfig/mutex.h b/synfig-core/src/synfig/mutex.h deleted file mode 100644 index 3497635..0000000 --- a/synfig-core/src/synfig/mutex.h +++ /dev/null @@ -1,118 +0,0 @@ -/* === S Y N F I G ========================================================= */ -/*! \file mutex.h -** \brief Template Header -** -** $Id$ -** -** \legal -** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley -** -** This package is free software; you can redistribute it and/or -** modify it under the terms of the GNU General Public License as -** published by the Free Software Foundation; either version 2 of -** the License, or (at your option) any later version. -** -** This package is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** General Public License for more details. -** \endlegal -*/ -/* ========================================================================= */ - -/* === S T A R T =========================================================== */ - -#ifndef __SYNFIG_MUTEX_H -#define __SYNFIG_MUTEX_H - -/* === H E A D E R S ======================================================= */ - -/* === M A C R O S ========================================================= */ - -/* === T Y P E D E F S ===================================================== */ - -/* === C L A S S E S & S T R U C T S ======================================= */ - -namespace synfig { - -class RecMutex; - -class Mutex -{ - friend class RecMutex; - -protected: - void* blackbox; - -public: - - class Lock - { - Mutex& mutex; - public: - Lock(Mutex& x):mutex(x) { mutex.lock(); } - ~Lock() { mutex.unlock(); } - }; - - Mutex(); - ~Mutex(); - - void lock(); - void unlock(); - bool try_lock(); - bool is_locked(); - -private: - //! Non-copyable - Mutex(const Mutex&); - - //! Non-assignable - void operator=(const Mutex&); -}; - -class RecMutex : public Mutex -{ -public: - RecMutex(); - - void unlock_all(); -}; - -class RWLock -{ - void* blackbox; - -public: - - class ReaderLock - { - RWLock& rw_lock; - public: - ReaderLock(RWLock& x):rw_lock(x) { rw_lock.reader_lock(); } - ~ReaderLock() { rw_lock.reader_unlock(); } - }; - class WriterLock - { - RWLock& rw_lock; - public: - WriterLock(RWLock& x):rw_lock(x) { rw_lock.writer_lock(); } - ~WriterLock() { rw_lock.writer_unlock(); } - }; - - RWLock(); - ~RWLock(); - - void reader_lock(); - void reader_unlock(); - bool reader_trylock(); - - void writer_lock(); - void writer_unlock(); - bool writer_trylock(); -}; - -}; // END of namespace synfig - -/* === E N D =============================================================== */ - -#endif diff --git a/synfig-core/src/synfig/node.cpp b/synfig-core/src/synfig/node.cpp index a66caf1..201f8fa 100644 --- a/synfig-core/src/synfig/node.cpp +++ b/synfig-core/src/synfig/node.cpp @@ -72,21 +72,21 @@ namespace { typedef std::map Map; private: - Mutex mutex; + std::mutex mutex_; Map map; public: Node* get(const GUID &guid) { - Mutex::Lock lock(mutex); + std::lock_guard lock(mutex_); Map::iterator i = map.find(guid); - return i == map.end() ? 0 : i->second; + return i == map.end() ? nullptr : i->second; } void add(const GUID &guid, Node *node) { assert(guid); assert(node); - Mutex::Lock lock(mutex); + std::lock_guard lock(mutex_); assert(!map.count(guid)); map[guid] = node; } @@ -95,7 +95,7 @@ namespace { assert(guid); assert(node); - Mutex::Lock lock(mutex); + std::lock_guard lock(mutex_); Map::iterator i = map.find(guid); assert(i != map.end() && i->second == node); map.erase(i); @@ -110,7 +110,7 @@ namespace { } assert(oldguid); - Mutex::Lock lock(mutex); + std::lock_guard lock(mutex_); Map::iterator i = map.find(oldguid); assert(i != map.end() && i->second == node); map.erase(i); @@ -218,7 +218,7 @@ Node::child_changed(const Node *x) const synfig::GUID& Node::get_guid()const { - Mutex::Lock lock(guid_mutex_); + std::lock_guard lock(guid_mutex_); if(!guid_) { guid_.make_unique(); @@ -232,7 +232,7 @@ void Node::set_guid(const synfig::GUID& x) { assert(x); - Mutex::Lock lock(guid_mutex_); + std::lock_guard lock(guid_mutex_); if (guid_ == x) return; if (!guid_) { diff --git a/synfig-core/src/synfig/node.h b/synfig-core/src/synfig/node.h index 4fb0133..03e54bb 100644 --- a/synfig-core/src/synfig/node.h +++ b/synfig-core/src/synfig/node.h @@ -37,7 +37,8 @@ #include "guid.h" #include #include "interpolation.h" -#include "mutex.h" +#include +#include /* === M A C R O S ========================================================= */ @@ -141,7 +142,7 @@ public: private: //! \ The GUID of the node - mutable Mutex guid_mutex_; + mutable std::mutex guid_mutex_; mutable GUID guid_; //! cached time values for all the children @@ -155,8 +156,7 @@ private: mutable int time_last_changed_; //! \writeme - //! \see mutex.h - mutable RWLock rw_lock_; + mutable Glib::Threads::RWLock rw_lock_; //! Variable used to remember that a signal_deleted has been thrown bool deleting_; @@ -248,7 +248,7 @@ public: const time_set &get_times() const; //! Writeme! - RWLock& get_rw_lock()const { return rw_lock_; } + Glib::Threads::RWLock& get_rw_lock()const { return rw_lock_; } virtual String get_string()const = 0; protected: diff --git a/synfig-core/src/synfig/rendering/primitive/contour.cpp b/synfig-core/src/synfig/rendering/primitive/contour.cpp index 633727d..a9afd2c 100644 --- a/synfig-core/src/synfig/rendering/primitive/contour.cpp +++ b/synfig-core/src/synfig/rendering/primitive/contour.cpp @@ -453,12 +453,12 @@ Contour::assign(const Contour &other) // other contour is constant, so we need to lock mutexes for read the bounds and intersector // see comments for get_bounds() and get_intersector() declarations { - Mutex::Lock lock(other.bounds_read_mutex); + std::lock_guard lock(other.bounds_read_mutex); bounds_calculated = other.bounds_calculated; bounds = other.bounds; } { - Mutex::Lock lock(other.intersector_read_mutex); + std::lock_guard lock(other.intersector_read_mutex); intersector = other.intersector; } } @@ -585,7 +585,7 @@ Contour::calc_bounds(const Matrix &transform_matrix) const Rect Contour::get_bounds() const { - Mutex::Lock lock(bounds_read_mutex); + std::lock_guard lock(bounds_read_mutex); if (!bounds_calculated) { bounds = calc_bounds(); bounds_calculated = true; @@ -621,10 +621,10 @@ Contour::crerate_intersector() const const Intersector& Contour::get_intersector() const { - Mutex::Lock lock(intersector_read_mutex); + std::lock_guard lock(intersector_read_mutex); if (!intersector) { intersector = crerate_intersector(); - Mutex::Lock lock(bounds_read_mutex); + std::lock_guard lock(bounds_read_mutex); if (!bounds_calculated) { bounds = intersector->get_bounds(); bounds_calculated = true; diff --git a/synfig-core/src/synfig/rendering/primitive/contour.h b/synfig-core/src/synfig/rendering/primitive/contour.h index 356206f..4f2f5e3 100644 --- a/synfig-core/src/synfig/rendering/primitive/contour.h +++ b/synfig-core/src/synfig/rendering/primitive/contour.h @@ -35,7 +35,7 @@ #include #include #include -#include +#include /* === M A C R O S ========================================================= */ @@ -102,11 +102,11 @@ private: int first; bool autocurve_begin, autocurve_end; - mutable Mutex bounds_read_mutex; + mutable std::mutex bounds_read_mutex; mutable bool bounds_calculated; mutable Rect bounds; - mutable Mutex intersector_read_mutex; + mutable std::mutex intersector_read_mutex; mutable etl::handle intersector; //! call this when 'chunks' or 'first' was changed diff --git a/synfig-core/src/synfig/rendering/primitive/mesh.cpp b/synfig-core/src/synfig/rendering/primitive/mesh.cpp index 7493f11..e953ab2 100644 --- a/synfig-core/src/synfig/rendering/primitive/mesh.cpp +++ b/synfig-core/src/synfig/rendering/primitive/mesh.cpp @@ -55,7 +55,7 @@ Mesh::assign(const Mesh &other) { // other mesh is constant, so we need to lock mutexes for read the relolution data // see comment for calculate_resolution_transfrom() declaration { - Mutex::Lock lock(other.resolution_transfrom_read_mutex); + std::lock_guard lock(other.resolution_transfrom_read_mutex); resolution_transfrom_calculated = other.resolution_transfrom_calculated; target_rectangle = other.target_rectangle; source_rectangle = other.source_rectangle; @@ -130,14 +130,14 @@ Mesh::calculate_resolution_transfrom_no_lock(bool force) const void Mesh::calculate_resolution_transfrom(bool force) const { - Mutex::Lock lock(resolution_transfrom_read_mutex); + std::lock_guard lock(resolution_transfrom_read_mutex); calculate_resolution_transfrom_no_lock(force); } Matrix2 Mesh::get_resolution_transfrom() const { - Mutex::Lock lock(resolution_transfrom_read_mutex); + std::lock_guard lock(resolution_transfrom_read_mutex); calculate_resolution_transfrom_no_lock(); return resolution_transfrom; } @@ -145,7 +145,7 @@ Mesh::get_resolution_transfrom() const Rect Mesh::get_target_rectangle() const { - Mutex::Lock lock(resolution_transfrom_read_mutex); + std::lock_guard lock(resolution_transfrom_read_mutex); calculate_resolution_transfrom_no_lock(); return target_rectangle; } @@ -153,7 +153,7 @@ Mesh::get_target_rectangle() const Rect Mesh::get_source_rectangle() const { - Mutex::Lock lock(resolution_transfrom_read_mutex); + std::lock_guard lock(resolution_transfrom_read_mutex); calculate_resolution_transfrom_no_lock(); return source_rectangle; } diff --git a/synfig-core/src/synfig/rendering/primitive/mesh.h b/synfig-core/src/synfig/rendering/primitive/mesh.h index eeaddaf..87feeb2 100644 --- a/synfig-core/src/synfig/rendering/primitive/mesh.h +++ b/synfig-core/src/synfig/rendering/primitive/mesh.h @@ -35,7 +35,7 @@ #include #include -#include +#include /* === M A C R O S ========================================================= */ @@ -78,7 +78,7 @@ public: TriangleList triangles; private: - mutable Mutex resolution_transfrom_read_mutex; + mutable std::mutex resolution_transfrom_read_mutex; mutable bool resolution_transfrom_calculated; mutable Rect target_rectangle; mutable Rect source_rectangle; diff --git a/synfig-core/src/synfig/rendering/resource.cpp b/synfig-core/src/synfig/rendering/resource.cpp index fd2080d..3c03a98 100644 --- a/synfig-core/src/synfig/rendering/resource.cpp +++ b/synfig-core/src/synfig/rendering/resource.cpp @@ -46,35 +46,25 @@ using namespace rendering; Resource::Id Resource::last_id = 0; -Resource::Storage::Storage(): refcount() { } +Resource::Storage::Storage(): refcount(0) { } Resource::Storage::~Storage() { } void Resource::Storage::ref() const { - #ifdef ETL_LOCK_REFCOUNTS - etl::mutex::lock lock(mtx); - #endif ++refcount; } bool Resource::Storage::unref_inactive() const { - #ifdef ETL_LOCK_REFCOUNTS - etl::mutex::lock lock(mtx); - #endif return refcount == 0 || --refcount != (int)resources.size(); } bool Resource::Storage::unref() const { - #ifdef ETL_LOCK_REFCOUNTS - etl::mutex::lock lock(mtx); - #endif - if (refcount == 0) return true; if (--refcount == (int)resources.size()) { @@ -91,9 +81,6 @@ Resource::Storage::unref() const int Resource::Storage::count() const { - #ifdef ETL_LOCK_REFCOUNTS - etl::mutex::lock lock(mtx); - #endif return refcount; } diff --git a/synfig-core/src/synfig/rendering/resource.h b/synfig-core/src/synfig/rendering/resource.h index e513786..cfb226c 100644 --- a/synfig-core/src/synfig/rendering/resource.h +++ b/synfig-core/src/synfig/rendering/resource.h @@ -30,7 +30,7 @@ #include #include -#include +#include /* === M A C R O S ========================================================= */ @@ -62,10 +62,7 @@ public: typedef etl::handle Handle; private: - mutable int refcount; - #ifdef ETL_LOCK_REFCOUNTS - mutable etl::mutex mtx; - #endif + mutable std::atomic refcount; friend class Resource; @@ -86,7 +83,7 @@ public: private: const Id id; mutable Storage::Handle alternatives; - mutable etl::mutex get_alternative_mtx; + mutable std::mutex get_alternative_mtx; public: Resource(): id(++last_id) { } @@ -112,7 +109,7 @@ public: template etl::handle get_alternative() const { - etl::mutex::lock lock(get_alternative_mtx); + std::lock_guard lock(get_alternative_mtx); etl::handle alternative = find_alternative(); if (!alternative) { diff --git a/synfig-core/src/synfig/rendering/software/function/packedsurface.cpp b/synfig-core/src/synfig/rendering/software/function/packedsurface.cpp index ac78039..11de59e 100644 --- a/synfig-core/src/synfig/rendering/software/function/packedsurface.cpp +++ b/synfig-core/src/synfig/rendering/software/function/packedsurface.cpp @@ -89,7 +89,7 @@ PackedSurface::Reader::open(const PackedSurface &surface) { this->surface = &surface; - synfig::Mutex::Lock lock(surface.mutex); + std::lock_guard lock(surface.mutex_); surface.readers.insert(this); } @@ -120,7 +120,7 @@ PackedSurface::Reader::close() if (is_opened()) { { - synfig::Mutex::Lock lock(surface->mutex); + std::lock_guard lock(surface->mutex_); surface->readers.erase(this); } if (cache) delete[] cache; diff --git a/synfig-core/src/synfig/rendering/software/function/packedsurface.h b/synfig-core/src/synfig/rendering/software/function/packedsurface.h index 8eb85e7..ce5ed5a 100644 --- a/synfig-core/src/synfig/rendering/software/function/packedsurface.h +++ b/synfig-core/src/synfig/rendering/software/function/packedsurface.h @@ -31,7 +31,6 @@ #include #include -#include #include #include "../../primitive/contour.h" @@ -129,7 +128,7 @@ public: typedef etl::sampler Sampler; private: - mutable synfig::Mutex mutex; + mutable std::mutex mutex_; mutable std::set readers; int width; diff --git a/synfig-studio/m4/ETL.m4 b/synfig-studio/m4/ETL.m4 index b1aaa8f..e58d140 100644 --- a/synfig-studio/m4/ETL.m4 +++ b/synfig-studio/m4/ETL.m4 @@ -10,22 +10,11 @@ AC_DEFUN([ETL_DEPS], AC_C_BIGENDIAN AC_CHECK_LIB(user32, main) - AC_CHECK_LIB([kernel32], [CreateMutex]) - AC_CHECK_LIB([pthread], [pthread_mutex_init]) - - AC_HEADER_STDC - - AC_CHECK_HEADERS(pthread.h) - AC_CHECK_HEADERS(sched.h) + AC_CHECK_HEADERS(sys/times.h) AC_CHECK_HEADERS(sys/time.h) AC_CHECK_HEADERS(unistd.h) AC_CHECK_HEADERS(windows.h) - AC_CHECK_FUNCS([pthread_create]) - AC_CHECK_FUNCS([pthread_rwlock_init]) - AC_CHECK_FUNCS([pthread_yield]) - AC_CHECK_FUNCS([sched_yield]) - AC_CHECK_FUNCS([CreateThread]) AC_CHECK_FUNCS([__clone]) AC_CHECK_FUNCS([QueryPerformanceCounter]) diff --git a/synfig-studio/src/gui/ipc.cpp b/synfig-studio/src/gui/ipc.cpp index 5f554b6..af5aa49 100644 --- a/synfig-studio/src/gui/ipc.cpp +++ b/synfig-studio/src/gui/ipc.cpp @@ -61,12 +61,11 @@ #include "docks/dock_toolbox.h" #include -#include +#include +#include #include #include -#include #include - #ifdef _WIN32 #include #define BUFSIZE 128 @@ -90,9 +89,11 @@ using namespace studio; #ifdef _WIN32 #define WIN32_PIPE_PATH "\\\\.\\pipe\\SynfigStudio.Cmd" -static synfig::Mutex cmd_mutex; +static std::mutex cmd_mutex; static std::list cmd_queue; static Glib::Dispatcher* cmd_dispatcher; +static bool thread_should_quit = false; +std::thread *cmd_thread = nullptr; static void pipe_listen_thread() { @@ -120,7 +121,7 @@ pipe_listen_thread() DWORD read_bytes; bool success; - Glib::Thread::yield(); + std::this_thread::yield(); if(connected) do { @@ -138,7 +139,7 @@ pipe_listen_thread() if(success && read_bytes==1 && c!='\n') data+=c; }while(c!='\n'); - synfig::Mutex::Lock lock(cmd_mutex); + std::lock_guard lock(cmd_mutex); cmd_queue.push_back(data); cmd_dispatcher->emit(); } while(success && read_bytes); @@ -150,7 +151,7 @@ pipe_listen_thread() static void empty_cmd_queue() { - synfig::Mutex::Lock lock(cmd_mutex); + std::lock_guard lock(cmd_mutex); while(!cmd_queue.empty()) { IPC::process_command(cmd_queue.front()); @@ -171,11 +172,9 @@ IPC::IPC() cmd_dispatcher=new Glib::Dispatcher; cmd_dispatcher->connect(sigc::ptr_fun(empty_cmd_queue)); - Glib::Thread::create( - sigc::ptr_fun(pipe_listen_thread), - false - ); + thread_should_quit = false; + cmd_thread = new std::thread(pipe_listen_thread); #else remove(fifo_path().c_str()); @@ -215,7 +214,13 @@ IPC::~IPC() // fclose(file.get()); remove(fifo_path().c_str()); - +#ifdef _WIN32 + thread_should_quit = true; + if (cmd_thread->joinable()) + cmd_thread->join(); + delete cmd_thread; + delete cmd_dispatcher; +#endif //if(fd>=0) // close(fd); } diff --git a/synfig-studio/src/gui/workarea.cpp b/synfig-studio/src/gui/workarea.cpp index 3f5b3f7..51c35fd 100644 --- a/synfig-studio/src/gui/workarea.cpp +++ b/synfig-studio/src/gui/workarea.cpp @@ -49,7 +49,6 @@ #include #include #include -#include #include #include #include diff --git a/synfig-studio/src/synfigapp/actions/layerpaint.cpp b/synfig-studio/src/synfigapp/actions/layerpaint.cpp index 7dd761a..b44fd25 100644 --- a/synfig-studio/src/synfigapp/actions/layerpaint.cpp +++ b/synfig-studio/src/synfigapp/actions/layerpaint.cpp @@ -154,7 +154,7 @@ Action::LayerPaint::PaintStroke::add_point_and_apply(const PaintPoint &point) int w = wrapper.surface->get_w(); int h = wrapper.surface->get_h(); { - Mutex::Lock lock(layer->mutex); + std::lock_guard lock(layer->mutex_); brush_.stroke_to(&wrapper, point.x, point.y, point.pressure, 0.f, 0.f, point.dtime); // fix state in case of surface resized @@ -219,7 +219,7 @@ Action::LayerPaint::PaintStroke::undo() assert(prepared); if (!applied) return; { - Mutex::Lock lock(layer->mutex); + std::lock_guard lock(layer->mutex_); Surface *surface = new Surface(); paint_prev(*surface); layer->rendering_surface = new rendering::SurfaceResource( @@ -237,7 +237,7 @@ Action::LayerPaint::PaintStroke::apply() assert(prepared); if (applied) return; { - Mutex::Lock lock(layer->mutex); + std::lock_guard lock(layer->mutex_); Surface *surface = new Surface(); paint_self(*surface); layer->rendering_surface = new rendering::SurfaceResource(