Commit 0ba6d5cd authored by Douglas Serson's avatar Douglas Serson
Browse files

Revert "Add option to disable locks for threading"

This reverts commit 3044e57b.
parent 163c18c4
......@@ -141,15 +141,6 @@ OPTION(NEKTAR_USE_MEMORY_POOLS
"Use memory pools to accelerate memory allocation." ON)
MARK_AS_ADVANCED(NEKTAR_USE_MEMORY_POOLS)
# Option to disable threads
OPTION(NEKTAR_USE_THREADS
"Enable functionality required for using threads." ON)
MARK_AS_ADVANCED(NEKTAR_USE_THREADS)
IF (NEKTAR_USE_THREADS)
ADD_DEFINITIONS(-DNEKTAR_USING_THREADS)
ENDIF()
IF (MSVC)
# Needed for M_PI to be visible in visual studio.
ADD_DEFINITIONS(-D_USE_MATH_DEFINES)
......
///////////////////////////////////////////////////////////////////////////////
//
// File: MutexTypeDefs.h
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Type definitions of mutex objects.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef NEKTAR_LIB_UTILITIES_BASICUTILS_MUTEXTYPEDEFS_H
#define NEKTAR_LIB_UTILITIES_BASICUTILS_MUTEXTYPEDEFS_H
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/locks.hpp>
#include <LibUtilities/LibUtilitiesDeclspec.h>
namespace Nektar
{
namespace LibUtilities
{
#ifdef NEKTAR_USING_THREADS
typedef boost::unique_lock<boost::shared_mutex> WriteLock;
typedef boost::shared_lock<boost::shared_mutex> ReadLock;
typedef boost::mutex::scoped_lock ScopedLock;
typedef boost::shared_mutex SharedMutex;
typedef boost::mutex Mutex;
#else
class Lock
{
public:
LIB_UTILITIES_EXPORT Lock(){}
LIB_UTILITIES_EXPORT Lock(int i){}
LIB_UTILITIES_EXPORT ~Lock(){}
LIB_UTILITIES_EXPORT inline void lock(){}
LIB_UTILITIES_EXPORT inline void unlock(){}
};
typedef Lock WriteLock;
typedef Lock ReadLock;
typedef Lock ScopedLock;
typedef int SharedMutex;
typedef int Mutex;
#endif
}
}
#endif //NEKTAR_LIB_UTILITIES_BASICUTILS_MUTEXTYPEDEFS_H
......@@ -43,6 +43,8 @@
#include <boost/preprocessor/arithmetic/sub.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/locks.hpp>
#include <boost/shared_ptr.hpp>
......@@ -51,7 +53,6 @@
#include <string>
#include <LibUtilities/BasicUtils/ErrorUtil.hpp>
#include <LibUtilities/BasicUtils/MutexTypeDefs.h>
#ifndef MAX_PARAM
#define MAX_PARAM 5 // default maximum number of parameters to support
......@@ -66,6 +67,8 @@ namespace Nektar
// Generate parameter typenames with default type of 'none'
#define FACTORY_print(z, n, data) BOOST_PP_CAT(data, n) = none
typedef boost::unique_lock<boost::shared_mutex> WriteLock;
typedef boost::shared_lock<boost::shared_mutex> ReadLock;
/**
* @class NekFactory
......@@ -322,7 +325,7 @@ namespace Nektar
TMapFactory mMapFactory;
SharedMutex m_mutex;
boost::shared_mutex m_mutex;
};
......@@ -344,6 +347,11 @@ namespace Nektar
#define n BOOST_PP_ITERATION()
// Define macro for printing the non-required template parameters
#define FACTORY_print(z, n, data) data
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/locks.hpp>
typedef boost::unique_lock<boost::shared_mutex> WriteLock;
typedef boost::shared_lock<boost::shared_mutex> ReadLock;
template < typename tKey,
typename tBase BOOST_PP_COMMA_IF(n)
......@@ -492,7 +500,7 @@ namespace Nektar
NekFactory& operator=(const NekFactory& rhs);
TMapFactory mMapFactory;
SharedMutex m_mutex;
boost::shared_mutex m_mutex;
};
#undef n
......
......@@ -41,10 +41,11 @@
#include <boost/function.hpp>
#include <boost/call_traits.hpp>
#include <boost/concept_check.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread/locks.hpp>
#include <boost/shared_ptr.hpp>
#include <LibUtilities/BasicUtils/ErrorUtil.hpp>
#include <LibUtilities/BasicUtils/MutexTypeDefs.h>
namespace Nektar
{
......@@ -52,6 +53,9 @@ namespace Nektar
{
using namespace std;
typedef boost::unique_lock<boost::shared_mutex> WriteLock;
typedef boost::shared_lock<boost::shared_mutex> ReadLock;
template <typename KeyType>
struct defOpLessCreator
{
......@@ -315,12 +319,12 @@ namespace Nektar
static FlagContainerPool m_managementEnabledContainerPool;
CreateFuncType m_globalCreateFunc;
CreateFuncContainer m_keySpecificCreateFuncs;
static SharedMutex m_mutex;
static boost::shared_mutex m_mutex;
};
template <typename KeyType, typename ValueT, typename opLessCreator> typename NekManager<KeyType, ValueT, opLessCreator>::ValueContainerPool NekManager<KeyType, ValueT, opLessCreator>::m_ValueContainerPool;
template <typename KeyType, typename ValueT, typename opLessCreator> typename NekManager<KeyType, ValueT, opLessCreator>::FlagContainerPool NekManager<KeyType, ValueT, opLessCreator>::m_managementEnabledContainerPool;
template <typename KeyType, typename ValueT, typename opLessCreator>
SharedMutex NekManager<KeyType, ValueT, opLessCreator>::m_mutex;
typename boost::shared_mutex NekManager<KeyType, ValueT, opLessCreator>::m_mutex;
}
}
......
......@@ -38,6 +38,8 @@
#include <queue>
#include <vector>
#include <boost/thread/mutex.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/thread.hpp>
#include <boost/enable_shared_from_this.hpp>
......@@ -45,8 +47,6 @@
#include <LibUtilities/BasicUtils/NekFactory.hpp>
#include <loki/Singleton.h>
#include <LibUtilities/BasicUtils/MutexTypeDefs.h>
namespace Nektar
{
namespace Thread
......@@ -321,6 +321,9 @@ class ThreadManager : public boost::enable_shared_from_this<ThreadManager>
}
};
typedef boost::unique_lock<boost::shared_mutex> WriteLock;
typedef boost::shared_lock<boost::shared_mutex> ReadLock;
/**
* A class to manage multiple ThreadManagers. It also acts as a cut-out during
* static initialisation, where code attempts to grab a ThreadManager before any
......@@ -342,7 +345,7 @@ class ThreadMaster
{
private:
std::vector<ThreadManagerSharedPtr> m_threadManagers;
LibUtilities::SharedMutex m_mutex;
boost::shared_mutex m_mutex;
std::string m_threadingType;
public:
......
......@@ -36,7 +36,6 @@
#include <LibUtilities/BasicUtils/Vmath.hpp>
#include <LibUtilities/BasicConst/NektarUnivTypeDefs.hpp>
#include <LibUtilities/LibUtilitiesDeclspec.h>
#include <LibUtilities/BasicUtils/MutexTypeDefs.h>
namespace Vmath
{
......@@ -132,14 +131,14 @@ namespace Vmath
#undef EPS
#undef RNMX
static Nektar::LibUtilities::Mutex mutex;
static boost::mutex mutex;
template LIB_UTILITIES_EXPORT Nektar::NekDouble ran2 (long* idum);
/// \brief Fills a vector with white noise.
template<class T> void FillWhiteNoise( int n, const T eps, T *x, const int incx, int outseed)
{
// Protect the static vars here and in ran2
Nektar::LibUtilities::ScopedLock l(mutex);
boost::mutex::scoped_lock l(mutex);
while( n-- )
{
static int iset = 0;
......
......@@ -18,7 +18,6 @@ SET(BasicUtilsHeaders
./BasicUtils/MeshEntities.hpp
./BasicUtils/MeshPartition.h
./BasicUtils/MeshPartitionMetis.h
./BasicUtils/MutexTypeDefs.h
./BasicUtils/NekManager.hpp
./BasicUtils/NekFactory.hpp
./BasicUtils/NekPtr.hpp
......
......@@ -40,12 +40,12 @@
#include <boost/thread/tss.hpp>
#include <boost/pool/pool.hpp>
#include <boost/thread/mutex.hpp>
#include <loki/Singleton.h>
#include <map>
#include <LibUtilities/BasicUtils/ErrorUtil.hpp>
#include <LibUtilities/LibUtilitiesDeclspec.h>
#include <LibUtilities/BasicUtils/MutexTypeDefs.h>
#include <cstring>
......@@ -100,7 +100,7 @@ namespace Nektar
/// \throw std::bad_alloc if memory is exhausted.
void* Allocate()
{
LibUtilities::ScopedLock l(m_mutex);
boost::mutex::scoped_lock l(m_mutex);
void* result = m_pool->malloc();
#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
......@@ -116,7 +116,7 @@ namespace Nektar
/// from this pool. Doing this will result in undefined behavior.
void Deallocate(const void* p)
{
LibUtilities::ScopedLock l(m_mutex);
boost::mutex::scoped_lock l(m_mutex);
#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
// The idea here is to fill the returned memory with some known
// pattern, then detect that pattern on the allocate. If the
......@@ -135,7 +135,7 @@ namespace Nektar
//boost::thread_specific_ptr<boost::pool<> > m_pool;
boost::pool<>* m_pool;
size_t m_blockSize;
LibUtilities::Mutex m_mutex;
boost::mutex m_mutex;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment