diff options
-rw-r--r-- | xbmc/threads/test/TestEvent.cpp | 42 | ||||
-rw-r--r-- | xbmc/threads/test/TestHelpers.h | 64 | ||||
-rw-r--r-- | xbmc/threads/test/TestSharedSection.cpp | 41 |
3 files changed, 67 insertions, 80 deletions
diff --git a/xbmc/threads/test/TestEvent.cpp b/xbmc/threads/test/TestEvent.cpp index 659b3dd42a..1fce0f7765 100644 --- a/xbmc/threads/test/TestEvent.cpp +++ b/xbmc/threads/test/TestEvent.cpp @@ -24,7 +24,8 @@ #include "threads/Event.h" #include "threads/Atomics.h" -#include <boost/thread/thread.hpp> +#include "threads/test/TestHelpers.h" + #include <boost/shared_array.hpp> #include <stdio.h> @@ -94,21 +95,6 @@ public: } }; -#define BOOST_MILLIS(x) (boost::get_system_time() + boost::posix_time::milliseconds(x)) - -static void Sleep(unsigned int millis) { boost::thread::sleep(BOOST_MILLIS(millis)); } - -template<class E> static bool waitForWaiters(E& event, int numWaiters, int milliseconds) -{ - for( int i = 0; i < milliseconds; i++) - { - if (event.getNumWaits() == numWaiters) - return true; - Sleep(1); - } - return false; -} - //============================================================================= BOOST_AUTO_TEST_CASE(TestEventCase) @@ -543,14 +529,6 @@ BOOST_AUTO_TEST_CASE(TestEventGroupTimedWait) BOOST_CHECK(waitThread2.timed_join(BOOST_MILLIS(10000))); } -class AtomicGuard -{ - volatile long* val; -public: - inline AtomicGuard(volatile long* val_) : val(val_) { if (val) AtomicIncrement(val); } - inline ~AtomicGuard() { if (val) AtomicDecrement(val); } -}; - #define TESTNUM 100000l #define NUMTHREADS 100l @@ -595,22 +573,6 @@ public: } }; -static bool waitForThread(volatile long& mutex, int numWaiters, int milliseconds) -{ - CCriticalSection sec; - for( int i = 0; i < milliseconds; i++) - { - if (mutex == (long)numWaiters) - return true; - - { - CSingleLock tmplock(sec); // kick any memory syncs - } - Sleep(1); - } - return false; -} - template <class W> void RunMassEventTest(boost::shared_array<W>& m, bool canWaitOnEvent) { boost::shared_array<boost::thread> t; diff --git a/xbmc/threads/test/TestHelpers.h b/xbmc/threads/test/TestHelpers.h new file mode 100644 index 0000000000..c9ef29dcb5 --- /dev/null +++ b/xbmc/threads/test/TestHelpers.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2005-2011 Team XBMC + * http://www.xbmc.org + * + * This Program 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, or (at your option) + * any later version. + * + * This Program 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. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#pragma once + +#include <boost/thread/thread.hpp> + +#define BOOST_MILLIS(x) (boost::get_system_time() + boost::posix_time::milliseconds(x)) + +inline static void Sleep(unsigned int millis) { boost::thread::sleep(BOOST_MILLIS(millis)); } + +template<class E> inline static bool waitForWaiters(E& event, int numWaiters, int milliseconds) +{ + for( int i = 0; i < milliseconds; i++) + { + if (event.getNumWaits() == numWaiters) + return true; + Sleep(1); + } + return false; +} + +inline static bool waitForThread(volatile long& mutex, int numWaiters, int milliseconds) +{ + CCriticalSection sec; + for( int i = 0; i < milliseconds; i++) + { + if (mutex == (long)numWaiters) + return true; + + { + CSingleLock tmplock(sec); // kick any memory syncs + } + Sleep(1); + } + return false; +} + +class AtomicGuard +{ + volatile long* val; +public: + inline AtomicGuard(volatile long* val_) : val(val_) { if (val) AtomicIncrement(val); } + inline ~AtomicGuard() { if (val) AtomicDecrement(val); } +}; + diff --git a/xbmc/threads/test/TestSharedSection.cpp b/xbmc/threads/test/TestSharedSection.cpp index 0eea876c4d..07e70c530d 100644 --- a/xbmc/threads/test/TestSharedSection.cpp +++ b/xbmc/threads/test/TestSharedSection.cpp @@ -25,53 +25,14 @@ #include "threads/SingleLock.h" #include "threads/Event.h" #include "threads/Atomics.h" +#include "threads/test/TestHelpers.h" -#include <boost/thread/thread.hpp> #include <stdio.h> //============================================================================= // Helper classes //============================================================================= -#define BOOST_MILLIS(x) (boost::get_system_time() + boost::posix_time::milliseconds(x)) - -static void Sleep(unsigned int millis) { boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(millis)); } - -static bool waitForThread(volatile long& mutex, int numWaiters, int milliseconds) -{ - CCriticalSection sec; - for( int i = 0; i < milliseconds; i++) - { - if (mutex == (long)numWaiters) - return true; - - { - CSingleLock tmplock(sec); // kick any memory syncs - } - Sleep(1); - } - return false; -} - -template<class E> static bool waitForWaiters(E& event, int numWaiters, int milliseconds) -{ - for( int i = 0; i < milliseconds; i++) - { - if (event.getNumWaits() == numWaiters) - return true; - Sleep(1); - } - return false; -} - -class AtomicGuard -{ - volatile long* val; -public: - inline AtomicGuard(volatile long* val_) : val(val_) { if (val) AtomicIncrement(val); } - inline ~AtomicGuard() { if (val) AtomicDecrement(val); } -}; - template<class L> class locker { |