Commit 1e07311f authored by Leif Walsh's avatar Leif Walsh Committed by Yoni Fogel

refs #5368 add implementations for some things in the portability layer


git-svn-id: file:///svn/toku/tokudb@48334 c7de825b-a66e-492c-adef-691d508d4ae1
parent 69161150
......@@ -23,18 +23,21 @@
#include <sys/file.h>
#if defined(HAVE_SYSCALL_H)
# include <syscall.h>
#elif defined(HAVE_SYS_SYSCALL_H)
#endif
#if defined(HAVE_SYS_SYSCALL_H)
# include <sys/syscall.h>
# if !defined(__NR_gettid) && defined(SYS_gettid)
# define __NR_gettid SYS_gettid
# endif
#endif
#if defined(HAVE_SYS_SYSCTL_H)
# include <sys/sysctl.h>
#endif
#if defined(HAVE_PTHREAD_NP_H)
# include <pthread_np.h>
#endif
#include <inttypes.h>
#include <sys/time.h>
#include <sys/resource.h>
#if defined(HAVE_SYS_RESOURCE_H)
# include <sys/resource.h>
#endif
#include <sys/statvfs.h>
#include "toku_portability.h"
#include "toku_os.h"
......@@ -59,7 +62,15 @@ toku_os_getpid(void) {
int
toku_os_gettid(void) {
#if defined(__NR_gettid)
return syscall(__NR_gettid);
#elif defined(SYS_gettid)
return syscall(SYS_gettid);
#elif defined(HAVE_PTHREAD_GETTHREADID_NP)
return pthread_getthreadid_np();
#else
# error "no implementation of gettid available"
#endif
}
int
......@@ -325,21 +336,21 @@ toku_get_processor_frequency_cpuinfo(uint64_t *hzret) {
}
static int
toku_get_processor_frequency_sysctl(uint64_t *hzret) {
toku_get_processor_frequency_sysctl(const char * const cmd, uint64_t *hzret) {
int r = 0;
static char cmd[] = "sysctl hw.cpufrequency";
FILE *fp = popen(cmd, "r");
if (!fp) {
r = EINVAL; // popen doesn't return anything useful in errno,
// gotta pick something
goto exit;
}
r = fscanf(fp, "hw.cpufrequency: %" SCNu64, hzret);
r = fscanf(fp, "%" SCNu64, hzret);
if (r != 1) {
r = get_maybe_error_errno();
} else {
r = 0;
}
pclose(fp);
exit:
return r;
......@@ -352,7 +363,9 @@ toku_os_get_processor_frequency(uint64_t *hzret) {
if (r != 0)
r = toku_get_processor_frequency_cpuinfo(hzret);
if (r != 0)
r = toku_get_processor_frequency_sysctl(hzret);
r = toku_get_processor_frequency_sysctl("sysctl -n hw.cpufrequency", hzret);
if (r != 0)
r = toku_get_processor_frequency_sysctl("sysctl -n machdep.tsc_freq", hzret);
return r;
}
......
......@@ -11,15 +11,26 @@
#include "toku_os.h"
#if defined(HAVE_SYSCALL_H)
# include <syscall.h>
#elif defined(HAVE_SYS_SYSCALL_H)
#endif
#if defined(HAVE_SYS_SYSCALL_H)
# include <sys/syscall.h>
# if !defined(__NR_gettid) && defined(SYS_gettid)
# define __NR_gettid SYS_gettid
# endif
#endif
#if defined(HAVE_PTHREAD_NP_H)
# include <pthread_np.h>
#endif
// since we implement the same thing here as in toku_os_gettid, this test
// is pretty pointless
static int gettid(void) {
#if defined(__NR_gettid)
return syscall(__NR_gettid);
#elif defined(SYS_gettid)
return syscall(SYS_gettid);
#elif defined(HAVE_PTHREAD_GETTHREADID_NP)
return pthread_getthreadid_np();
#else
# error "no implementation of gettid available"
#endif
}
int main(void) {
......
......@@ -10,6 +10,9 @@
#if defined(HAVE_BYTESWAP_H)
# include <byteswap.h>
#elif defined(HAVE_SYS_ENDIAN_H)
# include <sys/endian.h>
# define bswap_64 bswap64
#elif defined(HAVE_LIBKERN_OSBYTEORDER_H)
# include <libkern/OSByteOrder.h>
# define bswap_64 OSSwapInt64
......
......@@ -9,7 +9,14 @@
int toku_pthread_yield(void) {
#if defined(HAVE_PTHREAD_YIELD)
# if defined(PTHREAD_YIELD_RETURNS_INT)
return pthread_yield();
# elif defined(PTHREAD_YIELD_RETURNS_VOID)
pthread_yield();
return 0;
# else
# error "don't know what pthread_yield() returns"
# endif
#elif defined(HAVE_PTHREAD_YIELD_NP)
pthread_yield_np();
return 0;
......
......@@ -37,7 +37,14 @@ typedef struct toku_mutex {
#endif
} toku_mutex_t;
#if defined(__APPLE__)
#if defined(__FreeBSD__)
static const toku_mutex_t ZERO_MUTEX_INITIALIZER = {0};
# if TOKU_PTHREAD_DEBUG
static const toku_mutex_t TOKU_MUTEX_INITIALIZER = { .pmutex = PTHREAD_MUTEX_INITIALIZER, .owner = 0, .locked = false, .valid = true };
# else
static const toku_mutex_t TOKU_MUTEX_INITIALIZER = { .pmutex = PTHREAD_MUTEX_INITIALIZER };
# endif
#elif defined(__APPLE__)
static const toku_mutex_t ZERO_MUTEX_INITIALIZER = {{0}};
# if TOKU_PTHREAD_DEBUG
static const toku_mutex_t TOKU_MUTEX_INITIALIZER = { .pmutex = PTHREAD_MUTEX_INITIALIZER, .owner = 0, .locked = false, .valid = true };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment