diff options
| -rw-r--r-- | plugin/Makefile.mingw32.in | 1 | ||||
| -rw-r--r-- | src/Makefile.am | 2 | ||||
| -rw-r--r-- | src/atomic.h | 1 | ||||
| -rw-r--r-- | src/audiocacheeventhandler.h | 1 | ||||
| -rw-r--r-- | src/audiocachefile.h | 11 | ||||
| -rw-r--r-- | src/audiocacheidmanager.h | 9 | ||||
| -rw-r--r-- | src/audiofile.cc | 4 | ||||
| -rw-r--r-- | src/audiofile.h | 4 | ||||
| -rw-r--r-- | src/drumgizmo.cc | 3 | ||||
| -rw-r--r-- | src/drumgizmo.h | 3 | ||||
| -rw-r--r-- | src/drumkitloader.h | 1 | ||||
| -rw-r--r-- | src/events.cc | 6 | ||||
| -rw-r--r-- | src/events.h | 5 | ||||
| -rw-r--r-- | src/midimapper.h | 1 | ||||
| -rw-r--r-- | src/mutex.cc | 120 | ||||
| -rw-r--r-- | src/mutex.h | 56 | ||||
| -rw-r--r-- | test/Makefile.am | 3 | 
17 files changed, 23 insertions, 208 deletions
| diff --git a/plugin/Makefile.mingw32.in b/plugin/Makefile.mingw32.in index 02475d7..6ccfe48 100644 --- a/plugin/Makefile.mingw32.in +++ b/plugin/Makefile.mingw32.in @@ -32,7 +32,6 @@ DG_SRC = \  	@top_srcdir@/src/memchecker.cc \  	@top_srcdir@/src/midimapparser.cc \  	@top_srcdir@/src/midimapper.cc \ -	@top_srcdir@/src/mutex.cc \  	@top_srcdir@/src/path.cc \  	@top_srcdir@/src/powerlist.cc \  	@top_srcdir@/src/random.cc \ diff --git a/src/Makefile.am b/src/Makefile.am index d0ede77..f50acc6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,7 +36,6 @@ nodist_libdg_la_SOURCES = \  	memchecker.cc \  	midimapparser.cc \  	midimapper.cc \ -	mutex.cc \  	path.cc \  	powerlist.cc \  	random.cc \ @@ -80,7 +79,6 @@ EXTRA_DIST = \  	memchecker.h \  	midimapparser.h \  	midimapper.h \ -	mutex.h \  	nolocale.h \  	notifier.h \  	path.h \ diff --git a/src/atomic.h b/src/atomic.h index 55ec7e5..7ca5d1e 100644 --- a/src/atomic.h +++ b/src/atomic.h @@ -30,7 +30,6 @@  #include <atomic>  #include <mutex> -#include "mutex.h"  template <typename T, typename = void>  class Atomic; diff --git a/src/audiocacheeventhandler.h b/src/audiocacheeventhandler.h index 7d4ed58..e1e60a9 100644 --- a/src/audiocacheeventhandler.h +++ b/src/audiocacheeventhandler.h @@ -32,7 +32,6 @@  #include "thread.h"  #include "semaphore.h" -#include "mutex.h"  #include "audiocachefile.h"  #include "audiocacheidmanager.h" diff --git a/src/audiocachefile.h b/src/audiocachefile.h index 01625a7..66a6529 100644 --- a/src/audiocachefile.h +++ b/src/audiocachefile.h @@ -30,16 +30,15 @@  #include <list>  #include <map>  #include <vector> -  #include <mutex> -#include "mutex.h"  #include <sndfile.h>  #include <audiotypes.h>  //! Channel data container in the cache world. -class CacheChannel { +class CacheChannel +{  public:  	size_t channel; //< Channel number  	sample_t* samples; //< Sample buffer pointer. @@ -52,7 +51,8 @@ using CacheChannels = std::list<CacheChannel>;  //! This class is used to encapsulate reading from a single file source.  //! The access is ref counted so that the file is only opened once and closed  //! when it is no longer required. -class AudioCacheFile { +class AudioCacheFile +{  	friend class AudioCacheFiles;  	friend class TestableAudioCacheFiles;  public: @@ -82,7 +82,8 @@ private:  	std::vector<sample_t>& read_buffer;  }; -class AudioCacheFiles { +class AudioCacheFiles +{  public:  	//! Get the CacheAudioFile object corresponding to filename.  	//! If it does not exist it will be created. diff --git a/src/audiocacheidmanager.h b/src/audiocacheidmanager.h index a5a9755..0aa40e3 100644 --- a/src/audiocacheidmanager.h +++ b/src/audiocacheidmanager.h @@ -33,7 +33,6 @@  #include <audiotypes.h>  #include <mutex> -#include "mutex.h"  class AudioCacheFile; @@ -42,7 +41,8 @@ class AudioCacheFile;  typedef int cacheid_t; -typedef struct { +struct cache_t +{  	cacheid_t id{CACHE_NOID}; //< Current id of this cache_t. CACHE_NOID means not in use.  	AudioCacheFile* afile{nullptr}; @@ -55,9 +55,10 @@ typedef struct {  	sample_t* preloaded_samples{nullptr}; // nullptr means preload buffer not active.  	size_t preloaded_samples_size{0}; -} cache_t; +}; -class AudioCacheIDManager { +class AudioCacheIDManager +{  	friend class AudioCacheEventHandler;  public:  	AudioCacheIDManager() = default; diff --git a/src/audiofile.cc b/src/audiofile.cc index 93b2e4f..3fe854b 100644 --- a/src/audiofile.cc +++ b/src/audiofile.cc @@ -62,7 +62,7 @@ bool AudioFile::isValid() const  void AudioFile::unload()  {  	// Make sure we don't unload the object while loading it... -	MutexAutolock l(mutex); +	std::lock_guard<std::mutex> guard(mutex);  	is_loaded = false; @@ -77,7 +77,7 @@ void AudioFile::unload()  void AudioFile::load(std::size_t sample_limit)  {  	// Make sure we don't unload the object while loading it... -	MutexAutolock l(mutex); +	std::lock_guard<std::mutex> guard(mutex);  	if(this->data) // already loaded  	{ diff --git a/src/audiofile.h b/src/audiofile.h index 07b40dd..e393511 100644 --- a/src/audiofile.h +++ b/src/audiofile.h @@ -30,10 +30,10 @@  #include <map>  #include <vector>  #include <limits> +#include <mutex>  #include <sndfile.h> -#include "mutex.h"  #include "audio.h"  class AudioFile @@ -55,7 +55,7 @@ public:  	bool isValid() const; -	Mutex mutex; +	std::mutex mutex;  	std::size_t filechannel; diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index e55acf6..bf6fc7b 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -30,6 +30,7 @@  #include <cstdio>  #include <cassert>  #include <cstring> +#include <mutex>  #include <event.h>  #include <audiotypes.h> @@ -267,7 +268,7 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t* s, size_t sz)  				}  				{ -					MutexAutolock l(af.mutex); +					std::lock_guard<std::mutex> guard(af.mutex);  					size_t n = 0; // default start point is 0. diff --git a/src/drumgizmo.h b/src/drumgizmo.h index e74d1b5..008d189 100644 --- a/src/drumgizmo.h +++ b/src/drumgizmo.h @@ -37,7 +37,6 @@  #include "drumkit.h"  #include "drumkitloader.h"  #include "audiocache.h" -#include "mutex.h"  #include "chresampler.h"  #include "settings.h"  #include "inputprocessor.h" @@ -79,8 +78,6 @@ private:  protected:  	DrumKitLoader loader; -	Mutex mutex; -  	AudioOutputEngine& oe;  	AudioInputEngine& ie; diff --git a/src/drumkitloader.h b/src/drumkitloader.h index 22fa310..09177fa 100644 --- a/src/drumkitloader.h +++ b/src/drumkitloader.h @@ -29,7 +29,6 @@  #include <string>  #include <list>  #include <mutex> -#include "mutex.h"  #include "thread.h"  #include "semaphore.h" diff --git a/src/events.cc b/src/events.cc index a7ce715..1acbc11 100644 --- a/src/events.cc +++ b/src/events.cc @@ -28,14 +28,14 @@  void EventQueue::post(Event* event, timepos_t time)  { -	MutexAutolock lock(mutex); +	std::lock_guard<std::mutex> guard(mutex);  	event->offset = time;  	queue.insert(std::pair<timepos_t, Event*>(time, event));  }  Event* EventQueue::take(timepos_t time)  { -	MutexAutolock lock(mutex); +	std::lock_guard<std::mutex> guard(mutex);  	std::multimap<timepos_t, Event*>::iterator i = queue.find(time);  	if(i == queue.end())  		return NULL; @@ -46,6 +46,6 @@ Event* EventQueue::take(timepos_t time)  bool EventQueue::hasEvent(timepos_t time)  { -	MutexAutolock lock(mutex); +	std::lock_guard<std::mutex> guard(mutex);  	return queue.find(time) != queue.end();  } diff --git a/src/events.h b/src/events.h index bbbb7ea..b0ca6cf 100644 --- a/src/events.h +++ b/src/events.h @@ -29,11 +29,12 @@  #include <map>  #include <stdio.h>  #include <string> +#include <mutex> +  #include <sndfile.h>  #include "audiofile.h"  #include "audio.h" -#include "mutex.h"  #include "audiocache.h"  typedef unsigned int timepos_t; @@ -105,6 +106,6 @@ public:  private:  	std::multimap<timepos_t, Event*> queue; -	Mutex mutex; +	std::mutex mutex;  }; diff --git a/src/midimapper.h b/src/midimapper.h index ea836e3..fc3faec 100644 --- a/src/midimapper.h +++ b/src/midimapper.h @@ -29,7 +29,6 @@  #include <map>  #include <string>  #include <mutex> -#include "mutex.h"  typedef std::map<int, std::string> midimap_t;  typedef std::map<std::string, int> instrmap_t; diff --git a/src/mutex.cc b/src/mutex.cc deleted file mode 100644 index b90132d..0000000 --- a/src/mutex.cc +++ /dev/null @@ -1,120 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set et sw=2 ts=2: */ -/*************************************************************************** - *            mutex.cc - * - *  Thu Nov 12 10:51:32 CET 2009 - *  Copyright 2009 Bent Bisballe Nyeng - *  deva@aasimon.org - ****************************************************************************/ - -/* - *  This file is part of DrumGizmo. - * - *  DrumGizmo is free software; you can redistribute it and/or modify - *  it under the terms of the GNU Lesser General Public License as published by - *  the Free Software Foundation; either version 3 of the License, or - *  (at your option) any later version. - * - *  DrumGizmo 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 Lesser General Public License for more details. - * - *  You should have received a copy of the GNU Lesser General Public License - *  along with DrumGizmo; if not, write to the Free Software - *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. - */ -#include "mutex.h" - -#include <hugin.hpp> -#include "platform.h" - -#if DG_PLATFORM == DG_PLATFORM_WINDOWS -#include <windows.h> -#else -#include <pthread.h> -#include <errno.h> -#endif - -struct mutex_private_t { -#if DG_PLATFORM == DG_PLATFORM_WINDOWS -	HANDLE mutex; -#else -	pthread_mutex_t mutex; -#endif -}; - -Mutex::Mutex() -{ -	prv = new struct mutex_private_t(); -#if DG_PLATFORM == DG_PLATFORM_WINDOWS -	prv->mutex = CreateMutex(nullptr,  // default security attributes -	                         FALSE, // initially not owned -	                         nullptr); // unnamed mutex -#else -	pthread_mutex_init (&prv->mutex, nullptr); -#endif -} - -Mutex::~Mutex() -{ -#if DG_PLATFORM == DG_PLATFORM_WINDOWS -	CloseHandle(prv->mutex); -#else -	pthread_mutex_destroy(&prv->mutex); -#endif - -	if(prv) -	{ -	  delete prv; -	} -} - -//! \return true if the function succeeds in locking the mutex for the thread. -//! false otherwise. -bool Mutex::try_lock() -{ -#if DG_PLATFORM == DG_PLATFORM_WINDOWS -	DEBUG(mutex, "%s\n", __PRETTY_FUNCTION__); - -	DWORD result = WaitForSingleObject(prv->mutex, 0); - -	DEBUG(mutex, "WAIT_OBJECT_0: %lu, WAIT_TIMEOUT: %lu, result: %lu\n", -	      WAIT_OBJECT_0, WAIT_TIMEOUT, result); - -	return result != WAIT_TIMEOUT; -#else -	return pthread_mutex_trylock(&prv->mutex) != EBUSY; -#endif -} - -void Mutex::lock() -{ -#if DG_PLATFORM == DG_PLATFORM_WINDOWS -	WaitForSingleObject(prv->mutex, // handle to mutex -	                    INFINITE);  // no time-out interval -#else -	pthread_mutex_lock(&prv->mutex); -#endif -} - -void Mutex::unlock() -{ -#if DG_PLATFORM == DG_PLATFORM_WINDOWS -	ReleaseMutex(prv->mutex); -#else -	pthread_mutex_unlock(&prv->mutex); -#endif -} - -MutexAutolock::MutexAutolock(Mutex &m) -	: mutex(m) -{ -	mutex.lock(); -} - -MutexAutolock::~MutexAutolock() -{ -	mutex.unlock(); -} diff --git a/src/mutex.h b/src/mutex.h deleted file mode 100644 index eafebba..0000000 --- a/src/mutex.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set et sw=2 ts=2: */ -/*************************************************************************** - *            mutex.h - * - *  Thu Nov 12 10:51:32 CET 2009 - *  Copyright 2009 Bent Bisballe Nyeng - *  deva@aasimon.org - ****************************************************************************/ - -/* - *  This file is part of DrumGizmo. - * - *  DrumGizmo is free software; you can redistribute it and/or modify - *  it under the terms of the GNU Lesser General Public License as published by - *  the Free Software Foundation; either version 3 of the License, or - *  (at your option) any later version. - * - *  DrumGizmo 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 Lesser General Public License for more details. - * - *  You should have received a copy of the GNU Lesser General Public License - *  along with DrumGizmo; if not, write to the Free Software - *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. - */ -#pragma once - -#include "platform.h" - -struct mutex_private_t; - -class Mutex -{ -public: -	Mutex(); -	~Mutex(); - -	bool try_lock(); -	void lock(); -	void unlock(); - -private: -	struct mutex_private_t* prv; -}; - -class MutexAutolock -{ -public: -	MutexAutolock(Mutex &mutex); -	~MutexAutolock(); - -private: -	Mutex &mutex; -}; diff --git a/test/Makefile.am b/test/Makefile.am index 027b022..08ef4fa 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -37,7 +37,6 @@ audiocache_SOURCES = \  	$(top_srcdir)/src/audiocachefile.cc \  	$(top_srcdir)/src/audiocacheidmanager.cc \  	$(top_srcdir)/src/thread.cc \ -	$(top_srcdir)/src/mutex.cc \  	$(top_srcdir)/src/semaphore.cc \  	$(top_srcdir)/src/audiofile.cc \  	$(top_srcdir)/src/random.cc \ @@ -52,7 +51,6 @@ audiocachefile_LDFLAGS = $(PTHREAD_LIBS) $(CPPUNIT_LIBS) $(SNDFILE_LIBS)  audiocachefile_SOURCES = \  	$(top_srcdir)/src/audiocachefile.cc \  	$(top_srcdir)/src/thread.cc \ -	$(top_srcdir)/src/mutex.cc \  	$(top_srcdir)/src/semaphore.cc \  	$(top_srcdir)/src/audiofile.cc \  	$(top_srcdir)/src/random.cc \ @@ -79,7 +77,6 @@ audiocacheeventhandler_SOURCES = \  	$(top_srcdir)/src/audiocacheeventhandler.cc \  	$(top_srcdir)/src/audiocacheidmanager.cc \  	$(top_srcdir)/src/audiocachefile.cc \ -	$(top_srcdir)/src/mutex.cc \  	$(top_srcdir)/src/thread.cc \  	$(top_srcdir)/src/semaphore.cc \  	test.cc \ | 
