Skip to content

Commit

Permalink
Refs #4554 trying a boost mutex class, mostly to see if it compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Janik Zikovsky committed Jan 18, 2012
1 parent f6fc190 commit 5dd3ae3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Code/Mantid/Build/CMake/CommonSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ include ( VersionNumber )
# Look for dependencies - bail out if any not found
###########################################################################

find_package ( Boost REQUIRED signals date_time regex )
find_package ( Boost REQUIRED signals date_time regex thread )
include_directories( SYSTEM ${Boost_INCLUDE_DIRS} )
add_definitions ( -DBOOST_ALL_DYN_LINK )
# Need this defined globally for our log time values
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Framework/Kernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ set ( TEST_FILES
test/MatrixPropertyTest.h
test/MatrixTest.h
test/MemoryTest.h
test/MutexTest.h
test/MersenneTwisterTest.h
test/MultiFileNameParserTest.h
test/NeutronAtomTest.h
Expand Down
52 changes: 52 additions & 0 deletions Code/Mantid/Framework/Kernel/test/MutexTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef MUTEXTEST_H
#define MUTEXTEST_H

#include <cxxtest/TestSuite.h>
#include "MantidKernel/MultiThreaded.h"
#include <boost/thread.hpp>

using namespace Mantid::Kernel;

boost::shared_mutex _access;
void reader()
{
boost::shared_lock< boost::shared_mutex > lock(_access);
// do work here, without anyone having exclusive access
}

void conditional_writer()
{
boost::upgrade_lock< boost::shared_mutex > lock(_access);
// do work here, without anyone having exclusive access

if (true)
{
boost::upgrade_to_unique_lock< boost::shared_mutex > uniqueLock(lock);
// do work here, but now you have exclusive access
}

// do more work here, without anyone having exclusive access
}

void unconditional_writer()
{
boost::unique_lock< boost::shared_mutex > lock( _access );
// do work here, with exclusive access
}


class MutexTest : public CxxTest::TestSuite
{
public:

void test_1()
{

}

};


#endif /* MUTEXTEST_H */


0 comments on commit 5dd3ae3

Please sign in to comment.