Simplify mutex code by providing stubs that are do nothing during

CHAISCRIPT_NO_THREADS builds.
This commit is contained in:
Jason Turner
2011-03-25 22:49:17 -06:00
parent 58e5df0a9a
commit 92c836c58a
6 changed files with 106 additions and 103 deletions

View File

@@ -13,6 +13,14 @@
#pragma message ("ChaiScript is compiling without thread safety.")
#endif
/// \file
///
/// This file contains code necessary for thread support in ChaiScript.
/// If the compiler definition CHAISCRIPT_NO_THREADS is defined then thread safety
/// is disabled in ChaiScript. This has the result that some code is faster, because mutex locks are not required.
/// It also has the side effect that the chaiscript::ChaiScript object may not be accessed from more than
/// one thread simultaneously.
namespace chaiscript
{
namespace detail
@@ -21,6 +29,12 @@ namespace chaiscript
{
#ifndef CHAISCRIPT_NO_THREADS
using boost::unique_lock;
using boost::shared_lock;
using boost::lock_guard;
using boost::shared_mutex;
using boost::recursive_mutex;
template<typename T>
class Thread_Storage
@@ -51,6 +65,32 @@ namespace chaiscript
};
#else
template<typename T>
class unique_lock
{
public:
unique_lock(T &) {}
};
template<typename T>
class shared_lock
{
public:
shared_lock(T &) {}
void unlock() {}
};
template<typename T>
class lock_guard
{
public:
lock_guard(T &) {}
};
class shared_mutex { };
class recursive_mutex {};
template<typename T>
class Thread_Storage