-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide an abstraction of mutexes (currently implemented in terms of …
…pthread_mutex)
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ |