Skip to content

Commit

Permalink
Provide an abstraction of mutexes (currently implemented in terms of …
Browse files Browse the repository at this point in the history
…pthread_mutex)
  • Loading branch information
devreal committed Jan 12, 2017
1 parent 4347086 commit e2b311e
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
16 changes: 16 additions & 0 deletions CMakeExt/Threading.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


set(ENABLE_MULTITHREADING ${ENABLE_MULTITHREADING}
PARENT_SCOPE)

if (ENABLE_MULTITHREADING)

# Find support for pthreads
find_package(Threads REQUIRED)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} -pthread -DDART_ENABLE_THREADING -DHAVE_PTHREADS")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -pthread -DDART_ENABLE_THREADING -DHAVE_PTHREADS")
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -pthread")
endif()
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ option(ENABLE_HDF5
"Specify whether HDF5 features are enabled" on)
option(ENABLE_NASTYMPI
"Specify whether the NastyMPI proxy should be enabled" off)
option(ENABLE_MULTITHREADING
"Specify whether support for multithreading should be compiled" off)

if (BUILD_COVERAGE_TESTS)
set(BUILD_TESTS TRUE CACHE BOOLEAN
Expand Down Expand Up @@ -127,6 +129,9 @@ endif()
if (ENABLE_NASTYMPI)
include(${CMAKE_SOURCE_DIR}/CMakeExt/NastyMPI.cmake)
endif()
if (ENABLE_MULTITHREADING)
include(${CMAKE_SOURCE_DIR}/CMakeExt/Threading.cmake)
endif()

# prepare StaticConfig.h generation
include(${CMAKE_SOURCE_DIR}/CMakeExt/GenerateConfig.cmake)
Expand Down Expand Up @@ -282,6 +287,8 @@ message(INFO "HDF5 support: (ENABLE_HDF5) "
${ENABLE_HDF5})
message(INFO "Enabled DART backends: (DART_IMPLEMENTATIONS) "
${DART_IMPLEMENTATIONS})
message(INFO "Enable multithreading: (ENABLE_MULTITHREADING) "
${ENABLE_MULTITHREADING})
message(INFO "C compiler id: ${CMAKE_C_COMPILER_ID}")
message(INFO "C++ compiler id: ${CMAKE_CXX_COMPILER_ID}")
if (MPI_FOUND)
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ rm -Rf $BUILD_DIR/*
-DDART_IF_VERSION=3.2 \
-DINSTALL_PREFIX=$HOME/opt/dash-0.3.0/ \
-DDART_IMPLEMENTATIONS=mpi \
-DENABLE_MULTITHREADING=ON \
-DENABLE_DEVELOPER_COMPILER_WARNINGS=OFF \
-DENABLE_EXTENDED_COMPILER_WARNINGS=OFF \
-DENABLE_LT_OPTIMIZATION=OFF \
Expand Down
77 changes: 77 additions & 0 deletions dart-impl/base/include/dash/dart/base/mutex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#ifndef DASH_DART_BASE_MUTEX__H_
#define DASH_DART_BASE_MUTEX__H_

#include <dash/dart/if/dart_types.h>


#ifdef HAVE_PTHREADS
#include <pthread.h>
#endif

typedef struct dart_mutex {
#ifdef HAVE_PTHREADS
pthread_mutex_t mutex;
#endif
} dart_mutex_t;

static inline
dart_ret_t
dart_mutex_init(dart_mutex_t *mutex)
{
#ifdef HAVE_PTHREADS
pthread_mutex_init(&mutex->mutex, NULL);
return DART_OK;
#else
return DART_ERR_INVAL;
#endif
}

static inline
dart_ret_t
dart_mutex_lock(dart_mutex_t *mutex)
{
#ifdef HAVE_PTHREADS
pthread_mutex_lock(&mutex->mutex);
return DART_OK;
#else
return DART_ERR_INVAL;
#endif
}

static inline
dart_ret_t
dart_mutex_unlock(dart_mutex_t *mutex)
{
#ifdef HAVE_PTHREADS
pthread_mutex_unlock(&mutex->mutex);
return DART_OK;
#else
return DART_ERR_INVAL;
#endif
}

static inline
dart_ret_t
dart_mutex_trylock(dart_mutex_t *mutex)
{
#ifdef HAVE_PTHREADS
pthread_mutex_trylock(&mutex->mutex);
return DART_OK;
#else
return DART_ERR_INVAL;
#endif
}


dart_ret_t
dart_mutex_destroy(dart_mutex_t *mutex)
{
#ifdef HAVE_PTHREADS
pthread_mutex_destroy(&mutex->mutex);
return DART_OK;
#else
return DART_ERR_INVAL;
#endif
}

#endif /* DASH_DART_BASE_MUTEX__H_ */

0 comments on commit e2b311e

Please sign in to comment.