Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,53 @@
(addr = (void*)_aligned_malloc((size), (align)))
#define free_align(addr) _aligned_free(addr)

#ifdef __MINGW32__
#ifndef spin_t
// spinlock
#include <pthread.h>
#define spin_t pthread_spinlock_t
#define spin_init(arg) pthread_spin_init(arg, PTHREAD_PROCESS_SHARED)
#define spin_lock(arg) pthread_spin_lock(arg)
#define spin_trylock(arg) \
(pthread_spin_trylock(arg) == 0)
#define spin_unlock(arg) pthread_spin_unlock(arg)
#define spin_destroy(arg) pthread_spin_destroy(arg)
#define SPIN_INITIALIZER (spin_t)(1)
#endif
#ifndef mutex_t
// mutex
#include <pthread.h>
#define mutex_t pthread_mutex_t
#define mutex_init(arg) pthread_mutex_init(arg, NULL)
#define mutex_lock(arg) pthread_mutex_lock(arg)
#define mutex_trylock(arg) \
(pthread_mutex_trylock(arg) == 0)
#define mutex_unlock(arg) pthread_mutex_unlock(arg)
#define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#define mutex_destroy(arg) pthread_mutex_destroy(arg)
#endif
#ifndef thread_t
// thread
#include <pthread.h>
#define thread_t pthread_t
#define thread_cond_t pthread_cond_t
#define thread_create(tid, func, args) \
pthread_create((tid), NULL, (func), (args))
#define thread_join(tid, ret) pthread_join(tid, ret)
#define thread_cancel(tid) pthread_cancel(tid)
#define thread_exit(code) pthread_exit(code)
#define thread_cond_init(cond) pthread_cond_init(cond, NULL)
#define thread_cond_destroy(cond) pthread_cond_destroy(cond)
#define thread_cond_wait(cond, mutex) pthread_cond_wait(cond, mutex)
#define thread_cond_timedwait(cond, mutex, ms) \
{ \
struct timespec ts = convert_reltime_to_abstime(ms); \
pthread_cond_timedwait(cond, mutex, &ts); \
}
#define thread_cond_signal(cond) pthread_cond_signal(cond)
#define thread_cond_broadcast(cond) pthread_cond_broadcast(cond)
#endif
#else
#ifndef spin_t
// spinlock
#define spin_t CRITICAL_SECTION
Expand Down Expand Up @@ -474,6 +521,7 @@
#define thread_cond_signal(cond) WakeConditionVariable(cond)
#define thread_cond_broadcast(cond) WakeAllConditionVariable(cond)
#endif
#endif

#elif __CYGWIN__
// cygwin compatiable
Expand Down
12 changes: 6 additions & 6 deletions src/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ extern "C" {
#endif

// RW Lock(s)
#if !defined(WIN32) && !defined(_WIN32)
#if (!defined(WIN32) && !defined(_WIN32)) || defined(__MINGW32__)
#include <pthread.h>
typedef pthread_rwlock_t fdb_rw_lock;
#else // WINDOWS
Expand All @@ -176,7 +176,7 @@ typedef SRWLOCK fdb_rw_lock;
// ---> RW Lock

INLINE int init_rw_lock(fdb_rw_lock *lock) {
#if !defined(WIN32) && !defined(_WIN32)
#if (!defined(WIN32) && !defined(_WIN32)) || defined(__MINGW32__)
int rv = pthread_rwlock_init(lock, NULL);
return rv;
#else
Expand All @@ -197,7 +197,7 @@ INLINE int destroy_rw_lock(fdb_rw_lock *lock) {
}

INLINE int reader_lock(fdb_rw_lock *lock) {
#if !defined(WIN32) && !defined(_WIN32)
#if (!defined(WIN32) && !defined(_WIN32)) || defined(__MINGW32__)
int result = pthread_rwlock_rdlock(lock);
if (result != 0) {
fprintf(stderr, "pthread_rwlock_rdlock returned %d (%s)\n",
Expand All @@ -211,7 +211,7 @@ INLINE int reader_lock(fdb_rw_lock *lock) {
}

INLINE int reader_unlock(fdb_rw_lock *lock) {
#if !defined(WIN32) && !defined(_WIN32)
#if (!defined(WIN32) && !defined(_WIN32)) || defined(__MINGW32__)
int result = pthread_rwlock_unlock(lock);
if (result != 0) {
fprintf(stderr, "pthread_rwlock_unlock returned %d (%s)\n",
Expand All @@ -225,7 +225,7 @@ INLINE int reader_unlock(fdb_rw_lock *lock) {
}

INLINE int writer_lock(fdb_rw_lock *lock) {
#if !defined(WIN32) && !defined(_WIN32)
#if (!defined(WIN32) && !defined(_WIN32)) || defined(__MINGW32__)
int result = pthread_rwlock_wrlock(lock);
if (result != 0) {
fprintf(stderr, "pthread_rwlock_wrlock returned %d (%s)\n",
Expand All @@ -239,7 +239,7 @@ INLINE int writer_lock(fdb_rw_lock *lock) {
}

INLINE int writer_unlock(fdb_rw_lock *lock) {
#if !defined(WIN32) && !defined(_WIN32)
#if (!defined(WIN32) && !defined(_WIN32)) || defined(__MINGW32__)
int result = pthread_rwlock_unlock(lock);
if (result != 0) {
fprintf(stderr, "pthread_rwlock_unlock returned %d (%s)\n",
Expand Down
2 changes: 2 additions & 0 deletions src/filemgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#pragma once

#include <sys/types.h>
#if !defined(__MINGW32__)
#include <sys/stat.h>
#endif
#include <stdint.h>
#include <errno.h>

Expand Down
2 changes: 1 addition & 1 deletion src/kvs_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BtreeV2;
// _Atomic_address::store(void *) which breaks const qualifier
// So to work around this, declare func_name_t as char * on windows only
// compatible with __FUNCTION__ type.
#if defined(WIN32) || defined(_WIN32)
#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
#define BEGIN_HANDLE_BUSY(H) ((H)->beginBusy(__FUNCTION__))
#define END_HANDLE_BUSY(H) ((H)->endBusy(__FUNCTION__))
typedef char * func_name_t;
Expand Down
4 changes: 4 additions & 0 deletions tests/include/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include <time.h>
#if !defined(WIN32) && !defined(_WIN32)
#include <sys/time.h>
#else
#if defined (__MINGW32__)
#include <sys/time.h>
#endif
#endif
#include "time_utils.h"

Expand Down
4 changes: 3 additions & 1 deletion utils/gettimeofday_vs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
#include <winsock2.h>
#undef NOMINMAX
#include <time.h>
#include <Windows.h>
#include <windows.h>

#ifndef __MINGW32__
struct timezone
{
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};
#endif

int gettimeofday_vs(struct timeval *tv, void *tz);

16 changes: 13 additions & 3 deletions utils/time_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern "C" hrtime_t gethrtime_period(void)
}
#endif // _PLATFORM_LIB_AVAILABLE

#if defined(WIN32) || defined(_WIN32)
#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)

#ifndef _PLATFORM_LIB_AVAILABLE
void usleep(unsigned int usec)
Expand Down Expand Up @@ -118,10 +118,18 @@ void decaying_usleep(unsigned int *sleep_time, unsigned int max_sleep_time) {
*/
ts_nsec get_monotonic_ts() {
ts_nsec ts = 0;
#if defined(WIN32)
#if defined(WIN32) || defined (_WIN32)
#ifdef __MINGW32__
struct timespec tm;
if (clock_gettime(CLOCK_MONOTONIC, &tm) == -1) {
abort();
}
ts = tm.tv_nsec;
#else
LARGE_INTEGER _ts;
QueryPerformanceCounter(&_ts);
ts = _ts.QuadPart;
#endif
#elif defined(__APPLE__)
long time = mach_absolute_time();

Expand Down Expand Up @@ -153,10 +161,12 @@ ts_nsec ts_diff(ts_nsec start, ts_nsec end)
} else {
diff = end-start;
}
#if defined(WIN32)
#if defined(WIN32) || defined (_WIN32)
#ifndef __MINGW32__
LARGE_INTEGER Pf;
QueryPerformanceFrequency(&Pf);
return diff / (Pf.QuadPart/1000000);
#endif
#else
return diff/1000;
#endif // defined(WIN32)
Expand Down
6 changes: 4 additions & 2 deletions utils/time_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#pragma once

#if defined(WIN32) || defined(_WIN32)
#if (defined(WIN32) || defined(_WIN32)) && !defined(__MINGW32__)
#include <winsock2.h>
#include <Windows.h>
#else
Expand Down Expand Up @@ -50,13 +50,15 @@ uint64_t timeval_to_us(struct timeval tv);
#else
// If platform library has not been included, usleep
// needs to be explicitly defined for windows.
#if !defined(__MINGW32__)
void usleep(unsigned int useconds);
#endif
#endif // _PLATFORM_LIB_AVAILABLE
#endif // defined(WIN32) || defined(_WIN32)

void decaying_usleep(unsigned int *sleep_time, unsigned int max_sleep_time);

#if !defined(WIN32) && !defined(_WIN32)
#if (!defined(WIN32) && !defined(_WIN32)) || defined(__MINGW32__)
struct timespec convert_reltime_to_abstime(unsigned int ms);
#endif