From 7a962fca94c3ed8f5a24d160504a7c9d3ecce04c Mon Sep 17 00:00:00 2001 From: Rodolfo Ribeiro Gomes Date: Dec 04 2019 10:06:14 +0000 Subject: remove unused ETL mutex and thread classes Smach class just fakes that it is using them (by using mutex_null) Resource class uses it, but it can be replaced by C++11 standard mutex. That ETL_LOCK_REFCOUNTS directive is not mentioned anywhere. Maybe it should be removed? --- 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/synfig-core/src/synfig/rendering/resource.cpp b/synfig-core/src/synfig/rendering/resource.cpp index fd2080d..bb80ccf 100644 --- a/synfig-core/src/synfig/rendering/resource.cpp +++ b/synfig-core/src/synfig/rendering/resource.cpp @@ -54,7 +54,7 @@ void Resource::Storage::ref() const { #ifdef ETL_LOCK_REFCOUNTS - etl::mutex::lock lock(mtx); + std::lock_guard lock(mtx); #endif ++refcount; } @@ -63,7 +63,7 @@ bool Resource::Storage::unref_inactive() const { #ifdef ETL_LOCK_REFCOUNTS - etl::mutex::lock lock(mtx); + std::lock_guard lock(mtx); #endif return refcount == 0 || --refcount != (int)resources.size(); } @@ -72,7 +72,7 @@ bool Resource::Storage::unref() const { #ifdef ETL_LOCK_REFCOUNTS - etl::mutex::lock lock(mtx); + std::lock_guard lock(mtx); #endif if (refcount == 0) return true; @@ -92,7 +92,7 @@ int Resource::Storage::count() const { #ifdef ETL_LOCK_REFCOUNTS - etl::mutex::lock lock(mtx); + std::lock_guard 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..9d39e16 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 ========================================================= */ @@ -64,7 +64,7 @@ public: private: mutable int refcount; #ifdef ETL_LOCK_REFCOUNTS - mutable etl::mutex mtx; + mutable std::mutex mtx; #endif friend class Resource; @@ -86,7 +86,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 +112,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) {