diff options
| author | Jason Evans <jasone@canonware.com> | 2014-01-22 19:11:22 (GMT) |
|---|---|---|
| committer | Jason Evans <jasone@canonware.com> | 2014-01-22 19:11:22 (GMT) |
| commit | cc47dde16203a6ae7eb685b53e1ae501f3869bc6 (patch) | |
| tree | 74e81d65651b2ca7e294a857797dda6635177454 /test/src/mtx.c | |
| parent | 0135fb806e4137dc9cdf152541926a2bc95e33f0 (diff) | |
| parent | 798a48103014aabf8afb3d7efff90399a466dd8c (diff) | |
| download | jemalloc-3.5.0.zip jemalloc-3.5.0.tar.gz jemalloc-3.5.0.tar.bz2 | |
Merge branch 'dev'3.5.0
Diffstat (limited to 'test/src/mtx.c')
| -rw-r--r-- | test/src/mtx.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/test/src/mtx.c b/test/src/mtx.c new file mode 100644 index 0000000..41b95d5 --- /dev/null +++ b/test/src/mtx.c @@ -0,0 +1,62 @@ +#include "test/jemalloc_test.h" + +bool +mtx_init(mtx_t *mtx) +{ + +#ifdef _WIN32 + if (!InitializeCriticalSectionAndSpinCount(&mtx->lock, _CRT_SPINCOUNT)) + return (true); +#elif (defined(JEMALLOC_OSSPIN)) + mtx->lock = 0; +#else + pthread_mutexattr_t attr; + + if (pthread_mutexattr_init(&attr) != 0) + return (true); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT); + if (pthread_mutex_init(&mtx->lock, &attr) != 0) { + pthread_mutexattr_destroy(&attr); + return (true); + } + pthread_mutexattr_destroy(&attr); +#endif + return (false); +} + +void +mtx_fini(mtx_t *mtx) +{ + +#ifdef _WIN32 +#elif (defined(JEMALLOC_OSSPIN)) +#else + pthread_mutex_destroy(&mtx->lock); +#endif +} + +void +mtx_lock(mtx_t *mtx) +{ + +#ifdef _WIN32 + EnterCriticalSection(&mtx->lock); +#elif (defined(JEMALLOC_OSSPIN)) + OSSpinLockLock(&mtx->lock); +#else + pthread_mutex_lock(&mtx->lock); +#endif +} + +void +mtx_unlock(mtx_t *mtx) +{ + +#ifdef _WIN32 + LeaveCriticalSection(&mtx->lock); +#elif (defined(JEMALLOC_OSSPIN)) + OSSpinLockUnlock(&mtx->lock); +#else + pthread_mutex_unlock(&mtx->lock); +#endif +} |
