[t:4944] closes #4944. Remove all windows code and libraries.

We can resurrect this if necessary in the future and we want to support windows.
Right now it just gets in the way and makes checkouts larger."


git-svn-id: file:///svn/toku/tokudb@43969 c7de825b-a66e-492c-adef-691d508d4ae1
This commit is contained in:
Yoni Fogel 2013-04-17 00:00:37 -04:00
parent 5da2303bbc
commit 6de3fadd01
62 changed files with 0 additions and 7451 deletions

View file

@ -1,34 +0,0 @@
# -*- Mode: Makefile -*-
.DEFAULT_GOAL=install
TOKUROOT=../
INCLUDEDIRS=-I. -I$(TOKUROOT)ft
SKIP_LIBPORTABILITYRULE=1
include $(TOKUROOT)toku_include/Makefile.include
OPT_AROPT=-qnoipo #Disable ipo for lib creation even when optimization is on.
SRCS = $(wildcard *.c)
OBJS = $(patsubst %.c,%.$(OEXT),$(SRCS))
TARGET = libtokuportability.$(AEXT)
build install: $(LIBPORTABILITY) $(PTHREAD_LIB)
PTHREAD_LIB_CRUNTIME=$(TOKUROOT)windows/lib/$(CRUNTIME)/pthreadVC2.dll
$(PTHREAD_LIB): $(PTHREAD_LIB_CRUNTIME)
cp -u $< $@
$(LIBPORTABILITY): $(TARGET)
cp -u $< $@
$(TARGET): $(OBJS)
check: $(TARGET)
cd tests && $(MAKE) check
$(OBJS): CPPFLAGS += -DTOKU_WINDOWS_ALLOW_DEPRECATED
file.obj: CPPFLAGS += -DDONT_DEPRECATE_WRITES
clean:
rm -rf $(TARGET) $(LIBPORTABILITY) $(PTHREAD_LIB)
cd tests && $(MAKE) clean

View file

@ -1,44 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ifndef _TOKU_DIRENT_H
#define _TOKU_DIRENT_H
#include "toku_os_types.h"
#if defined(__cplusplus)
extern "C" {
#endif
//The DIR functions do not exist in windows, but the Linux API ends up
//just using a wrapper. We might convert these into an toku_os_* type api.
enum {
DT_UNKNOWN = 0,
DT_DIR = 4,
DT_REG = 8
};
struct dirent {
char d_name[_MAX_PATH];
unsigned char d_type;
};
struct __toku_windir;
typedef struct __toku_windir DIR;
DIR *opendir(const char *name);
struct dirent *readdir(DIR *dir);
int closedir(DIR *dir);
#ifndef NAME_MAX
#define NAME_MAX 255
#endif
#if defined(__cplusplus)
};
#endif
#endif

View file

@ -1,161 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <toku_portability.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <toku_assert.h>
#include <errno.h>
#include <direct.h>
#include <dirent.h>
#include <io.h>
#include <sys/stat.h>
#include <windows.h>
struct __toku_windir {
struct dirent ent;
struct _finddatai64_t data;
intptr_t handle;
BOOL finished;
};
DIR*
opendir(const char *name) {
char *format = NULL;
DIR *result = malloc(sizeof(*result));
int r;
if (!result) {
r = ENOMEM;
goto cleanup;
}
format = malloc(strlen(name)+2+1); //2 for /*, 1 for '\0'
if (!format) {
r = ENOMEM;
goto cleanup;
}
strcpy(format, name);
if (format[strlen(format)-1]=='/') format[strlen(format)-1]='\0';
strcat(format, "/*");
result->handle = _findfirsti64(format, &result->data);
// printf("%s:%d %p %d\n", __FILE__, __LINE__, result->handle, errno); fflush(stdout);
if (result->handle==-1L) {
if (errno==ENOENT) {
int64_t r_stat;
//ENOENT can mean a good directory with no files, OR
//a directory that does not exist.
struct _stat64 buffer;
format[strlen(format)-3] = '\0'; //Strip the "/*"
r_stat = _stati64(format, &buffer);
if (r_stat==0) {
//Empty directory.
result->finished = TRUE;
r = 0;
goto cleanup;
}
}
r = errno;
assert(r!=0);
goto cleanup;
}
result->finished = FALSE;
r = 0;
cleanup:
if (r!=0) {
if (result) free(result);
result = NULL;
}
if (format) free(format);
return result;
}
struct dirent*
readdir(DIR *dir) {
struct dirent *result;
int r;
if (dir->finished) {
errno = ENOENT;
result = NULL;
goto cleanup;
}
assert(dir->handle!=-1L);
strcpy(dir->ent.d_name, dir->data.name);
if (dir->data.attrib&_A_SUBDIR) dir->ent.d_type=DT_DIR;
else dir->ent.d_type=DT_REG;
r = _findnexti64(dir->handle, &dir->data);
if (r==-1L) dir->finished = TRUE;
result = &dir->ent;
cleanup:
return result;
}
int
closedir(DIR *dir) {
int r;
if (dir->handle==-1L) r = 0;
else r = _findclose(dir->handle);
free(dir);
return r;
}
#define SUPPORT_CYGWIN_STYLE_STAT 0
#define CYGWIN_ROOT_DIR_PREFIX "c:/cygwin"
#define CYGDRIVE_PREFIX "/cygdrive/"
int
toku_stat(const char *name, toku_struct_stat *statbuf) {
char new_name[strlen(name) + sizeof(CYGWIN_ROOT_DIR_PREFIX)];
int bytes;
#if SUPPORT_CYGWIN_STYLE_STAT
if (name[0] == '/') {
char *cygdrive = strstr(name, CYGDRIVE_PREFIX);
if (cygdrive==name && isalpha(name[strlen(CYGDRIVE_PREFIX)]))
bytes = snprintf(new_name, sizeof(new_name), "%c:%s", name[strlen(CYGDRIVE_PREFIX)], name+strlen(CYGDRIVE_PREFIX)+1); //handle /cygdrive/DRIVELETTER
else bytes = snprintf(new_name, sizeof(new_name), "%s%s", CYGWIN_ROOT_DIR_PREFIX, name); //handle /usr/local (for example)
}
else
#endif
bytes = snprintf(new_name, sizeof(new_name), "%s", name); //default
//Verify no overflow
assert(bytes>=0);
assert((size_t)bytes < sizeof(new_name));
int needdir = 0;
if (bytes>1 && new_name[bytes-1]=='/') {
//Strip trailing '/', but this implies it is a directory.
new_name[bytes-1] = '\0';
needdir = 1;
}
toku_struct_stat temp;
int r = _stati64(new_name, &temp);
if (r==0 && needdir && !(temp.st_mode&_S_IFDIR)) {
r = -1;
errno = ENOENT;
}
if (r==0) *statbuf = temp;
return r;
}
int
toku_fstat(int fd, toku_struct_stat *statbuf) {
int r = _fstati64(fd, statbuf);
return r;
}
int
toku_fsync_dirfd_without_accounting(DIR *dirp) {
//Believed to not be supported in windows.
//Possibly not needed
return 0;
}
int
toku_fsync_directory(const char *UU(fname)) {
return 0; // toku_fsync_dirfd
}
int
toku_fsync_dir_by_name_without_accounting(const char *dir_name) {
//Believed to not be supported in windows.
//Possibly not needed
return 0;
}

View file

@ -1,18 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ident "Copyright (c) 2007 Tokutek Inc. All rights reserved."
#ifndef ENDIAN_H
#define ENDIAN_H
#if defined(__BYTE_ORDER) || defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN)
#error Standards are defined for some reason
#endif
//Windows does not exist for big endian machines, only little endian
#define __LITTLE_ENDIAN (0x01020304)
#define __BIG_ENDIAN (0x04030201)
#define __BYTE_ORDER (__LITTLE_ENDIAN)
#endif

View file

@ -1,35 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <toku_portability.h>
#include <windows.h>
#include <toku_stdlib.h>
#include <toku_assert.h>
int
setenv(const char *name, const char *value, int overwrite) {
char * current = getenv(name);
BOOL exists = current!=NULL;
int r;
if (overwrite || !exists) {
char setstring[sizeof("=") + strlen(name) + strlen(value)];
int bytes = snprintf(setstring, sizeof(setstring), "%s=%s", name, value);
assert(bytes>=0);
assert((size_t)bytes < sizeof(setstring));
r = _putenv(setstring);
if (r==-1) {
errno = GetLastError();
goto cleanup;
}
}
r = 0;
cleanup:
return r;
}
int
unsetenv(const char *name) {
int r = setenv(name, "", 1);
return r;
}

View file

@ -1,614 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <toku_portability.h>
#include <stdio.h>
#include <toku_assert.h>
#include <stdint.h>
#include <unistd.h>
#include <windows.h>
#include <toku_atomic.h>
#include <toku_time.h>
#include <fcntl.h>
int64_t
pread(int fildes, void *buf, size_t nbyte, int64_t offset) {
HANDLE filehandle;
OVERLAPPED win_offset = {0};
filehandle = (HANDLE)_get_osfhandle(fildes);
int64_t r;
if (filehandle==INVALID_HANDLE_VALUE) {
r = errno; assert(r!=0);
goto cleanup;
}
win_offset.Offset = offset % (1LL<<32LL);
win_offset.OffsetHigh = offset / (1LL<<32LL);
DWORD bytes_read;
r = ReadFile(filehandle, buf, nbyte, &bytes_read, &win_offset);
if (!r) {
r = GetLastError();
if (r==ERROR_HANDLE_EOF) r = bytes_read;
else {
errno = r;
r = -1;
}
}
else r = bytes_read;
// printf("%s: %d %p %u %I64d %I64d\n", __FUNCTION__, fildes, buf, nbyte, offset, r); fflush(stdout);
cleanup:
return r;
}
int64_t
pwrite(int fildes, const void *buf, size_t nbyte, int64_t offset) {
HANDLE filehandle;
OVERLAPPED win_offset = {0};
filehandle = (HANDLE)_get_osfhandle(fildes);
int64_t r;
if (filehandle==INVALID_HANDLE_VALUE) {
r = -1;
assert(errno!=0);
goto cleanup;
}
win_offset.Offset = offset % (1LL<<32LL);
win_offset.OffsetHigh = offset / (1LL<<32LL);
DWORD bytes_written;
r = WriteFile(filehandle, buf, nbyte, &bytes_written, &win_offset);
if (!r) {
errno = GetLastError();
if (errno == ERROR_HANDLE_DISK_FULL ||
errno == ERROR_DISK_FULL) {
errno = ENOSPC;
}
r = -1;
}
else r = bytes_written;
// printf("%s: %d %p %u %I64d %I64d\n", __FUNCTION__, fildes, buf, nbyte, offset, r); fflush(stdout);
cleanup:
return r;
}
int
fsync(int fd) {
int r = _commit(fd);
return r;
}
int
ftruncate(int fd, toku_off_t offset) {
int r = _chsize_s(fd, offset);
if (r!=0) {
r = -1;
assert(errno!=0);
}
return r;
}
int
truncate(const char *path, toku_off_t length) {
int r;
int saved_errno;
int fd = open(path, _O_BINARY|_O_RDWR, _S_IREAD|_S_IWRITE);
if (fd<0) {
r = -1;
goto done;
}
r = ftruncate(fd, length);
saved_errno = errno;
if (r!=0) {
r = -1;
assert(errno!=0);
}
int r2 = close(fd);
if (r==0) {
r = r2;
}
else {
errno = saved_errno;
}
done:
return r;
}
static ssize_t (*t_write)(int, const void *, size_t) = NULL;
static ssize_t (*t_full_write)(int, const void *, size_t) = NULL;
static ssize_t (*t_pwrite)(int, const void *, size_t, toku_off_t) = NULL;
static ssize_t (*t_full_pwrite)(int, const void *, size_t, toku_off_t) = NULL;
static FILE * (*t_fdopen)(int, const char *) = NULL;
static FILE * (*t_fopen)(const char *, const char *) = NULL;
static int (*t_open)(const char *, int, int) = NULL; // no implementation of variadic form until needed
static int (*t_fclose)(FILE *) = NULL;
int
toku_set_func_write (ssize_t (*write_fun)(int, const void *, size_t)) {
t_write = write_fun;
return 0;
}
int
toku_set_func_full_write (ssize_t (*write_fun)(int, const void *, size_t)) {
t_full_write = write_fun;
return 0;
}
int
toku_set_func_pwrite (ssize_t (*pwrite_fun)(int, const void *, size_t, toku_off_t)) {
t_pwrite = pwrite_fun;
return 0;
}
int
toku_set_func_full_pwrite (ssize_t (*pwrite_fun)(int, const void *, size_t, toku_off_t)) {
t_full_pwrite = pwrite_fun;
return 0;
}
int
toku_set_func_fdopen(FILE * (*fdopen_fun)(int, const char *)) {
t_fdopen = fdopen_fun;
return 0;
}
int
toku_set_func_fopen(FILE * (*fopen_fun)(const char *, const char *)) {
t_fopen = fopen_fun;
return 0;
}
int
toku_set_func_open(int (*open_fun)(const char *, int, int)) {
t_open = open_fun;
return 0;
}
int
toku_set_func_fclose(int (*fclose_fun)(FILE*)) {
t_fclose = fclose_fun;
return 0;
}
static int toku_assert_on_write_enospc = 0;
static const int toku_write_enospc_sleep = 1;
static uint64_t toku_write_enospc_last_report; // timestamp of most recent report to error log
static time_t toku_write_enospc_last_time; // timestamp of most recent ENOSPC
static uint32_t toku_write_enospc_current; // number of threads currently blocked on ENOSPC
static uint64_t toku_write_enospc_total; // total number of times ENOSPC was returned from an attempt to write
void toku_set_assert_on_write_enospc(int do_assert) {
toku_assert_on_write_enospc = do_assert;
}
void
toku_fs_get_write_info(time_t *enospc_last_time, uint64_t *enospc_current, uint64_t *enospc_total) {
*enospc_last_time = toku_write_enospc_last_time;
*enospc_current = toku_write_enospc_current;
*enospc_total = toku_write_enospc_total;
}
//Print any necessary errors
//Return whether we should try the write again.
static void
try_again_after_handling_write_error(int fd, size_t len, ssize_t r_write) {
int try_again = 0;
assert(r_write < 0);
int errno_write = errno;
assert(errno_write != 0);
switch (errno_write) {
case EINTR: { //The call was interrupted by a signal before any data was written; see signal(7).
char err_msg[sizeof("Write of [] bytes to fd=[] interrupted. Retrying.") + 20+10]; //64 bit is 20 chars, 32 bit is 10 chars
snprintf(err_msg, sizeof(err_msg), "Write of [%"PRIu64"] bytes to fd=[%d] interrupted. Retrying.", (uint64_t)len, fd);
perror(err_msg);
fflush(stderr);
try_again = 1;
break;
}
case ENOSPC: {
if (toku_assert_on_write_enospc) {
char err_msg[sizeof("Failed write of [] bytes to fd=[].") + 20+10]; //64 bit is 20 chars, 32 bit is 10 chars
snprintf(err_msg, sizeof(err_msg), "Failed write of [%"PRIu64"] bytes to fd=[%d].", (uint64_t)len, fd);
perror(err_msg);
fflush(stderr);
int out_of_disk_space = 1;
assert(!out_of_disk_space); //Give an error message that might be useful if this is the only one that survives.
} else {
toku_sync_fetch_and_increment_uint64(&toku_write_enospc_total);
toku_sync_fetch_and_increment_uint32(&toku_write_enospc_current);
time_t tnow = time(0);
toku_write_enospc_last_time = tnow;
if (toku_write_enospc_last_report == 0 || tnow - toku_write_enospc_last_report >= 60) {
toku_write_enospc_last_report = tnow;
const int tstr_length = 26;
char tstr[tstr_length];
time_t t = time(0);
ctime_r(&t, tstr);
#if 0
//TODO: Find out how to get name from fd or handle
//In vista/server08 and later there exists GetFinalPathNameByHandle()
//In XP there exists:
// Example code that requires on kernel-level functions that
// are not guaranteed to stay around.
// http://rubyforge.org/pipermail/win32utils-devel/2008-May/001091.html
// Example code that works for files of length > 0 (according
// to author). This one appears to not require unsafe apis
// (not guaranteed to stick around)
// http://msdn.microsoft.com/en-us/library/aa366789%28VS.85%29.aspx
// Can we use runtime-checks to determine what version of OS we
// are using so we can choose which function to use?
// We CAN do compile-time checks, but then we would need to
// release multiple versions of binary.
// Is this important?
//
const int MY_MAX_PATH = 256;
char fname[MY_MAX_PATH], symname[MY_MAX_PATH+1];
sprintf(fname, "/proc/%d/fd/%d", getpid(), fd);
ssize_t n = readlink(fname, symname, MY_MAX_PATH);
if ((int)n == -1)
fprintf(stderr, "%.24s Tokudb No space when writing %"PRIu64" bytes to fd=%d ", tstr, (uint64_t) len, fd);
else {
tstr[n] = 0; // readlink doesn't append a NUL to the end of the buffer.
fprintf(stderr, "%.24s Tokudb No space when writing %"PRIu64" bytes to %*s ", tstr, (uint64_t) len, (int) n, symname);
}
#else
fprintf(stderr, "%.24s Tokudb No space when writing %"PRIu64" bytes to fd=%d ", tstr, (uint64_t) len, fd);
#endif
fprintf(stderr, "retry in %d second%s\n", toku_write_enospc_sleep, toku_write_enospc_sleep > 1 ? "s" : "");
fflush(stderr);
}
sleep(toku_write_enospc_sleep);
try_again = 1;
toku_sync_fetch_and_decrement_uint32(&toku_write_enospc_current);
break;
}
}
default:
break;
}
assert(try_again);
errno = errno_write;
}
void
toku_os_full_write (int fd, const void *buf, size_t len) {
const uint8_t *bp = (const uint8_t *) buf;
while (len > 0) {
ssize_t r;
if (t_full_write) {
r = t_full_write(fd, bp, len);
} else {
r = write(fd, bp, len);
}
if (r > 0) {
len -= r;
bp += r;
}
else {
try_again_after_handling_write_error(fd, len, r);
}
}
assert(len == 0);
}
int
toku_os_write (int fd, const void *buf, size_t len) {
const uint8_t *bp = (const uint8_t *) buf;
int result = 0;
while (len > 0) {
ssize_t r;
if (t_write) {
r = t_write(fd, bp, len);
} else {
r = write(fd, bp, len);
}
if (r < 0) {
result = errno;
break;
}
len -= r;
bp += r;
}
return result;
}
void
toku_os_full_pwrite (int fd, const void *buf, size_t len, toku_off_t off) {
const uint8_t *bp = (const uint8_t *) buf;
while (len > 0) {
ssize_t r;
if (t_full_pwrite) {
r = t_full_pwrite(fd, bp, len, off);
} else {
r = pwrite(fd, bp, len, off);
}
if (r > 0) {
len -= r;
bp += r;
off += r;
}
else {
try_again_after_handling_write_error(fd, len, r);
}
}
assert(len == 0);
}
ssize_t
toku_os_pwrite (int fd, const void *buf, size_t len, toku_off_t off) {
const uint8_t *bp = (const uint8_t *) buf;
ssize_t result = 0;
while (len > 0) {
ssize_t r;
if (t_pwrite) {
r = t_pwrite(fd, bp, len, off);
} else {
r = pwrite(fd, bp, len, off);
}
if (r < 0) {
result = errno;
break;
}
len -= r;
bp += r;
off += r;
}
return result;
}
FILE *
toku_os_fdopen(int fildes, const char *mode) {
FILE * rval;
if (t_fdopen)
rval = t_fdopen(fildes, mode);
else
rval = fdopen(fildes, mode);
return rval;
}
FILE *
toku_os_fopen(const char *filename, const char *mode){
FILE * rval;
if (t_fopen)
rval = t_fopen(filename, mode);
else
rval = fopen(filename, mode);
return rval;
}
int
toku_os_open(const char *path, int oflag, int mode) {
int rval;
if (t_open)
rval = t_open(path, oflag, mode);
else
rval = open(path, oflag, mode);
return rval;
}
int
toku_os_fclose(FILE * stream) {
int rval = -1;
if (t_fclose)
rval = t_fclose(stream);
else { // if EINTR, retry until success
while (rval != 0) {
rval = fclose(stream);
if (rval && (errno != EINTR))
break;
}
}
return rval;
}
int
toku_os_close (int fd) { // if EINTR, retry until success
int r = -1;
while (r != 0) {
r = close(fd);
if (r) {
int rr = errno;
if (rr!=EINTR) printf("rr=%d (%s)\n", rr, strerror(rr));
assert(rr==EINTR);
}
}
return r;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// fsync logic:
// t_fsync exists for testing purposes only
static int (*t_fsync)(int) = 0;
static uint64_t toku_fsync_count;
static uint64_t toku_fsync_time;
static uint64_t sched_fsync_count;
static uint64_t sched_fsync_time;
#if !TOKU_WINDOWS_HAS_ATOMIC_64
static toku_pthread_mutex_t fsync_lock;
#endif
int
toku_fsync_init(void) {
int r = 0;
#if !TOKU_WINDOWS_HAS_ATOMIC_64
r = toku_pthread_mutex_init(&fsync_lock, NULL); assert(r == 0);
#endif
return r;
}
int
toku_fsync_destroy(void) {
int r = 0;
#if !TOKU_WINDOWS_HAS_ATOMIC_64
r = toku_pthread_mutex_destroy(&fsync_lock); assert(r == 0);
#endif
return r;
}
int
toku_set_func_fsync(int (*fsync_function)(int)) {
t_fsync = fsync_function;
return 0;
}
static uint64_t get_tnow(void) {
struct timeval tv;
int r = gettimeofday(&tv, NULL); assert(r == 0);
return tv.tv_sec * 1000000ULL + tv.tv_usec;
}
// keep trying if fsync fails because of EINTR
static int
toku_file_fsync_internal (int fd, uint64_t *duration_p) {
uint64_t tstart = get_tnow();
int r = -1;
while (r != 0) {
if (t_fsync)
r = t_fsync(fd);
else
r = fsync(fd);
if (r) {
int rr = errno;
if (rr!=EINTR) printf("rr=%d (%s)\n", rr, strerror(rr));
assert(rr==EINTR);
}
}
uint64_t duration;
duration = get_tnow() - tstart;
#if TOKU_WINDOWS_HAS_ATOMIC_64
toku_sync_fetch_and_increment_uint64(&toku_fsync_count);
toku_sync_fetch_and_add_uint64(&toku_fsync_time, duration);
#else
//These two need to be fully 64 bit and atomic.
//The windows atomic add 64 bit is not available.
//toku_sync_fetch_and_add_uint64 (and increment) treat it as 32 bit, and
//would overflow.
//Even on 32 bit machines, aligned 64 bit writes/writes are atomic, so we just
//need to make sure there's only one writer for these two variables.
//Protect with a mutex. Fsync is rare/slow enough that this should be ok.
int r_mutex;
r_mutex = toku_pthread_mutex_lock(&fsync_lock); assert(r_mutex == 0);
toku_fsync_count++;
toku_fsync_time += duration;
r_mutex = toku_pthread_mutex_unlock(&fsync_lock); assert(r_mutex == 0);
#endif
if (duration_p) *duration_p = duration;
return r;
}
// keep trying if fsync fails because of EINTR
int
toku_file_fsync_without_accounting (int fd) {
int r = toku_file_fsync_internal(fd, NULL);
return r;
}
int
toku_file_fsync(int fd) {
uint64_t duration;
int r = toku_file_fsync_internal(fd, &duration);
#if TOKU_WINDOWS_HAS_ATOMIC_64
toku_sync_fetch_and_increment_uint64(&sched_fsync_count);
toku_sync_fetch_and_add_uint64(&sched_fsync_time, duration);
#else
//These two need to be fully 64 bit and atomic.
//The windows atomic add 64 bit is not available.
//toku_sync_fetch_and_add_uint64 (and increment) treat it as 32 bit, and
//would overflow.
//Even on 32 bit machines, aligned 64 bit writes/writes are atomic, so we just
//need to make sure there's only one writer for these two variables.
//Protect with a mutex. Fsync is rare/slow enough that this should be ok.
int r_mutex;
r_mutex = toku_pthread_mutex_lock(&fsync_lock); assert(r_mutex == 0);
sched_fsync_count++;
sched_fsync_time += duration;
r_mutex = toku_pthread_mutex_unlock(&fsync_lock); assert(r_mutex == 0);
#endif
return r;
}
// for real accounting
void
toku_get_fsync_times(uint64_t *fsync_count, uint64_t *fsync_time) {
*fsync_count = toku_fsync_count;
*fsync_time = toku_fsync_time;
}
// for scheduling algorithm only
void
toku_get_fsync_sched(uint64_t *fsync_count, uint64_t *fsync_time) {
*fsync_count = sched_fsync_count;
*fsync_time = sched_fsync_time;
}
static toku_pthread_mutex_t mkstemp_lock;
int
toku_mkstemp_init(void) {
int r = 0;
r = toku_pthread_mutex_init(&mkstemp_lock, NULL); assert(r == 0);
return r;
}
int
toku_mkstemp_destroy(void) {
int r = 0;
r = toku_pthread_mutex_destroy(&mkstemp_lock); assert(r == 0);
return r;
}
int mkstemp (char * template) {
int fd;
int r_mutex;
r_mutex = toku_pthread_mutex_lock(&mkstemp_lock);
assert(r_mutex == 0);
errno_t err = _mktemp_s(template, strlen(template)+1);
if (err!=0) {
fd = -1;
errno = err;
goto cleanup;
}
assert(err==0);
fd = open(template, _O_BINARY|_O_CREAT|_O_SHORT_LIVED|_O_EXCL|_O_RDWR, _S_IREAD|_S_IWRITE);
cleanup:
r_mutex = toku_pthread_mutex_unlock(&mkstemp_lock);
assert(r_mutex == 0);
return fd;
}
toku_off_t
ftello(FILE *stream) {
toku_off_t offset = _ftelli64(stream);
return offset;
}
ssize_t
toku_os_read(int fd, void *buf, size_t count) {
return read(fd, buf, count);
}

View file

@ -1,79 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <toku_portability.h>
#include <stdio.h>
#include <unistd.h>
char *optarg;
int optind;
static const char *match(char c, const char *optstring) {
int i;
for (i=0;optstring[i]; i++)
if (c == optstring[i])
return &optstring[i];
return 0;
}
int getopt(int argc, char * const argv[], const char *optstring) {
static int nextargc = 0;
static int nextchar = 0;
char *arg;
const char *theopt;
// first time initialization
if (nextargc == 0) {
nextargc = 1;
optind = 1;
nextchar = 0;
}
again:
optarg = 0;
optind = nextargc;
// last arg
if (nextargc >= argc)
return -1;
arg = argv[nextargc];
if (!arg[nextchar]) {
nextargc++;
nextchar = 0;
goto again;
}
if (!nextchar) {
// not an option
if (arg[0] != '-')
return -1;
// end of options "--"
if (arg[1] == '-') {
nextargc++;
optind = nextargc;
return -1;
}
nextchar = 1;
}
// try to match the arg with the options
theopt = match(arg[nextchar++], optstring);
if (!theopt)
return '?';
if (theopt[1] == ':') {
if (arg[nextchar]) {
optarg = &arg[nextchar];
nextargc++;
nextchar = 0;
} else if (nextargc >= argc) {
nextargc++;
nextchar = 0;
return -1;
} else {
nextargc++;
nextchar = 0;
optarg = argv[nextargc++];
}
}
return theopt[0];
}

View file

@ -1,21 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ifndef _TOKUWIN_GETOPT_H
#define _TOKUWIN_GETOPT_H
#if defined(__cplusplus)
extern "C" {
#endif
int
getopt(int argc, char *const argv[], const char *optstring);
extern char *optarg;
extern int optind;
#if defined(__cplusplus)
};
#endif
#endif

View file

@ -1,23 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ifndef _INTTYPES_H
#define _INTTYPES_H
#include <stdint.h>
//Define printf types.
#define SCNd64 "I64d"
#define SCNu64 "I64u"
#define SCNd32 "d"
#define SCNu32 "u"
#define PRId64 "I64d"
#define PRIu64 "I64u"
#define PRIx64 "I64x"
#define PRIX64 "I64X"
#define PRId32 "d"
#define PRIu32 "u"
#define PRIx32 "x"
#define PRIX32 "X"
#endif

View file

@ -1,208 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ident "Copyright (c) 2007-2011 Tokutek Inc. All rights reserved."
#include <toku_portability.h>
#include "memory.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include "toku_assert.h"
#include "toku_pthread.h"
static malloc_fun_t t_malloc = 0;
static malloc_fun_t t_xmalloc = 0;
static free_fun_t t_free = 0;
static realloc_fun_t t_realloc = 0;
static realloc_fun_t t_xrealloc = 0;
static MEMORY_STATUS_S status;
static size_t
my_malloc_usable_size(void *p) {
return p == NULL ? 0 : malloc_usable_size(p);
}
void
toku_memory_get_status(MEMORY_STATUS s) {
*s = status;
}
// max_in_use may be slightly off because use of max_in_use is not thread-safe.
// It is not worth the overhead to make it completely accurate.
static inline void
set_max(uint64_t sum_used, uint64_t sum_freed) {
uint64_t in_use = (sum_used - sum_freed);
if ((!(in_use & 0x8000000000000000)) // if wrap due to another thread, ignore bogus "negative" value
&& (in_use > status.max_in_use)) {
status.max_in_use = in_use;
}
}
void *toku_malloc(size_t size) {
void *p = t_malloc ? t_malloc(size) : os_malloc(size);
if (p) {
size_t used = my_malloc_usable_size(p);
__sync_add_and_fetch(&status.malloc_count, 1);
__sync_add_and_fetch(&status.requested,size);
__sync_add_and_fetch(&status.used, used);
set_max(status.used, status.freed);
} else {
__sync_add_and_fetch(&status.malloc_fail, 1);
}
return p;
}
void *
toku_calloc(size_t nmemb, size_t size) {
size_t newsize = nmemb * size;
void *p = toku_malloc(newsize);
if (p) memset(p, 0, newsize);
return p;
}
void *
toku_realloc(void *p, size_t size) {
size_t used_orig = p ? my_malloc_usable_size(p) : 0;
void *q = t_realloc ? t_realloc(p, size) : os_realloc(p, size);
if (q) {
size_t used = my_malloc_usable_size(q);
__sync_add_and_fetch(&status.realloc_count, 1);
__sync_add_and_fetch(&status.requested, size);
__sync_add_and_fetch(&status.used, used);
__sync_add_and_fetch(&status.freed, used_orig);
set_max(status.used, status.freed);
} else {
__sync_add_and_fetch(&status.realloc_fail, 1);
}
return q;
}
void *
toku_memdup(const void *v, size_t len) {
void *p = toku_malloc(len);
if (p) memcpy(p, v,len);
return p;
}
char *
toku_strdup(const char *s) {
return toku_memdup(s, strlen(s)+1);
}
void
toku_free(void *p) {
if (p) {
size_t used = my_malloc_usable_size(p);
__sync_add_and_fetch(&status.free_count, 1);
__sync_add_and_fetch(&status.freed, used);
if (t_free)
t_free(p);
else
os_free(p);
}
}
void
toku_free_n(void* p, size_t size __attribute__((unused))) {
toku_free(p);
}
void *
toku_xmalloc(size_t size) {
void *p = t_xmalloc ? t_xmalloc(size) : os_malloc(size);
if (p == NULL) // avoid function call in common case
resource_assert(p);
size_t used = my_malloc_usable_size(p);
__sync_add_and_fetch(&status.malloc_count, 1);
__sync_add_and_fetch(&status.requested, size);
__sync_add_and_fetch(&status.used, used);
set_max(status.used, status.freed);
return p;
}
void *
toku_xcalloc(size_t nmemb, size_t size) {
size_t newsize = nmemb * size;
void *vp = toku_xmalloc(newsize);
if (vp) memset(vp, 0, newsize);
return vp;
}
void *
toku_xrealloc(void *v, size_t size) {
size_t used_orig = v ? my_malloc_usable_size(v) : 0;
void *p = t_xrealloc ? t_xrealloc(v, size) : os_realloc(v, size);
if (p == 0) // avoid function call in common case
resource_assert(p);
size_t used = my_malloc_usable_size(p);
__sync_add_and_fetch(&status.realloc_count, 1);
__sync_add_and_fetch(&status.requested, size);
__sync_add_and_fetch(&status.used, used);
__sync_add_and_fetch(&status.freed, used_orig);
set_max(status.used, status.freed);
return p;
}
size_t
toku_malloc_usable_size(void *p) {
return p == NULL ? 0 : malloc_usable_size(p);
}
void *
toku_xmemdup (const void *v, size_t len) {
void *p = toku_xmalloc(len);
memcpy(p, v, len);
return p;
}
char *
toku_xstrdup (const char *s) {
return toku_xmemdup(s, strlen(s)+1);
}
void
toku_set_func_malloc(malloc_fun_t f) {
t_malloc = f;
t_xmalloc = f;
}
void
toku_set_func_xmalloc_only(malloc_fun_t f) {
t_xmalloc = f;
}
void
toku_set_func_malloc_only(malloc_fun_t f) {
t_malloc = f;
}
void
toku_set_func_realloc(realloc_fun_t f) {
t_realloc = f;
t_xrealloc = f;
}
void
toku_set_func_xrealloc_only(realloc_fun_t f) {
t_xrealloc = f;
}
void
toku_set_func_realloc_only(realloc_fun_t f) {
t_realloc = f;
}
void
toku_set_func_free(free_fun_t f) {
t_free = f;
}
#include <valgrind/drd.h>
void __attribute__((constructor)) toku_memory_drd_ignore(void);
void
toku_memory_drd_ignore(void) {
DRD_IGNORE_VAR(status);
}

View file

@ -1,98 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ifndef _MISC_H
#define _MISC_H
#if defined(__cplusplus)
extern "C" {
#endif
#include "toku_os.h"
#include <sys/stat.h>
#include <stddef.h>
//These are functions that really exist in windows but are named
//something else.
//TODO: Sort these into some .h file that makes sense.
int fsync(int fildes);
int toku_fsync_init(void);
int toku_fsync_destroy(void);
int toku_mkstemp_init(void);
int toku_mkstemp_destroy(void);
int gettimeofday(struct timeval *tv, struct timezone *tz);
long long int strtoll(const char *nptr, char **endptr, int base);
//TODO: Enforce use of these macros. Otherwise, open, creat, and chmod may fail
//toku_os_mkdir actually ignores the permissions, so it won't fail.
//Permissions
//User permissions translate to global
//Execute bit does not exist
//TODO: Determine if we need to use BINARY mode for opening.
#define S_IRWXU S_IRUSR | S_IWUSR | S_IXUSR
#define S_IRUSR S_IREAD
#define S_IWUSR S_IWRITE
//Execute bit does not exist
#define S_IXUSR (0)
//Group permissions thrown away.
#define S_IRWXG S_IRGRP | S_IWGRP | S_IXGRP
#define S_IRGRP (0)
#define S_IWGRP (0)
#define S_IXGRP (0)
//Other permissions thrown away. (Except for read)
//MySQL defines S_IROTH as S_IREAD. Avoid the warning.
#if defined(S_IROTH)
#undef S_IROTH
#endif
#define S_IRWXO S_IROTH | S_IWOTH | S_IXOTH
#define S_IROTH S_IREAD
#define S_IWOTH (0)
#define S_IXOTH (0)
long int random(void);
void srandom(unsigned int seed);
//strtoll has a different name in windows.
#define strtoll _strtoi64
#define strtoull _strtoui64
//rmdir has a different name in windows.
#define rmdir _rmdir
#ifndef PATH_MAX
#define PATH_MAX _MAX_PATH
#endif
char *realpath(const char *path, char *resolved_path);
int unsetenv(const char *name);
int setenv(const char *name, const char *value, int overwrite);
int vsnprintf(char *str, size_t size, const char *format, va_list ap);
int snprintf(char *str, size_t size, const char *format, ...);
int usleep(unsigned int useconds);
int mkstemp(char * ttemplate);
toku_off_t ftello(FILE *stream);
int strerror_r(int errnum, char *buf, size_t buflen);
#define __builtin_offsetof(type, member) offsetof(type, member)
#if defined(__cplusplus)
};
#endif
#endif

View file

@ -1,54 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
#include <toku_portability.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <errno.h>
static inline size_t resize(size_t n) {
if (n >= 1*1024*1024)
n = (n+7) & ~7; // round up to make windbg !heap happy
#define DO_PAD_64K 0
#if DO_PAD_64K
else if (64*1024 <= n && n < 1*1024*1024)
n = 1*1024*1024; // map anything >= 64K to 1M
#endif
#define DO_ROUND_POW2 1
#if DO_ROUND_POW2
else {
// make all buffers a power of 2 in size including the windows overhead
size_t r = 0;
size_t newn = 1<<r;
size_t overhead = 0x24;
n += overhead;
while (n > newn) {
r++;
newn = 1<<r;
}
n = newn - overhead;
}
#endif
return n;
}
void *
os_malloc(size_t size)
{
return malloc(resize(size));
}
void *
os_realloc(void *p, size_t size)
{
return realloc(p, resize(size));
}
void
os_free(void* p)
{
free(p);
}

File diff suppressed because it is too large Load diff

View file

@ -1,44 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
//rand_s requires _CRT_RAND_S be defined before including stdlib
#define _CRT_RAND_S
#include <toku_portability.h>
#include <stdio.h>
#include <toku_assert.h>
#include <stdint.h>
#include <toku_stdlib.h>
#include <windows.h>
static int used_srand = 0;
long int
random(void) {
u_int32_t r;
if (used_srand) {
//rand is a relatively poor number generator, but can be seeded
//rand generates 15 bits. We need 3 calls to generate 31 bits.
u_int32_t r1 = rand() & ((1<<15)-1);
u_int32_t r2 = rand() & ((1<<15)-1);;
u_int32_t r3 = rand() & 0x1;
r = r1 | (r2<<15) | (r3<<30);
}
else {
//rand_s is a good number generator, but cannot be seeded (for
//repeatability).
errno_t r_error = rand_s(&r);
assert(r_error==0);
//Should return 0 to 2**31-1 instead of 2**32-1
r >>= 1;
}
return r;
}
//TODO: Implement srandom to modify the way rand_s works (IF POSSIBLE).. or
//reimplement random.
void
srandom(unsigned int seed) {
srand(seed);
used_srand = 1;
}

View file

@ -1,57 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <toku_portability.h>
#include <windows.h>
#include <stdint.h>
#include <inttypes.h>
#include <toku_os.h>
#define DO_MEMORY_INFO 1
#if DO_MEMORY_INFO
#include <psapi.h>
static int
get_memory_info(PROCESS_MEMORY_COUNTERS *meminfo) {
int r;
r = GetProcessMemoryInfo(GetCurrentProcess(), meminfo, sizeof *meminfo);
if (r == 0)
return GetLastError();
return 0;
}
#endif
int
toku_os_get_rss(int64_t *rss) {
int r;
#if DO_MEMORY_INFO
PROCESS_MEMORY_COUNTERS meminfo;
r = get_memory_info(&meminfo);
if (r == 0)
*rss = meminfo.WorkingSetSize;
#else
r = 0;
*rss = 0;
#endif
return r;
}
int
toku_os_get_max_rss(int64_t *maxrss) {
int r;
#if DO_MEMORY_INFO
PROCESS_MEMORY_COUNTERS meminfo;
r = get_memory_info(&meminfo);
if (r == 0)
*maxrss = meminfo.PeakWorkingSetSize;
#else
r = 0;
*maxrss = 0;
#endif
return r;
}

View file

@ -1,182 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/*
* Module: sched.h
*
* Purpose:
* Provides an implementation of POSIX realtime extensions
* as defined in
*
* POSIX 1003.1b-1993 (POSIX.1b)
*
* --------------------------------------------------------------------------
*
* Pthreads-win32 - POSIX Threads Library for Win32
* Copyright(C) 1998 John E. Bossom
* Copyright(C) 1999,2005 Pthreads-win32 contributors
*
* Contact Email: rpj@callisto.canberra.edu.au
*
* The current list of contributors is contained
* in the file CONTRIBUTORS included with the source
* code distribution. The list can also be seen at the
* following World Wide Web location:
* http://sources.redhat.com/pthreads-win32/contributors.html
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library in the file COPYING.LIB;
* if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifndef _SCHED_H
#define _SCHED_H
#undef PTW32_LEVEL
#if defined(_POSIX_SOURCE)
#define PTW32_LEVEL 0
/* Early POSIX */
#endif
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
#undef PTW32_LEVEL
#define PTW32_LEVEL 1
/* Include 1b, 1c and 1d */
#endif
#if defined(INCLUDE_NP)
#undef PTW32_LEVEL
#define PTW32_LEVEL 2
/* Include Non-Portable extensions */
#endif
#define PTW32_LEVEL_MAX 3
#if ( defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112 ) || !defined(PTW32_LEVEL)
#define PTW32_LEVEL PTW32_LEVEL_MAX
/* Include everything */
#endif
#if __GNUC__ && ! defined (__declspec)
# error Please upgrade your GNU compiler to one that supports __declspec.
#endif
/*
* When building the DLL code, you should define PTW32_BUILD so that
* the variables/functions are exported correctly. When using the DLL,
* do NOT define PTW32_BUILD, and then the variables/functions will
* be imported correctly.
*/
#ifndef PTW32_STATIC_LIB
# ifdef PTW32_BUILD
# define PTW32_DLLPORT __declspec (dllexport)
# else
# define PTW32_DLLPORT __declspec (dllimport)
# endif
#else
# define PTW32_DLLPORT
#endif
/*
* This is a duplicate of what is in the autoconf config.h,
* which is only used when building the pthread-win32 libraries.
*/
#ifndef PTW32_CONFIG_H
# if defined(WINCE)
# define NEED_ERRNO
# define NEED_SEM
# endif
# if defined(_UWIN) || defined(__MINGW32__)
# define HAVE_MODE_T
# endif
#endif
/*
*
*/
#if PTW32_LEVEL >= PTW32_LEVEL_MAX
#ifdef NEED_ERRNO
#include "need_errno.h"
#else
#include <errno.h>
#endif
#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
#if defined(__MINGW32__) || defined(_UWIN)
# if PTW32_LEVEL >= PTW32_LEVEL_MAX
/* For pid_t */
# include <sys/types.h>
/* Required by Unix 98 */
# include <time.h>
# else
typedef int pid_t;
# endif
#else
typedef int pid_t;
#endif
/* Thread scheduling policies */
enum {
SCHED_OTHER = 0,
SCHED_FIFO,
SCHED_RR,
SCHED_MIN = SCHED_OTHER,
SCHED_MAX = SCHED_RR
};
struct sched_param {
int sched_priority;
};
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
PTW32_DLLPORT int __cdecl sched_yield (void);
PTW32_DLLPORT int __cdecl sched_get_priority_min (int policy);
PTW32_DLLPORT int __cdecl sched_get_priority_max (int policy);
PTW32_DLLPORT int __cdecl sched_setscheduler (pid_t pid, int policy);
PTW32_DLLPORT int __cdecl sched_getscheduler (pid_t pid);
/*
* Note that this macro returns ENOTSUP rather than
* ENOSYS as might be expected. However, returning ENOSYS
* should mean that sched_get_priority_{min,max} are
* not implemented as well as sched_rr_get_interval.
* This is not the case, since we just don't support
* round-robin scheduling. Therefore I have chosen to
* return the same value as sched_setscheduler when
* SCHED_RR is passed to it.
*/
#define sched_rr_get_interval(_pid, _interval) \
( errno = ENOTSUP, (int) -1 )
#ifdef __cplusplus
} /* End of extern "C" */
#endif /* __cplusplus */
#undef PTW32_LEVEL
#undef PTW32_LEVEL_MAX
#endif /* !_SCHED_H */

View file

@ -1,8 +0,0 @@
@echo off
call "C:\Program Files (x86)\Intel\Compiler\C++\10.1.032\EM64T\Bin\ICLVars.bat"
C:
chdir C:\cygwin\bin
bash --login -i %*

View file

@ -1,73 +0,0 @@
#!/usr/bin/bash
#Install BDB
echo Installing BDB if necessary ...
if ! test -d /usr/local/BerkeleyDB.4.6 ; then
(
echo "BDB is missing. Downloading from svn" &&
cd /usr/local &&
svn co -q https://svn.tokutek.com/tokudb/berkeleydb/windows/amd64/BerkeleyDB.4.6
) || { echo Failed; exit 1; }
fi
if ! grep 'export BDB=' ~/.bashrc > /dev/null; then
echo "Adding 'export BDB=/usr/local/BerkeleyDB.4.6' to ~/.bashrc"
echo 'export BDB=/usr/local/BerkeleyDB.4.6' >> ~/.bashrc
fi
if ! grep 'export BDBDIR=' ~/.bashrc > /dev/null; then
echo "Adding 'export BDBDIR=C:/cygwin/usr/local/BerkeleyDB.4.6'' to ~/.bashrc"
echo 'export BDBDIR=C:/cygwin/usr/local/BerkeleyDB.4.6' >> ~/.bashrc
fi
echo Done installing BDB.
echo
#Install licenses.
if ! test -e ../licenses/install_licenses_amd64.bat; then
echo Missing ../licenses directory.
exit 1
fi
echo Installing licenses...
(cd ../licenses && cmd /c install_licenses_amd64.bat) > /dev/null
echo Done installing licenses.
echo
#install icc integration
(
cd amd64 &&
if ! diff -q Cygwin.bat /cygdrive/c/cygwin/Cygwin.bat > /dev/null; then
cp Cygwin.bat /cygdrive/c/cygwin/ || { echo Failed Cygwin.bat; exit 1; }
fi
)
if ! grep 'export CC=' ~/.bashrc > /dev/null; then
echo "Adding 'export CC=icc' to ~/.bashrc"
echo 'export CC=icc' >> ~/.bashrc
fi
if ! grep 'export CYGWIN=' ~/.bashrc > /dev/null; then
echo "Adding 'export CYGWIN=CYGWIN' to ~/.bashrc"
echo 'export CYGWIN=CYGWIN' >> ~/.bashrc
fi
#cygwin link is in the way
if test -e /usr/bin/link; then
mv /usr/bin/link /usr/bin/link_DISABLED || { echo Failed changing link; exit 1; }
fi
#cygwin cmake is in the way
if test -e /usr/bin/cmake; then
mv /usr/bin/cmake /usr/bin/cmake_DISABLED || { echo Failed changing link; exit 1; }
fi
#Set up aliases
( cd amd64/symlinks && cp -d * /usr/local/bin/ || { echo Failed copying link; exit 1; } )
#Copy nightly script.
cp -u nightly.sh ~/ || { echo Failed copying nightly.sh; exit 1; }
echo You can now install the intel compiler.
echo You must restart cygwin after intel compiler is installed.
echo If the intel compiler is already installed, just restart cygwin.
echo

View file

@ -1,25 +0,0 @@
#!/bin/bash
SVN_USER="tokubuild"
SVN_PASS="Tb091638"
if ! [ -d $HOME/svn.build ] ; then
mkdir -p $HOME/svn.build || exit 1
fi
cd $HOME/svn.build
if ! [ -d tokudb.build ] ; then
svn --username $SVN_USER --password $SVN_PASS co -q --depth=empty https://svn.tokutek.com/tokudb/tokudb.build || exit 1
fi
if ! [ -d scripts ] ; then
svn --username $SVN_USER --password $SVN_PASS co -q --depth=empty https://svn.tokutek.com/toku/tokudb/scripts || exit 1
fi
cd scripts
svn --username $SVN_USER --password $SVN_PASS up || exit 1
cd bin
./build.check.bash --windows=1 "$@" || exit 1

View file

@ -1,27 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <toku_portability.h>
#include <windows.h>
#include <unistd.h>
unsigned int
sleep(unsigned int seconds) {
unsigned int m = seconds / 1000000;
unsigned int n = seconds % 1000000;
unsigned int i;
for (i=0; i<m; i++)
Sleep(1000000*1000);
Sleep(n*1000);
return 0;
}
int
usleep(unsigned int useconds) {
unsigned int m = useconds / 1000;
unsigned int n = useconds % 1000;
if (m == 0 && n > 0)
m = 1;
Sleep(m);
return 0;
}

View file

@ -1,48 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ifndef _STDINT_H
#define _STDINT_H
#if defined(__cplusplus)
extern "C" {
#endif
#include <basetsd.h>
#include <sys/types.h>
//Define standard integer types.
typedef __int8 int8_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int8 u_int8_t;
typedef __int16 int16_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int16 u_int16_t;
typedef __int32 int32_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int32 u_int32_t;
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
typedef unsigned __int64 u_int64_t;
typedef SSIZE_T ssize_t;
//Limits
#define INT8_MIN _I8_MIN
#define INT8_MAX _I8_MAX
#define UINT8_MAX _UI8_MAX
#define INT16_MIN _I16_MIN
#define INT16_MAX _I16_MAX
#define UINT16_MAX _UI16_MAX
#define INT32_MIN _I32_MIN
#define INT32_MAX _I32_MAX
#define UINT32_MAX _UI32_MAX
#define INT64_MIN _I64_MIN
#define INT64_MAX _I64_MAX
#define UINT64_MAX _UI64_MAX
#if defined(__cplusplus)
};
#endif
#endif

View file

@ -1,41 +0,0 @@
# -*- Mode: Makefile -*-
.DEFAULT_GOAL=all
TOKUROOT=../../
INCLUDEDIRS=-I$(TOKUROOT)include/windows -I$(TOKUROOT)ft -I$(TOKUROOT)windows/tests
include $(TOKUROOT)toku_include/Makefile.include
SKIP_WARNING += $(ICC_NOWARN)1418 #Non static functions do not need prototypes.
SRCS=$(sort $(filter-out dir.%.c,$(wildcard *.c)))
BINS_RAW = $(patsubst %.c,%,$(SRCS))
#Bins will be generated.
$(BINS): $(LIBPORTABILITY)
$(BINS): CFLAGS+=-DTESTDIR=\"dir.$<.dir\"
RUNTARGETS = $(patsubst %$(BINSUF),%.tdbrun,$(BINS))
VGRIND =
all: $(BINS)
.PHONY: check
check: $(BINS) $(RUNTARGETS);
test-pwrite4g.tdbrun: TEST_EXTRA_ARGS=.
test-pwrite4g.tdbrun: VERBVERBOSE=
%.tdbrun: %$(BINSUF) $(PTHREAD_LOCAL)
mkdir -p dir.$*
ifeq ($(VGRIND),)
cd dir.$* && ../$< $(TEST_EXTRA_ARGS) $(VERBVERBOSE) $(SUMMARIZE_CMD)
else
cd dir.$* && .$(VGRIND) --log-file=$<.valgrind ../$< $(TEST_EXTRA_ARGS) $(VERBVERBOSE); \
if [ $$? = 0 ] ; then \
grep "LEAK SUMMARY" dir.$*/$<.valgrind >/dev/null 2>&1; \
if [ $$? = 0 ] ; then cat dir.$*/$<.valgrind; test 0 = 1; fi \
fi \
$(SUMMARIZE_CMD)
endif
clean:
rm -rf $(TARGETS) *.valgrind dir.*

View file

@ -1,83 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#define _CRT_SECURE_NO_DEPRECATE
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <toku_assert.h>
#include <fcntl.h>
#include "toku_os.h"
#include <dirent.h>
int verbose;
static int walk(const char *dirname) {
DIR *d;
struct dirent *dirent;
int dotfound = 0, dotdotfound = 0, otherfound = 0;
d = opendir(dirname);
if (d == NULL)
return -1;
while ((dirent = readdir(d))) {
if (verbose)
printf("%p %s\n", dirent, dirent->d_name);
if (strcmp(dirent->d_name, ".") == 0)
dotfound++;
else if (strcmp(dirent->d_name, "..") == 0)
dotdotfound++;
else
otherfound++;
}
closedir(d);
assert(dotfound == 1 && dotdotfound == 1);
return otherfound;
}
int test_main(int argc, char *const argv[]) {
int i;
int found;
int fd;
int r;
for (i=1; i<argc; i++) {
char *arg = argv[i];
if (strcmp(arg, "-v") == 0 || strcmp(arg, "--verbose") == 0)
verbose++;
}
system("rm -rf " TESTDIR);
// try to walk a directory that does not exist
found = walk(TESTDIR);
assert(found == -1);
// try to walk an empty directory
r = toku_os_mkdir(TESTDIR, 0777); assert(r==0);
found = walk(TESTDIR);
assert(found == 0);
//Try to delete the empty directory
system("rm -rf " TESTDIR);
r = toku_os_mkdir(TESTDIR, 0777); assert(r==0);
// walk a directory with a bunch of files in it
#define N 100
for (i=0; i<N; i++) {
char fname[256];
sprintf(fname, TESTDIR "/%d", i);
if (verbose)
printf("%s\n", fname);
// fd = creat(fname, 0777);
fd = open(fname, O_CREAT+O_RDWR, 0777);
assert(fd >= 0);
close(fd);
}
found = walk(TESTDIR);
assert(found == N);
// walk and remove files
return 0;
}

View file

@ -1,70 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <toku_assert.h>
#include <fcntl.h>
#include "toku_os.h"
int verbose=0;
enum {NUM_IDS=4};
struct fileid old_ids[NUM_IDS];
BOOL valid[NUM_IDS];
//TODO: Test that different files are different,
// other stuff
static void test_handles(const char *fname, unsigned which) {
unlink(fname);
int fd = open(fname, O_RDWR | O_CREAT | O_BINARY, S_IRWXU|S_IRWXG|S_IRWXO);
assert(fd!=-1);
int i;
struct fileid id_base;
struct fileid id;
int r = toku_os_get_unique_file_id(fd, &id_base);
CKERR(r);
assert(which < NUM_IDS);
for (i = 0; i < NUM_IDS; i++) {
if (valid[i]) {
if (which==i) {
//Assert same
assert(memcmp(&id_base, &old_ids[i], sizeof(id_base))==0);
}
else {
//Assert different
assert(memcmp(&id_base, &old_ids[i], sizeof(id_base))!=0);
}
}
}
memcpy(&old_ids[which], &id_base, sizeof(id_base));
valid[which] = TRUE;
if (verbose) printf("[%s] : r=[%d] errno=[%d] id=[0x%"PRIx32"/0x%"PRIx64"]\n", fname, r, errno, id_base.st_dev, id_base.st_ino);
for (i=0; i < 1<<16; i++) {
r = toku_os_get_unique_file_id(fd, &id);
CKERR(r);
assert(memcmp(&id, &id_base, sizeof(id))==0);
}
r = close(fd);
CKERR(r);
}
int test_main(int argc, char *const argv[]) {
int i;
for (i=1; i<argc; i++) {
char *arg = argv[i];
if (strcmp(arg, "-v") == 0 || strcmp(arg, "--verbose") == 0)
verbose++;
}
test_handles("junk1", 0);
test_handles("junk2", 1);
test_handles("junk3", 2);
test_handles("NUL", 3);
test_handles(".\\NUL", 3);
test_handles("\\NUL", 3);
test_handles("C:\\NUL", 3);
return 0;
}

View file

@ -1,51 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#define _CRT_SECURE_NO_DEPRECATE
#include <test.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <toku_stdint.h>
#include <unistd.h>
#include <toku_assert.h>
#include "toku_os.h"
int test_main(int argc, char *const argv[]) {
int verbose = 0;
int limit = 1;
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
verbose = 1;
continue;
}
if (strcmp(argv[i], "--timeit") == 0) {
limit = 100000;
continue;
}
}
int r;
#if 0
r = toku_get_filesystem_sizes(NULL, NULL, NULL, NULL);
assert(r == EFAULT);
#endif
r = toku_get_filesystem_sizes(".", NULL, NULL, NULL);
assert(r == 0);
uint64_t free_size = 0, avail_size = 0, total_size = 0;
for (int i = 0; i < limit; i++) {
r = toku_get_filesystem_sizes(".", &avail_size, &free_size, &total_size);
assert(r == 0);
assert(avail_size <= free_size && free_size <= total_size);
}
if (verbose) {
printf("avail=%"PRIu64"\n", avail_size);
printf("free=%"PRIu64"\n", free_size);
printf("total=%"PRIu64"\n", total_size);
}
return 0;
}

View file

@ -1,240 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include "test.h"
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include "toku_time.h"
int verbose = 0;
static void
create_files(int N, int fds[N]) {
int r;
int i;
char name[30];
for (i = 0; i < N; i++) {
snprintf(name, sizeof(name), "%d", i);
fds[i] = open(name, O_CREAT|O_WRONLY);
if (fds[i] < 0) {
r = errno;
CKERR(r);
}
}
}
static void
write_to_files(int N, int bytes, int fds[N]) {
char junk[bytes];
int i;
for (i = 0; i < bytes; i++) {
junk[i] = random() & 0xFF;
}
int r;
for (i = 0; i < N; i++) {
r = toku_os_write(fds[i], junk, bytes);
CKERR(r);
}
}
static void
time_many_fsyncs_one_file(int N, int bytes, int fds[N]) {
if (verbose>1) {
printf("Starting %s\n", __FUNCTION__);
fflush(stdout);
}
struct timeval begin;
struct timeval after_first;
struct timeval end;
write_to_files(1, bytes, fds);
if (verbose>1) {
printf("Done writing to os buffers\n");
fflush(stdout);
}
int i;
int r;
r = gettimeofday(&begin, NULL);
CKERR(r);
r = fsync(fds[0]);
CKERR(r);
r = gettimeofday(&after_first, NULL);
CKERR(r);
for (i = 0; i < N; i++) {
r = fsync(fds[0]);
CKERR(r);
}
r = gettimeofday(&end, NULL);
CKERR(r);
if (verbose) {
printf("Fsyncing one file %d times:\n"
"\tFirst fsync took: [%f] seconds\n"
"\tRemaining %d fsyncs took additional: [%f] seconds\n"
"\tTotal time [%f] seconds\n",
N + 1,
toku_tdiff(&after_first, &begin),
N,
toku_tdiff(&end, &after_first),
toku_tdiff(&end, &begin));
fflush(stdout);
}
}
static void
time_fsyncs_many_files(int N, int bytes, int fds[N]) {
if (verbose>1) {
printf("Starting %s\n", __FUNCTION__);
fflush(stdout);
}
write_to_files(N, bytes, fds);
if (verbose>1) {
printf("Done writing to os buffers\n");
fflush(stdout);
}
struct timeval begin;
struct timeval after_first;
struct timeval end;
int i;
int r;
r = gettimeofday(&begin, NULL);
CKERR(r);
for (i = 0; i < N; i++) {
r = fsync(fds[i]);
CKERR(r);
if (i==0) {
r = gettimeofday(&after_first, NULL);
CKERR(r);
}
if (verbose>2) {
printf("Done fsyncing %d\n", i);
fflush(stdout);
}
}
r = gettimeofday(&end, NULL);
CKERR(r);
if (verbose) {
printf("Fsyncing %d files:\n"
"\tFirst fsync took: [%f] seconds\n"
"\tRemaining %d fsyncs took additional: [%f] seconds\n"
"\tTotal time [%f] seconds\n",
N,
toku_tdiff(&after_first, &begin),
N-1,
toku_tdiff(&end, &after_first),
toku_tdiff(&end, &begin));
fflush(stdout);
}
}
#if !TOKU_WINDOWS
//sync() does not appear to have an analogue on windows.
static void
time_sync_fsyncs_many_files(int N, int bytes, int fds[N]) {
if (verbose>1) {
printf("Starting %s\n", __FUNCTION__);
fflush(stdout);
}
//TODO: timing
write_to_files(N, bytes, fds);
if (verbose>1) {
printf("Done writing to os buffers\n");
fflush(stdout);
}
int i;
int r;
struct timeval begin;
struct timeval after_sync;
struct timeval end;
r = gettimeofday(&begin, NULL);
CKERR(r);
sync();
r = gettimeofday(&after_sync, NULL);
CKERR(r);
if (verbose>1) {
printf("Done with sync()\n");
fflush(stdout);
}
for (i = 0; i < N; i++) {
r = fsync(fds[i]);
CKERR(r);
if (verbose>2) {
printf("Done fsyncing %d\n", i);
fflush(stdout);
}
}
r = gettimeofday(&end, NULL);
CKERR(r);
if (verbose) {
printf("sync() then fsyncing %d files:\n"
"\tsync() took: [%f] seconds\n"
"\tRemaining %d fsyncs took additional: [%f] seconds\n"
"\tTotal time [%f] seconds\n",
N,
toku_tdiff(&after_sync, &begin),
N,
toku_tdiff(&end, &after_sync),
toku_tdiff(&end, &begin));
fflush(stdout);
}
}
#endif
int test_main(int argc, char *const argv[]) {
int i;
int r;
int N = 1000;
int bytes = 4096;
for (i=1; i<argc; i++) {
if (strcmp(argv[i], "-v") == 0) {
if (verbose < 0) verbose = 0;
verbose++;
continue;
}
if (strcmp(argv[i], "-q") == 0) {
verbose = 0;
continue;
}
if (strcmp(argv[i], "-b") == 0) {
i++;
if (i>=argc) exit(1);
bytes = atoi(argv[i]);
if (bytes <= 0) exit(1);
continue;
}
if (strcmp(argv[i], "-n") == 0) {
i++;
if (i>=argc) exit(1);
N = atoi(argv[i]);
if (N <= 0) exit(1);
continue;
}
}
r = system("rm -rf " ENVDIR);
CKERR(r);
r = toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);
CKERR(r);
r = chdir(ENVDIR);
CKERR(r);
int fds[N];
create_files(N, fds);
time_many_fsyncs_one_file(N, bytes, fds);
time_fsyncs_many_files(N, bytes, fds);
#if !TOKU_WINDOWS
time_sync_fsyncs_many_files(N, bytes, fds);
#endif
return 0;
}

View file

@ -1,62 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <toku_assert.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#if 0 && TOKU_WINDOWS
#include <windows.h>
static int ftruncate(int fd, uint64_t offset) {
HANDLE h = (HANDLE) _get_osfhandle(fd);
printf("%s:%d %p\n", __FILE__, __LINE__, h); fflush(stdout);
if (h == INVALID_HANDLE_VALUE)
return -1;
int r = _lseeki64(fd, 0, SEEK_SET);
printf("%s:%d %d\n", __FILE__, __LINE__, r); fflush(stdout);
if (r != 0)
return -2;
BOOL b = SetEndOfFile(h);
printf("%s:%d %d\n", __FILE__, __LINE__, b); fflush(stdout);
if (!b)
return -3;
return 0;
}
#endif
int test_main(int argc, char *const argv[]) {
int r;
int fd;
fd = open("test-file-truncate", O_CREAT+O_RDWR+O_TRUNC, S_IREAD+S_IWRITE);
assert(fd != -1);
int i;
for (i=0; i<32; i++) {
char junk[4096];
memset(junk, 0, sizeof junk);
toku_os_full_write(fd, junk, sizeof junk);
}
toku_struct_stat filestat;
r = toku_fstat(fd, &filestat);
assert(r == 0);
printf("orig size %lu\n", (unsigned long) filestat.st_size); fflush(stdout);
r = ftruncate(fd, 0);
assert(r == 0);
r = toku_fstat(fd, &filestat);
assert(r == 0);
printf("truncated size %lu\n", (unsigned long) filestat.st_size); fflush(stdout);
assert(filestat.st_size == 0);
return 0;
}

View file

@ -1,17 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <toku_assert.h>
#include <toku_time.h>
int test_main(int argc, char *const argv[]) {
int r;
struct timeval tv;
struct timezone tz;
r = gettimeofday(&tv, 0);
assert(r == 0);
return 0;
}

View file

@ -1,18 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#define _GNU_SOURCE
#include <test.h>
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <unistd.h>
#include <toku_assert.h>
#include <toku_os.h>
int test_main(int argc, char *const argv[]) {
uint64_t maxdata;
int r = toku_os_get_max_process_data_size(&maxdata);
assert(r == 0);
printf("maxdata=%"PRIu64"\n", maxdata);
return 0;
}

View file

@ -1,19 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
int test_main(int argc, char *const argv[]) {
int i;
for (i=1; i<argc; i++) {
int fd = open(argv[i], O_RDONLY);
printf("%s: %d %d\n", argv[i], fd, errno);
if (fd >= 0) close(fd);
}
return 0;
}

View file

@ -1,54 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <toku_assert.h>
#include <errno.h>
#include <fcntl.h>
#if TOKU_WINDOWS
#include <io.h>
#endif
#include <sys/stat.h>
#ifndef S_IRUSR
#define S_IRUSR S_IREAD
#endif
#ifndef S_IWUSR
#define S_IWUSR S_IWRITE
#endif
#define TESTFILE "test-open-unlink-file"
#define NEWNAME TESTFILE ".junk"
int test_main(int argc, char *const argv[]) {
int r;
int fd;
r = system("rm -rf " TESTFILE); assert(r==0);
r = system("rm -rf " NEWNAME); assert(r==0);
fd = open(TESTFILE, O_CREAT+O_RDWR, S_IRUSR+S_IWUSR);
assert(fd != -1);
r = rename(TESTFILE, NEWNAME);
printf("%s:%d rename %d %d\n", __FILE__, __LINE__, r, errno); fflush(stdout);
#if defined(__linux__)
assert(r == 0);
r = close(fd);
assert(r == 0);
#endif
#if TOKU_WINDOWS
assert(r == -1);
r = close(fd);
assert(r == 0);
r = rename(TESTFILE, NEWNAME);
printf("%s:%d rename %d %d\n", __FILE__, __LINE__, r, errno); fflush(stdout);
assert(r == 0);
#endif
return 0;
}

View file

@ -1,52 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <toku_assert.h>
#include <errno.h>
#include <fcntl.h>
#if TOKU_WINDOWS
#include <io.h>
#endif
#include <sys/stat.h>
#ifndef S_IRUSR
#define S_IRUSR S_IREAD
#endif
#ifndef S_IWUSR
#define S_IWUSR S_IWRITE
#endif
const char TESTFILE[] = "test-open-unlink-file";
int test_main(int argc, char *const argv[]) {
int r;
int fd;
system("rm -rf test-open-unlink-file");
fd = open(TESTFILE, O_CREAT+O_RDWR, S_IRUSR+S_IWUSR);
assert(fd != -1);
r = unlink(TESTFILE);
printf("%s:%d unlink %d %d\n", __FILE__, __LINE__, r, errno); fflush(stdout);
#if defined(__linux__)
assert(r == 0);
r = close(fd);
assert(r == 0);
#endif
#if TOKU_WINDOWS
assert(r == -1);
r = close(fd);
assert(r == 0);
r = unlink(TESTFILE);
printf("%s:%d unlink %d %d\n", __FILE__, __LINE__, r, errno); fflush(stdout);
assert(r == 0);
#endif
return 0;
}

View file

@ -1,41 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <toku_assert.h>
#include <fcntl.h>
#include "toku_os.h"
int verbose;
static void test_pread_empty(const char *fname) {
int fd;
char c[12];
uint64_t r;
unlink(fname);
fd = open(fname, O_RDWR | O_CREAT | O_BINARY, S_IRWXU|S_IRWXG|S_IRWXO);
if (verbose)
printf("open %s fd %d\n", fname, fd);
assert(fd != -1);
r = pread(fd, c, sizeof c, 0);
assert(r == 0);
r = close(fd);
if (verbose)
printf("close %s %"PRIu64"\n", fname, r);
}
int test_main(int argc, char *const argv[]) {
int i;
for (i=1; i<argc; i++) {
char *arg = argv[i];
if (strcmp(arg, "-v") == 0 || strcmp(arg, "--verbose") == 0)
verbose++;
}
test_pread_empty("junk");
return 0;
}

View file

@ -1,87 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <toku_assert.h>
#include <toku_pthread.h>
struct q {
toku_pthread_mutex_t m;
toku_pthread_cond_t r;
toku_pthread_cond_t w;
void *item;
};
static void q_init(struct q *q) {
toku_pthread_mutex_init(&q->m, NULL);
toku_pthread_cond_init(&q->r, NULL);
toku_pthread_cond_init(&q->w, NULL);
q->item = NULL;
}
static void q_destroy(struct q *q) {
toku_pthread_cond_destroy(&q->w);
toku_pthread_cond_destroy(&q->r);
toku_pthread_mutex_destroy(&q->m);
}
static void *q_get(struct q *q) {
void *item;
toku_pthread_mutex_lock(&q->m);
while (q->item == NULL)
toku_pthread_cond_wait(&q->r, &q->m);
item = q->item; q->item = NULL;
toku_pthread_mutex_unlock(&q->m);
toku_pthread_cond_signal(&q->w);
return item;
}
static void q_put(struct q *q, void *item) {
toku_pthread_mutex_lock(&q->m);
while (q->item != NULL)
toku_pthread_cond_wait(&q->w, &q->m);
q->item = item;
toku_pthread_mutex_unlock(&q->m);
toku_pthread_cond_signal(&q->r);
}
static void *writer(void *arg) {
struct q *q = arg;
int i;
printf("%s %p %lu\n", __FUNCTION__, arg, GetCurrentThreadId());
for (i=0; i<100; i++)
q_put(q, (void*)(i+1));
return arg;
}
static void *reader(void *arg) {
struct q *q = arg;
int i;
printf("%s %p %lu\n", __FUNCTION__, arg, GetCurrentThreadId());
for (i=0; i<100; i++) {
void *item = q_get(q);
printf("%p\n", item); fflush(stdout);
Sleep(i);
}
return arg;
}
int test_main(int argc, char *const argv[]) {
int i;
void *ret;
toku_pthread_t t[2];
struct q q;
q_init(&q);
toku_pthread_create(&t[0], NULL, reader, &q);
toku_pthread_create(&t[1], NULL, writer, &q);
for (i=0; i<2; i++)
toku_pthread_join(t[i], &ret);
q_destroy(&q);
return 0;
}

View file

@ -1,40 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <toku_assert.h>
#include <unistd.h>
#include <toku_pthread.h>
static void *myfunc1(void *arg) {
printf("%s %p %lu\n", __FUNCTION__, arg, GetCurrentThreadId());
fflush(stdout);
sleep(10);
return arg;
}
static void *myfunc2(void *arg) {
printf("%s %p %lu\n", __FUNCTION__, arg, GetCurrentThreadId());
fflush(stdout);
sleep(10);
return arg;
}
int test_main(int argc, char *const argv[]) {
#define N 10
toku_pthread_t t[N];
int i;
for (i=0; i<N; i++) {
toku_pthread_create(&t[i], NULL, i & 1 ? myfunc1 : myfunc2, (void *)i);
}
for (i=0; i<N; i++) {
void *ret;
toku_pthread_join(t[i], &ret);
assert(ret == (void*)i);
}
return 0;
}

View file

@ -1,33 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
// test for a pthread handle leak
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <toku_assert.h>
#include <unistd.h>
#include <toku_pthread.h>
static void *mythreadfunc(void *arg) {
return arg;
}
int test_main(int argc, char *const argv[]) {
#define N 1000000
int i;
for (i=0; i<N; i++) {
int r;
toku_pthread_t tid;
r = toku_pthread_create(&tid, NULL, mythreadfunc, (void *)i);
assert(r == 0);
void *ret;
r = toku_pthread_join(tid, &ret);
assert(r == 0 && ret == (void*)i);
}
printf("ok\n"); fflush(stdout);
return 0;
}

View file

@ -1,21 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <toku_assert.h>
#include <toku_pthread.h>
#include <stdio.h>
#include <unistd.h>
int test_main(int argc __attribute__((__unused__)), char *const argv[] __attribute__((__unused__))) {
toku_pthread_rwlock_t rwlock;
toku_pthread_rwlock_init(&rwlock, NULL);
toku_pthread_rwlock_rdlock(&rwlock);
toku_pthread_rwlock_rdlock(&rwlock);
toku_pthread_rwlock_rdunlock(&rwlock);
toku_pthread_rwlock_rdunlock(&rwlock);
toku_pthread_rwlock_destroy(&rwlock);
return 0;
}

View file

@ -1,61 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <toku_assert.h>
#include <toku_pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
// write a test see if things happen in the right order.
volatile int state = 0;
int verbose = 0;
static void *f(void *arg) {
toku_pthread_rwlock_t *mylock = arg;
sleep(2);
assert(state==42); state = 16; if (verbose) printf("%s:%d\n", __FUNCTION__, __LINE__);
toku_pthread_rwlock_wrlock(mylock);
assert(state==49); state = 17; if (verbose) printf("%s:%d\n", __FUNCTION__, __LINE__);
toku_pthread_rwlock_wrunlock(mylock);
sleep(10);
assert(state==52); state = 20; if (verbose) printf("%s:%d\n", __FUNCTION__, __LINE__);
return arg;
}
int test_main(int argc , char *const argv[] ) {
assert(argc==1 || argc==2);
if (argc==2) {
assert(strcmp(argv[1],"-v")==0);
verbose = 1;
}
int r;
toku_pthread_rwlock_t rwlock;
toku_pthread_t tid;
void *retptr;
toku_pthread_rwlock_init(&rwlock, NULL);
state = 37; if (verbose) printf("%s:%d\n", __FUNCTION__, __LINE__);
toku_pthread_rwlock_rdlock(&rwlock);
r = toku_pthread_create(&tid, NULL, f, &rwlock); assert(r == 0);
assert(state==37); state = 42; if (verbose) printf("%s:%d\n", __FUNCTION__, __LINE__);
sleep(4);
assert(state==16); state = 44; if (verbose) printf("%s:%d\n", __FUNCTION__, __LINE__);
toku_pthread_rwlock_rdlock(&rwlock);
assert(state==44); state = 46; if (verbose) printf("%s:%d\n", __FUNCTION__, __LINE__);
toku_pthread_rwlock_rdunlock(&rwlock);
sleep(4);
assert(state==46); state=49; if (verbose) printf("%s:%d\n", __FUNCTION__, __LINE__); // still have a read lock
toku_pthread_rwlock_rdunlock(&rwlock);
sleep(6);
assert(state==17); state=52; if (verbose) printf("%s:%d\n", __FUNCTION__, __LINE__);
r = toku_pthread_join(tid, &retptr); assert(r == 0);
toku_pthread_rwlock_destroy(&rwlock);
return 0;
}

View file

@ -1,45 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/* Verify that toku_os_full_pwrite does the right thing when writing beyond 4GB. */
#include <test.h>
#include <fcntl.h>
#include <toku_assert.h>
#include <string.h>
#include <stdio.h>
static int iszero(char *cp, size_t n) {
size_t i;
for (i=0; i<n; i++)
if (cp[i] != 0)
return 0;
return 1;
}
int test_main(int argc, char *const argv[]) {
assert(argc==2); // first arg is the directory to put the data file into.
char short_fname[] = "pwrite4g.data";
int fname_len = strlen(short_fname) + strlen(argv[1]) + 5;
char fname[fname_len];
snprintf(fname, fname_len, "%s/%s", argv[1], short_fname);
int r;
unlink(fname);
int fd = open(fname, O_RDWR | O_CREAT | O_BINARY, S_IRWXU|S_IRWXG|S_IRWXO);
assert(fd>=0);
char buf[] = "hello";
int64_t offset = (1LL<<32) + 100;
toku_os_full_pwrite(fd, buf, sizeof buf, offset);
char newbuf[sizeof buf];
r = pread(fd, newbuf, sizeof newbuf, 100);
assert(r==sizeof newbuf);
assert(iszero(newbuf, sizeof newbuf));
r = pread(fd, newbuf, sizeof newbuf, offset);
assert(r==sizeof newbuf);
assert(memcmp(newbuf, buf, sizeof newbuf) == 0);
int64_t fsize;
r = toku_os_get_file_size(fd, &fsize);
assert(r == 0);
assert(fsize > 100 + (signed)sizeof(buf));
r = close(fd);
assert(r==0);
return 0;
}

View file

@ -1,33 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <toku_assert.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include <toku_os.h>
static void do_mallocs(void) {
int i;
for (i=0; i<1000; i++) {
int nbytes = 1024*1024;
void *vp = malloc(nbytes);
memset(vp, 0, nbytes);
}
}
int test_main(int argc, char *const argv[]) {
int64_t rss;
toku_os_get_max_rss(&rss);
printf("%I64d\n", rss);
do_mallocs();
toku_os_get_max_rss(&rss);
printf("%I64d\n", rss);
return 0;
}

View file

@ -1,36 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <toku_assert.h>
#include <unistd.h>
#include <string.h>
int verbose;
int test_main(int argc, char *const argv[]) {
int i;
for (i=1; i<argc; i++) {
char *arg = argv[i];
if (strcmp(arg, "-v") == 0 || strcmp(arg, "--verbose") == 0)
verbose++;
}
for (i=0; i<10; i++) {
if (verbose) {
printf("sleep %d\n", i); fflush(stdout);
}
sleep(i);
}
for (i=0; i<10*1000000; i += 1000000) {
if (verbose) {
printf("usleep %d\n", i); fflush(stdout);
}
usleep(i);
}
return 0;
}

View file

@ -1,48 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ident "Copyright (c) 2007, 2008 Tokutek Inc. All rights reserved."
#include <test.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <toku_portability.h>
#include <toku_assert.h>
#include <toku_os.h>
static void
check_snprintf(int i) {
char buf_before[8];
char target[5];
char buf_after[8];
memset(target, 0xFF, sizeof(target));
memset(buf_before, 0xFF, sizeof(buf_before));
memset(buf_after, 0xFF, sizeof(buf_after));
int64_t n = 1;
int j;
for (j = 0; j < i; j++) n *= 10;
int bytes = snprintf(target, sizeof target, "%"PRId64, n);
assert(bytes==i+1 ||
(i+1>=(int)(sizeof target) && bytes>=(int)(sizeof target)));
if (bytes>=(int)(sizeof target)) {
//Overflow prevented by snprintf
assert(target[sizeof target - 1] == '\0');
assert(strlen(target)==sizeof target-1);
}
else {
assert(target[bytes] == '\0');
assert(strlen(target)==(size_t)bytes);
}
}
int test_main(int argc __attribute__((__unused__)), char *const argv[] __attribute__((__unused__))) {
int i;
for (i = 0; i < 8; i++) {
check_snprintf(i);
}
return 0;
}

View file

@ -1,46 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <toku_assert.h>
#include <sys/stat.h>
#include <errno.h>
void test_stat(char *dirname, int result, int ex_errno) {
int r;
toku_struct_stat buf;
r = toku_stat(dirname, &buf);
printf("stat %s %d %d\n", dirname, r, errno); fflush(stdout);
assert(r==result);
if (r!=0) assert(errno == ex_errno);
}
int test_main(int argc, char *const argv[]) {
int r;
test_stat(".", 0, 0);
test_stat("./", 0, 0);
r = system("rm -rf testdir"); assert(r==0);
test_stat("testdir", -1, ENOENT);
test_stat("testdir/", -1, ENOENT);
test_stat("testdir/foo", -1, ENOENT);
test_stat("testdir/foo/", -1, ENOENT);
r = toku_os_mkdir("testdir", S_IRWXU);
assert(r == 0);
test_stat("testdir/foo", -1, ENOENT);
test_stat("testdir/foo/", -1, ENOENT);
r = system("touch testdir/foo"); assert(r==0);
test_stat("testdir/foo", 0, 0);
test_stat("testdir/foo/", -1, ENOENT);
test_stat("testdir", 0, 0);
test_stat("./testdir", 0, 0);
test_stat("./testdir/", 0, 0);
return 0;
}

View file

@ -1,44 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <toku_assert.h>
#include "toku_os.h"
int verbose;
void testit(int64_t i, int base) {
int64_t o;
#define SN 32
char s[SN];
sprintf(s, "%I64d", i);
o = strtoll(s, NULL, base);
if (verbose)
printf("%s: %I64d %I64d %s\n", __FUNCTION__, i, o, s);
assert(i == o);
}
int test_main(int argc, char *const argv[]) {
int i;
int64_t n;
int64_t o;
#define SN 32
char s[SN];
for (i=1; i<argc; i++) {
char *arg = argv[i];
if (strcmp(arg, "-v") == 0 || strcmp(arg, "--verbose") == 0)
verbose++;
}
for (n=0; n<1000; n++) {
testit(n, 10);
}
testit(1I64 << 31, 10);
testit((1I64 << 32) - 1, 10);
testit(1I64 << 32, 10);
return 0;
}

View file

@ -1,23 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <toku_assert.h>
#include <fcntl.h>
int test_main(int argc, char *const argv[]) {
int r;
int fd;
struct fileid fid;
fd = open(DEV_NULL_FILE, O_RDWR);
assert(fd != -1);
r = toku_os_get_unique_file_id(fd, &fid);
printf("%s:%d %d\n", __FILE__, __LINE__, r);
r = close(fd);
assert(r != -1);
return 0;
}

View file

@ -1,48 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <toku_assert.h>
#include <fcntl.h>
#include <windows.h>
#include <winsock.h>
int usleep_socket(SOCKET s, unsigned int useconds) {
fd_set dummy;
struct timeval tv;
FD_ZERO(&dummy);
FD_SET(s, &dummy);
tv.tv_sec = useconds / 1000000;
tv.tv_usec = useconds % 1000000;
return select(0, 0, 0, &dummy, &tv);
}
int verbose;
int test_main(int argc, char *const argv[]) {
int i;
int n = 1;
WSADATA wsadata;
SOCKET s;
for (i=1; i<argc; i++) {
char *arg = argv[i];
if (strcmp(arg, "-v") == 0 || strcmp(arg, "--verbose") == 0)
verbose++;
n = atoi(arg);
}
WSAStartup(MAKEWORD(1, 0), &wsadata);
s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
printf("s=%"PRIu64"\n", s);
for (i=0; i<1000; i++) {
if (verbose) {
printf("usleep %d\n", i); fflush(stdout);
}
usleep_socket(s, n);
}
return 0;
}

View file

@ -1,31 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <test.h>
#include <stdio.h>
#include <stdlib.h>
#include <toku_assert.h>
#include <string.h>
#include <unistd.h>
int verbose;
int test_main(int argc, char *const argv[]) {
int i;
int n = 1;
for (i=1; i<argc; i++) {
char *arg = argv[i];
if (strcmp(arg, "-v") == 0 || strcmp(arg, "--verbose") == 0)
verbose++;
n = atoi(arg);
}
for (i=0; i<1000; i++) {
if (verbose) {
printf("usleep %d\n", i); fflush(stdout);
}
usleep(n);
}
return 0;
}

View file

@ -1,26 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <toku_portability.h>
#include <toku_assert.h>
#define CKERR(r) ({ int __r = r; if (__r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, __r, strerror(r)); assert(__r==0); })
#define CKERR2(r,r2) do { if (r!=r2) fprintf(stderr, "%s:%d error %d %s, expected %d\n", __FILE__, __LINE__, r, strerror(r), r2); assert(r==r2); } while (0)
#define CKERR2s(r,r2,r3) do { if (r!=r2 && r!=r3) fprintf(stderr, "%s:%d error %d %s, expected %d or %d\n", __FILE__, __LINE__, r, strerror(r), r2,r3); assert(r==r2||r==r3); } while (0)
#define DEBUG_LINE do { \
fprintf(stderr, "%s() %s:%d\n", __FUNCTION__, __FILE__, __LINE__); \
fflush(stderr); \
} while (0)
int test_main(int argc, char *const argv[]);
int
main(int argc, char *const argv[]) {
int ri = toku_portability_init();
assert(ri==0);
int r = test_main(argc, argv);
int rd = toku_portability_destroy();
assert(rd==0);
return r;
}

View file

@ -1,120 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ident "Copyright (c) 2007-2010 Tokutek Inc. All rights reserved."
#include <toku_portability.h>
#include "toku_assert.h"
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#if !TOKU_WINDOWS
#include <execinfo.h>
#endif
#if !TOKU_WINDOWS
#define N_POINTERS 1000
// These are statically allocated so that the backtrace can run without any calls to malloc()
static void *backtrace_pointers[N_POINTERS];
#endif
// Function pointers are zero by default so asserts can be used by brt-layer tests without an environment.
static int (*toku_maybe_get_engine_status_text_p)(char* buff, int buffsize) = 0;
static void (*toku_maybe_set_env_panic_p)(int code, char* msg) = 0;
void toku_assert_set_fpointers(int (*toku_maybe_get_engine_status_text_pointer)(char*, int),
void (*toku_maybe_set_env_panic_pointer)(int, char*)) {
toku_maybe_get_engine_status_text_p = toku_maybe_get_engine_status_text_pointer;
toku_maybe_set_env_panic_p = toku_maybe_set_env_panic_pointer;
}
void (*do_assert_hook)(void) = NULL;
static void toku_do_backtrace_abort(void) __attribute__((noreturn));
static void
toku_do_backtrace_abort(void) {
// backtrace
#if !TOKU_WINDOWS
int n = backtrace(backtrace_pointers, N_POINTERS);
fprintf(stderr, "Backtrace: (Note: toku_do_assert=0x%p)\n", toku_do_assert); fflush(stderr);
backtrace_symbols_fd(backtrace_pointers, n, fileno(stderr));
#endif
fflush(stderr);
if (toku_maybe_get_engine_status_text_p) {
int r;
int buffsize = 1024 * 32;
char buff[buffsize];
r = toku_maybe_get_engine_status_text_p(buff, buffsize);
fprintf(stderr, "Engine status:\n%s\n", buff);
}
else
fprintf(stderr, "Engine status function not available\n");
fprintf(stderr, "Memory usage:\n");
fflush(stderr); // just in case malloc_stats() crashes, we still want engine status (and to know that malloc_stats() failed)
malloc_stats();
fflush(stderr);
#if TOKU_WINDOWS
//Following commented methods will not always end the process (could hang).
//They could be unacceptable for other reasons as well (popups,
//flush buffers before quitting, etc)
// abort()
// assert(FALSE) (assert.h assert)
// raise(SIGABRT)
// divide by 0
// null dereference
// _exit
// exit
// ExitProcess
TerminateProcess(GetCurrentProcess(), 134); //Only way found so far to unconditionally
//Terminate the process
#endif
if (do_assert_hook) do_assert_hook();
abort();
}
static void
set_panic_if_not_panicked(int caller_errno, char * msg) {
int code = caller_errno ? caller_errno : -1;
if (toku_maybe_set_env_panic_p) {
toku_maybe_set_env_panic_p(code, msg);
}
}
#define MSGLEN 1024
void
toku_do_assert_fail (const char *expr_as_string, const char *function, const char *file, int line, int caller_errno) {
char msg[MSGLEN];
snprintf(msg, MSGLEN, "%s:%d %s: Assertion `%s' failed (errno=%d)\n", file, line, function, expr_as_string, caller_errno);
perror(msg);
set_panic_if_not_panicked(caller_errno, msg);
toku_do_backtrace_abort();
}
void
toku_do_assert_zero_fail (uintptr_t expr, const char *expr_as_string, const char *function, const char *file, int line, int caller_errno) {
char msg[MSGLEN];
snprintf(msg, MSGLEN, "%s:%d %s: Assertion `%s == 0' failed (errno=%d) (%s=%"PRIuPTR")\n", file, line, function, expr_as_string, caller_errno, expr_as_string, expr);
perror(msg);
set_panic_if_not_panicked(caller_errno, msg);
toku_do_backtrace_abort();
}
void
toku_do_assert(int expr, const char *expr_as_string, const char *function, const char* file, int line, int caller_errno) {
if (expr == 0)
toku_do_assert_fail(expr_as_string, function, file, line, caller_errno);
}

View file

@ -1,43 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ifndef _TOKU_HTONL_H
#define _TOKU_HTONL_H
#if !TOKU_WINDOWS
#error
#endif
#if defined(__cplusplus)
extern "C" {
#endif
#if defined(__INTEL_COMPILER)
// assume endian == LITTLE_ENDIAN
static inline uint32_t toku_htonl(uint32_t i) {
return _bswap(i);
}
static inline uint32_t toku_ntohl(uint32_t i) {
return _bswap(i);
}
#elif defined(_MSVC_VER)
#include <winsock.h>
static inline uint32_t toku_htonl(uint32_t i) {
return htonl(i);
}
static inline uint32_t toku_ntohl(uint32_t i) {
return ntonl(i);
}
#endif
#if defined(__cplusplus)
};
#endif
#endif

View file

@ -1,33 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ifndef TOKU_OS_TYPES_H
#define TOKU_OS_TYPES_H
#if defined(__cplusplus)
extern "C" {
#endif
#include <stdlib.h>
#include <direct.h>
#include <sys/types.h>
#include <sys/stat.h>
// define an OS handle
typedef void *toku_os_handle_t;
typedef int pid_t;
typedef int mode_t;
struct fileid {
uint32_t st_dev;
uint64_t st_ino;
};
typedef struct _stati64 toku_struct_stat;
#if defined(__cplusplus)
};
#endif
#endif

View file

@ -1,82 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <toku_portability.h>
#include <windows.h>
#include <toku_pthread.h>
#include "toku_assert.h"
int
toku_pthread_yield(void) {
Sleep(0);
return 0;
}
toku_pthread_win32_funcs pthread_win32 = {0};
HMODULE pthread_win32_dll = NULL;
//TODO: add a portability_init/destroy function (call in brt_init)
//TODO: Call in portability_init
int
toku_pthread_win32_init(void) {
int r = 0;
pthread_win32_dll = NULL;
memset(&pthread_win32, 0, sizeof(pthread_win32));
pthread_win32_dll = LoadLibrary(TEXT("pthreadVC2"));
if (pthread_win32_dll == NULL)
r = GetLastError();
else {
#define LOAD_PTHREAD_FUNC(name) do { \
pthread_win32.pthread_ ## name = (toku_pthread_win32_ ## name ## _func) GetProcAddress(pthread_win32_dll, "pthread_" #name); \
assert(pthread_win32.pthread_ ## name != NULL); \
} while (0)
LOAD_PTHREAD_FUNC(attr_init);
LOAD_PTHREAD_FUNC(attr_destroy);
LOAD_PTHREAD_FUNC(attr_getstacksize);
LOAD_PTHREAD_FUNC(attr_setstacksize);
LOAD_PTHREAD_FUNC(mutex_init);
LOAD_PTHREAD_FUNC(mutex_destroy);
LOAD_PTHREAD_FUNC(mutex_lock);
LOAD_PTHREAD_FUNC(mutex_trylock);
LOAD_PTHREAD_FUNC(mutex_unlock);
LOAD_PTHREAD_FUNC(cond_init);
LOAD_PTHREAD_FUNC(cond_destroy);
LOAD_PTHREAD_FUNC(cond_wait);
LOAD_PTHREAD_FUNC(cond_timedwait);
LOAD_PTHREAD_FUNC(cond_signal);
LOAD_PTHREAD_FUNC(cond_broadcast);
LOAD_PTHREAD_FUNC(rwlock_init);
LOAD_PTHREAD_FUNC(rwlock_destroy);
LOAD_PTHREAD_FUNC(rwlock_rdlock);
LOAD_PTHREAD_FUNC(rwlock_wrlock);
LOAD_PTHREAD_FUNC(rwlock_unlock);
LOAD_PTHREAD_FUNC(create);
LOAD_PTHREAD_FUNC(join);
LOAD_PTHREAD_FUNC(self);
LOAD_PTHREAD_FUNC(key_create);
LOAD_PTHREAD_FUNC(key_delete);
LOAD_PTHREAD_FUNC(getspecific);
LOAD_PTHREAD_FUNC(setspecific);
#undef LOAD_PTHREAD_FUNC
}
return r;
}
//TODO: Call in brt_destroy
int toku_pthread_win32_destroy(void) {
assert(pthread_win32_dll != NULL);
BOOL succ = FreeLibrary(pthread_win32_dll);
assert(succ);
return 0;
}

View file

@ -1,336 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ifndef _TOKU_PTHREAD_H
#define _TOKU_PTHREAD_H
#if defined(__cplusplus)
extern "C" {
#endif
#include "pthread.h"
#include <toku_time.h>
#define USE_PTHREADS_WIN32_RWLOCKS 0
int toku_pthread_win32_init(void);
int toku_pthread_win32_destroy(void);
typedef pthread_attr_t toku_pthread_attr_t;
typedef pthread_t toku_pthread_t;
typedef pthread_mutexattr_t toku_pthread_mutexattr_t;
typedef pthread_mutex_t toku_pthread_mutex_t;
typedef pthread_condattr_t toku_pthread_condattr_t;
typedef pthread_cond_t toku_pthread_cond_t;
static inline int toku_pthread_cond_init(toku_pthread_cond_t *cond, const toku_pthread_condattr_t *attr);
static inline int toku_pthread_cond_destroy(toku_pthread_cond_t *cond);
static inline int toku_pthread_cond_wait(toku_pthread_cond_t *cond, toku_pthread_mutex_t *mutex);
static inline int toku_pthread_cond_signal(toku_pthread_cond_t *cond);
static inline int toku_pthread_cond_broadcast(toku_pthread_cond_t *cond);
#if USE_PTHREADS_WIN32_RWLOCKS
typedef pthread_rwlock_t toku_pthread_rwlock_t;
typedef pthread_rwlockattr_t toku_pthread_rwlockattr_t;
#else
#include "../ft/rwlock.h"
typedef struct toku_pthread_rwlock_struct {
struct rwlock rwlock;
toku_pthread_mutex_t mutex;
} toku_pthread_rwlock_t;
typedef struct toku_pthread_rwlockattr_struct {
} toku_pthread_rwlockattr_t;
#endif
typedef pthread_key_t toku_pthread_key_t;
//typedef struct timespec toku_timespec_t; //Already defined in toku_time.h
typedef int (__cdecl *toku_pthread_win32_rwlock_init_func) (pthread_rwlock_t *lock, const pthread_rwlockattr_t *attr);
typedef int (__cdecl *toku_pthread_win32_rwlock_destroy_func) (pthread_rwlock_t *lock);
typedef int (__cdecl *toku_pthread_win32_rwlock_rdlock_func) (pthread_rwlock_t *rwlock);
typedef int (__cdecl *toku_pthread_win32_rwlock_wrlock_func) (pthread_rwlock_t *rwlock);
typedef int (__cdecl *toku_pthread_win32_rwlock_unlock_func) (pthread_rwlock_t *rwlock);
typedef int (__cdecl *toku_pthread_win32_attr_init_func) (pthread_attr_t *attr);
typedef int (__cdecl *toku_pthread_win32_attr_destroy_func) (pthread_attr_t *attr);
typedef int (__cdecl *toku_pthread_win32_attr_getstacksize_func)(pthread_attr_t *attr, size_t *stacksize);
typedef int (__cdecl *toku_pthread_win32_attr_setstacksize_func)(pthread_attr_t *attr, size_t stacksize);
typedef int (__cdecl *toku_pthread_win32_create_func) (pthread_t *thread, const pthread_attr_t *attr, void *(*start_function)(void *), void *arg);
typedef int (__cdecl *toku_pthread_win32_join_func) (pthread_t thread, void **value_ptr);
typedef pthread_t (__cdecl *toku_pthread_win32_self_func)(void);
typedef int (__cdecl *toku_pthread_win32_mutex_init_func) (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
typedef int (__cdecl *toku_pthread_win32_mutex_destroy_func) (pthread_mutex_t *mutex);
typedef int (__cdecl *toku_pthread_win32_mutex_lock_func) (pthread_mutex_t *mutex);
typedef int (__cdecl *toku_pthread_win32_mutex_trylock_func) (pthread_mutex_t *mutex);
typedef int (__cdecl *toku_pthread_win32_mutex_unlock_func) (pthread_mutex_t *mutex);
typedef int (__cdecl *toku_pthread_win32_cond_init_func) (pthread_cond_t *cond, const pthread_condattr_t *attr);
typedef int (__cdecl *toku_pthread_win32_cond_destroy_func) (pthread_cond_t *cond);
typedef int (__cdecl *toku_pthread_win32_cond_wait_func) (pthread_cond_t *cond, pthread_mutex_t *mutex);
typedef int (__cdecl *toku_pthread_win32_cond_timedwait_func) (pthread_cond_t *cond, pthread_mutex_t *mutex, toku_timespec_t *wakeup_at);
typedef int (__cdecl *toku_pthread_win32_cond_signal_func) (pthread_cond_t *cond);
typedef int (__cdecl *toku_pthread_win32_cond_broadcast_func) (pthread_cond_t *cond);
typedef int (__cdecl *toku_pthread_win32_key_create_func) (pthread_key_t *key, void (*destroyf)(void *));
typedef int (__cdecl *toku_pthread_win32_key_delete_func) (pthread_key_t key);
typedef void *(__cdecl *toku_pthread_win32_getspecific_func) (pthread_key_t key);
typedef int (__cdecl *toku_pthread_win32_setspecific_func) (pthread_key_t key, void *data);
typedef struct toku_pthread_win32_funcs_struct {
toku_pthread_win32_attr_init_func pthread_attr_init;
toku_pthread_win32_attr_destroy_func pthread_attr_destroy;
toku_pthread_win32_attr_getstacksize_func pthread_attr_getstacksize;
toku_pthread_win32_attr_setstacksize_func pthread_attr_setstacksize;
toku_pthread_win32_mutex_init_func pthread_mutex_init;
toku_pthread_win32_mutex_destroy_func pthread_mutex_destroy;
toku_pthread_win32_mutex_lock_func pthread_mutex_lock;
toku_pthread_win32_mutex_trylock_func pthread_mutex_trylock;
toku_pthread_win32_mutex_unlock_func pthread_mutex_unlock;
toku_pthread_win32_cond_init_func pthread_cond_init;
toku_pthread_win32_cond_destroy_func pthread_cond_destroy;
toku_pthread_win32_cond_wait_func pthread_cond_wait;
toku_pthread_win32_cond_timedwait_func pthread_cond_timedwait;
toku_pthread_win32_cond_signal_func pthread_cond_signal;
toku_pthread_win32_cond_broadcast_func pthread_cond_broadcast;
toku_pthread_win32_rwlock_init_func pthread_rwlock_init;
toku_pthread_win32_rwlock_destroy_func pthread_rwlock_destroy;
toku_pthread_win32_rwlock_rdlock_func pthread_rwlock_rdlock;
toku_pthread_win32_rwlock_wrlock_func pthread_rwlock_wrlock;
toku_pthread_win32_rwlock_unlock_func pthread_rwlock_unlock;
toku_pthread_win32_create_func pthread_create;
toku_pthread_win32_join_func pthread_join;
toku_pthread_win32_self_func pthread_self;
toku_pthread_win32_key_create_func pthread_key_create;
toku_pthread_win32_key_delete_func pthread_key_delete;
toku_pthread_win32_getspecific_func pthread_getspecific;
toku_pthread_win32_setspecific_func pthread_setspecific;
} toku_pthread_win32_funcs;
extern toku_pthread_win32_funcs pthread_win32;
int toku_pthread_yield(void);
static inline
int toku_pthread_attr_init(toku_pthread_attr_t *attr) {
return pthread_win32.pthread_attr_init(attr);
}
static inline
int toku_pthread_attr_destroy(toku_pthread_attr_t *attr) {
return pthread_win32.pthread_attr_destroy(attr);
}
static inline
int toku_pthread_attr_getstacksize(toku_pthread_attr_t *attr, size_t *stacksize) {
return pthread_win32.pthread_attr_getstacksize(attr, stacksize);
}
static inline
int toku_pthread_attr_setstacksize(toku_pthread_attr_t *attr, size_t stacksize) {
return pthread_win32.pthread_attr_setstacksize(attr, stacksize);
}
static inline
int toku_pthread_create(toku_pthread_t *thread, const toku_pthread_attr_t *attr, void *(*start_function)(void *), void *arg) {
return pthread_win32.pthread_create(thread, attr, start_function, arg);
}
static inline
int toku_pthread_join(toku_pthread_t thread, void **value_ptr) {
return pthread_win32.pthread_join(thread, value_ptr);
}
static inline
toku_pthread_t toku_pthread_self(void) {
return pthread_win32.pthread_self();
}
#define TOKU_PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
static inline
int toku_pthread_mutex_init(toku_pthread_mutex_t *mutex, const toku_pthread_mutexattr_t *attr) {
return pthread_win32.pthread_mutex_init(mutex, attr);
}
static inline
int toku_pthread_mutex_destroy(toku_pthread_mutex_t *mutex) {
return pthread_win32.pthread_mutex_destroy(mutex);
}
static inline
int toku_pthread_mutex_lock(toku_pthread_mutex_t *mutex) {
return pthread_win32.pthread_mutex_lock(mutex);
}
static inline int
toku_pthread_mutex_trylock(toku_pthread_mutex_t *mutex) {
return pthread_win32.pthread_mutex_trylock(mutex);
}
static inline
int toku_pthread_mutex_unlock(toku_pthread_mutex_t *mutex) {
return pthread_win32.pthread_mutex_unlock(mutex);
}
static inline
int toku_pthread_cond_init(toku_pthread_cond_t *cond, const toku_pthread_condattr_t *attr) {
return pthread_win32.pthread_cond_init(cond, attr);
}
static inline
int toku_pthread_cond_destroy(toku_pthread_cond_t *cond) {
return pthread_win32.pthread_cond_destroy(cond);
}
static inline
int toku_pthread_cond_wait(toku_pthread_cond_t *cond, toku_pthread_mutex_t *mutex) {
return pthread_win32.pthread_cond_wait(cond, mutex);
}
static inline
int toku_pthread_cond_timedwait(toku_pthread_cond_t *cond, toku_pthread_mutex_t *mutex, toku_timespec_t *wakeup_at) {
return pthread_win32.pthread_cond_timedwait(cond, mutex, wakeup_at);
}
static inline
int toku_pthread_cond_signal(toku_pthread_cond_t *cond) {
return pthread_win32.pthread_cond_signal(cond);
}
static inline
int toku_pthread_cond_broadcast(toku_pthread_cond_t *cond) {
return pthread_win32.pthread_cond_broadcast(cond);
}
static inline int
toku_pthread_key_create(pthread_key_t *key, void (*destroyf)(void *)) {
return pthread_win32.pthread_key_create(key, destroyf);
}
static inline int
toku_pthread_key_delete(pthread_key_t key) {
return pthread_win32.pthread_key_delete(key);
}
static inline void*
toku_pthread_getspecific(pthread_key_t key) {
return pthread_win32.pthread_getspecific(key);
}
static inline int
toku_pthread_setspecific(pthread_key_t key, void *data) {
return pthread_win32.pthread_setspecific(key, data);
}
#if USE_PTHREADS_WIN32_RWLOCKS
static inline int
toku_pthread_rwlock_init(toku_pthread_rwlock_t *__restrict rwlock, const toku_pthread_rwlockattr_t *__restrict attr) {
return pthread_win32.pthread_rwlock_init(rwlock, attr);
}
static inline int
toku_pthread_rwlock_destroy(toku_pthread_rwlock_t *rwlock) {
return pthread_win32.pthread_rwlock_destroy(rwlock);
}
static inline int
toku_pthread_rwlock_rdlock(toku_pthread_rwlock_t *rwlock) {
return pthread_win32.pthread_rwlock_rdlock(rwlock);
}
static inline int
toku_pthread_rwlock_rdunlock(toku_pthread_rwlock_t *rwlock) {
return pthread_win32.pthread_rwlock_unlock(rwlock);
}
static inline int
toku_pthread_rwlock_wrlock(toku_pthread_rwlock_t *rwlock) {
return pthread_win32.pthread_rwlock_wrlock(rwlock);
}
static inline int
toku_pthread_rwlock_wrunlock(toku_pthread_rwlock_t *rwlock) {
return pthread_win32.pthread_rwlock_unlock(rwlock);
}
#else
static inline int
toku_pthread_rwlock_init(toku_pthread_rwlock_t *__restrict rwlock, const toku_pthread_rwlockattr_t *__restrict attr) {
int r = 0;
if (attr!=NULL) r = EINVAL;
if (r==0)
r = toku_pthread_mutex_init(&rwlock->mutex, NULL);
if (r==0)
rwlock_init(&rwlock->rwlock);
return r;
}
static inline int
toku_pthread_rwlock_destroy(toku_pthread_rwlock_t *rwlock) {
int r = 0;
rwlock_destroy(&rwlock->rwlock);
r = toku_pthread_mutex_destroy(&rwlock->mutex);
return r;
}
static inline int
toku_pthread_rwlock_rdlock(toku_pthread_rwlock_t *rwlock) {
int r = 0;
r = toku_pthread_mutex_lock(&rwlock->mutex);
assert(r==0);
//We depend on recursive read locks.
rwlock_prefer_read_lock(&rwlock->rwlock, &rwlock->mutex);
r = toku_pthread_mutex_unlock(&rwlock->mutex);
assert(r==0);
return r;
}
static inline int
toku_pthread_rwlock_rdunlock(toku_pthread_rwlock_t *rwlock) {
int r = 0;
r = toku_pthread_mutex_lock(&rwlock->mutex);
assert(r==0);
rwlock_read_unlock(&rwlock->rwlock);
r = toku_pthread_mutex_unlock(&rwlock->mutex);
assert(r==0);
return r;
}
static inline int
toku_pthread_rwlock_wrlock(toku_pthread_rwlock_t *rwlock) {
int r = 0;
r = toku_pthread_mutex_lock(&rwlock->mutex);
assert(r==0);
rwlock_write_lock(&rwlock->rwlock, &rwlock->mutex);
r = toku_pthread_mutex_unlock(&rwlock->mutex);
assert(r==0);
return r;
}
static inline int
toku_pthread_rwlock_wrunlock(toku_pthread_rwlock_t *rwlock) {
int r = 0;
r = toku_pthread_mutex_lock(&rwlock->mutex);
assert(r==0);
rwlock_write_unlock(&rwlock->rwlock);
r = toku_pthread_mutex_unlock(&rwlock->mutex);
assert(r==0);
return r;
}
#endif
int
initialize_pthread_functions();
int
pthread_functions_free();
#if defined(__cplusplus)
};
#endif
#endif

View file

@ -1,10 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ifndef TOKU_STDINT_H
#define TOKU_STDINT_H
#include <stdint.h>
#include <inttypes.h>
#endif

View file

@ -1,22 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ifndef _TOKU_STDLIB_H
#define _TOKU_STDLIB_H
#include <stdlib.h>
#if defined(__cplusplus)
extern "C" {
#endif
long int random(void);
void srandom(unsigned int seed);
int unsetenv(const char *name);
int setenv(const char *name, const char *value, int overwrite);
#if defined(__cplusplus)
};
#endif
#endif

View file

@ -1,52 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#include <toku_portability.h>
#include <windows.h>
#include <toku_assert.h>
#include <toku_time.h>
int
gettimeofday(struct timeval *tv, struct timezone *tz) {
FILETIME filetime;
ULARGE_INTEGER t;
GetSystemTimeAsFileTime(&filetime);
t.u.LowPart = filetime.dwLowDateTime;
t.u.HighPart = filetime.dwHighDateTime;
t.QuadPart -= 116444736000000000i64;
t.QuadPart /= 10; // convert to microseconds
if (tv) {
tv->tv_sec = t.QuadPart / 1000000;
tv->tv_usec = t.QuadPart % 1000000;
}
if (tz) {
assert(0);
}
return 0;
}
static int
clock_get_realtime(toku_timespec_t *ts) {
FILETIME filetime;
ULARGE_INTEGER t;
GetSystemTimeAsFileTime(&filetime);
t.u.LowPart = filetime.dwLowDateTime;
t.u.HighPart = filetime.dwHighDateTime;
t.QuadPart -= 116444736000000000i64;
t.QuadPart *= 100; // convert to nanoseconds
if (ts) {
ts->tv_sec = t.QuadPart / 1000000000;
ts->tv_nsec = t.QuadPart % 1000000000;
}
return 0;
}
int
clock_gettime(clockid_t clockid, toku_timespec_t *ts) {
if (clockid == CLOCK_REALTIME)
return clock_get_realtime(ts);
else
return -1;
}

View file

@ -1,39 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ifndef TOKU_TIME_H
#define TOKU_TIME_H
#include <windows.h>
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
struct timezone {
int tz_minuteswest;
int tz_dsttime;
};
int gettimeofday(struct timeval *tv, struct timezone *tz);
typedef enum {
CLOCK_REALTIME = 0
} clockid_t;
typedef struct toku_timespec_struct {
long tv_sec;
long tv_nsec;
} toku_timespec_t;
int clock_gettime(clockid_t clock_id, toku_timespec_t *ts);
static inline float toku_tdiff (struct timeval *a, struct timeval *b) {
return (a->tv_sec - b->tv_sec) +1e-6*(a->tv_usec - b->tv_usec);
}
#ifdef __cplusplus
};
#endif
#endif

View file

@ -1,40 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#ifndef _TOKUWIN_UNISTD_H
#define _TOKUWIN_UNISTD_H
#if defined(__cplusplus)
extern "C" {
#endif
#include <io.h>
#include <stdio.h>
#include <stdint.h>
#include <getopt.h>
int fsync(int fildes);
int
ftruncate(int fildes, toku_off_t offset);
int
truncate(const char *path, toku_off_t length);
int64_t
pwrite(int fildes, const void *buf, size_t nbyte, int64_t offset);
int64_t
pread(int fildes, void *buf, size_t nbyte, int64_t offset);
unsigned int
sleep(unsigned int);
int
usleep(unsigned int);
#if defined(__cplusplus)
};
#endif
#endif

View file

@ -1,378 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
#define _CRT_SECURE_NO_DEPRECATE
//rand_s requires _CRT_RAND_S be defined before including stdlib
#define _CRT_RAND_S
#include <stdlib.h>
#include <toku_portability.h>
#include <windows.h>
#include <dirent.h>
#include <toku_assert.h>
#include <direct.h>
#include <errno.h>
#include <io.h>
#include <malloc.h>
#include <process.h>
#include <share.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <Crtdbg.h>
#include <string.h>
static int
toku_malloc_init(void) {
int r = 0;
#if TOKU_WINDOWS_32
//Set the heap (malloc/free/realloc) to use the low fragmentation mode.
ULONG HeapFragValue = 2;
int success;
success = HeapSetInformation(GetProcessHeap(),
HeapCompatibilityInformation,
&HeapFragValue,
sizeof(HeapFragValue));
//if (success==0) //Do some error output if necessary.
if (!success)
r = GetLastError();
#endif
return r;
}
int
toku_portability_init(void) {
int r = 0;
if (r==0)
r = toku_malloc_init();
if (r==0)
r = toku_pthread_win32_init();
if (r==0)
r = toku_fsync_init();
if (r==0)
r = toku_mkstemp_init();
if (r==0)
_fmode = _O_BINARY; //Default open file is BINARY
return r;
}
int
toku_portability_destroy(void) {
int r = 0;
if (r==0)
r = toku_mkstemp_destroy();
if (r==0)
r = toku_fsync_destroy();
if (r==0)
r = toku_pthread_win32_destroy();
return r;
}
int
toku_os_get_file_size(int fildes, int64_t *sizep) {
int r;
int64_t size = _filelengthi64(fildes);
if (size<0) r = errno;
else {
r = 0;
*sizep = size;
}
return r;
}
uint64_t
toku_os_get_phys_memory_size(void) {
MEMORYSTATUS memory_status;
GlobalMemoryStatus(&memory_status);
return memory_status.dwTotalPhys;
}
int
toku_os_get_number_processors(void) {
SYSTEM_INFO system_info;
GetSystemInfo(&system_info);
return system_info.dwNumberOfProcessors;
}
int
toku_os_get_number_active_processors(void) {
SYSTEM_INFO system_info;
DWORD mask, n;
GetSystemInfo(&system_info);
mask = system_info.dwActiveProcessorMask;
for (n=0; mask; mask >>= 1)
n += mask & 1;
return n;
}
int
toku_os_get_pagesize(void) {
SYSTEM_INFO system_info;
GetSystemInfo(&system_info);
return system_info.dwPageSize;
}
int
toku_os_get_unique_file_id(int fildes, struct fileid *id) {
int r;
BY_HANDLE_FILE_INFORMATION info;
HANDLE filehandle;
memset(id, 0, sizeof(*id));
memset(&info, 0, sizeof(info));
filehandle = (HANDLE)_get_osfhandle(fildes);
if (filehandle==INVALID_HANDLE_VALUE) {
r = errno; assert(r!=0);
goto cleanup;
}
r = GetFileInformationByHandle(filehandle, &info);
if (r==0) { //0 is error here.
r = GetLastError(); assert(r!=0);
if (r==ERROR_INVALID_FUNCTION && info.dwVolumeSerialNumber == 0 &&
info.nFileIndexHigh == 0 && info.nFileIndexLow == 0) {
//"NUL" will return this.
//TODO: Remove this hack somehow
r = 0;
goto continue_dev_null;
}
goto cleanup;
}
//Make sure only "NUL" returns all zeros.
assert(info.dwVolumeSerialNumber!=0 || info.nFileIndexHigh!=0 || info.nFileIndexLow!=0);
continue_dev_null: //Skip zeros check (its allowed here).
id->st_dev = info.dwVolumeSerialNumber;
id->st_ino = info.nFileIndexHigh;
id->st_ino <<= 32;
id->st_ino |= info.nFileIndexLow;
r = 0;
cleanup:
if (r!=0) {
errno = r;
r = -1;
}
return r;
}
static void
convert_filetime_timeval(FILETIME filetime, struct timeval *tv) {
ULARGE_INTEGER t;
t.u.HighPart = filetime.dwHighDateTime;
t.u.LowPart = filetime.dwLowDateTime;
t.QuadPart /= 10;
if (tv) {
tv->tv_sec = t.QuadPart / 1000000;
tv->tv_usec = t.QuadPart % 1000000;
}
}
int
toku_os_get_process_times(struct timeval *usertime, struct timeval *kerneltime) {
FILETIME w_createtime, w_exittime, w_usertime, w_kerneltime;
if (GetProcessTimes(GetCurrentProcess(), &w_createtime, &w_exittime, &w_kerneltime, &w_usertime)) {
convert_filetime_timeval(w_usertime, usertime);
convert_filetime_timeval(w_kerneltime, kerneltime);
return 0;
}
return GetLastError();
}
int
toku_os_getpid(void) {
#if 0
return _getpid();
#else
return GetCurrentProcessId();
#endif
}
int
toku_os_gettid(void) {
return GetCurrentThreadId();
}
int
toku_os_get_max_process_data_size(uint64_t *maxdata) {
#if TOKU_WINDOWS_32
// the process gets 1/2 of the 32 bit address space.
// we are ignoring the 3GB feature for now.
*maxdata = 1ULL << 31;
return 0;
#elif TOKU_WINDOWS_64
*maxdata = ~0ULL;
return 0;
#else
#error
return EINVAL;
#endif
}
int
toku_os_lock_file(char *name) {
int fd = _sopen(name, O_CREAT, _SH_DENYRW, S_IREAD|S_IWRITE);
return fd;
}
int
toku_os_unlock_file(int fildes) {
int r = close(fildes);
return r;
}
int
toku_os_mkdir(const char *pathname, mode_t mode) {
int r = mkdir(pathname);
UNUSED_WARNING(mode);
if (r!=0) r = errno;
return r;
}
static void printfParameterHandler(const wchar_t* expression,
const wchar_t* function, const wchar_t* file,
unsigned int line, uintptr_t pReserved) {
fwprintf(stderr, L"Invalid parameter detected in function %s."
L" File: %s Line: %d\n"
L"Expression: %s\n", function, file, line, expression);
}
static void ignoreParameterHandler(const wchar_t* expression,
const wchar_t* function, const wchar_t* file,
unsigned int line, uintptr_t pReserved) {
UNUSED_WARNING(expression);
UNUSED_WARNING(function);
UNUSED_WARNING(file);
UNUSED_WARNING(line);
UNUSED_WARNING(pReserved);
}
int
toku_os_initialize_settings(int verbosity) {
int r;
static int initialized = 0;
assert(initialized==0);
initialized=1;
if (verbosity>0)
_set_invalid_parameter_handler(printfParameterHandler);
else
_set_invalid_parameter_handler(ignoreParameterHandler);
#if defined(_DEBUG)
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
#endif
r = 0;
return r;
}
int
toku_os_is_absolute_name(const char* path) {
return (path[0] == '\\' ||
path[0] == '/' ||
(isalpha(path[0]) && path[1]==':' && path[2]=='\\') ||
(isalpha(path[0]) && path[1]==':' && path[2]=='/'));
}
int
vsnprintf(char *str, size_t size, const char *format, va_list ap) {
int r = _vsnprintf(str, size, format, ap);
if (str && size>0) {
str[size-1] = '\0'; //Always null terminate.
if (r<0 && errno==ERANGE) {
r = strlen(str)+1; //Mimic linux return value.
//May be too small, but it does
//at least indicate overflow
}
}
return r;
}
int
snprintf(char *str, size_t size, const char *format, ...) {
va_list ap;
va_start(ap, format);
int r = vsnprintf(str, size, format, ap);
va_end(ap);
return r;
}
#include <PowrProf.h>
#define TOKU_MICROSOFT_DID_NOT_DEFINE_PROCESSOR_POWER_INFORMATION 1
#if TOKU_MICROSOFT_DID_NOT_DEFINE_PROCESSOR_POWER_INFORMATION
//From MSDN: (As of Windows 2000)
// Note that this structure definition was accidentally omitted from WinNT.h.
// This error will be corrected in the future. In the meantime, to compile your
// application, include the structure definition contained in this topic in your
// source code.
typedef struct _PROCESSOR_POWER_INFORMATION {
ULONG Number;
ULONG MaxMhz;
ULONG CurrentMhz;
ULONG MhzLimit;
ULONG MaxIdleState;
ULONG CurrentIdleState;
}PROCESSOR_POWER_INFORMATION, *PPROCESSOR_POWER_INFORMATION;
#endif
int
toku_os_get_processor_frequency(uint64_t *hzret) {
SYSTEM_INFO sys_info;
// find out how many processors we have in the system
GetSystemInfo(&sys_info);
PROCESSOR_POWER_INFORMATION infos[sys_info.dwNumberOfProcessors];
memset(infos, 0, sizeof(infos));
NTSTATUS r = CallNtPowerInformation(ProcessorInformation, NULL, 0, &infos[0], sizeof(infos));
assert(r==ERROR_SUCCESS);
uint64_t mhz = infos[0].MaxMhz;
*hzret = mhz * 1000000ULL;
return 0;
}
int
toku_dup2(int fd, int fd2) {
int r;
r = _dup2(fd, fd2);
if (r==0) //success
r = fd2;
return r;
}
// for now, just return zeros
int
toku_get_filesystem_sizes(const char *path, uint64_t *avail_size, uint64_t *free_size, uint64_t *total_size) {
int r;
ULARGE_INTEGER free_bytes_for_user;
ULARGE_INTEGER free_bytes_total;
ULARGE_INTEGER total_bytes;
BOOL success = GetDiskFreeSpaceEx(path,
&free_bytes_for_user,
&total_bytes,
&free_bytes_total);
if (success) {
r = 0;
if (avail_size) *avail_size = free_bytes_for_user.QuadPart;
if (free_size) *free_size = free_bytes_total.QuadPart;
if (total_size) *total_size = total_bytes.QuadPart;
}
else {
r = GetLastError();
}
return r;
}
int strerror_r(int errnum, char *buf, size_t buflen) {
int r = strerror_s(buf, buflen, errnum);
return r;
}

View file

@ -1,334 +0,0 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: expandtab:ts=8:sw=4:softtabstop=4:
/* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-2005 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#ifndef ZCONF_H
#define ZCONF_H
/*
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
*/
#ifdef Z_PREFIX
# define deflateInit_ z_deflateInit_
# define deflate z_deflate
# define deflateEnd z_deflateEnd
# define inflateInit_ z_inflateInit_
# define inflate z_inflate
# define inflateEnd z_inflateEnd
# define deflateInit2_ z_deflateInit2_
# define deflateSetDictionary z_deflateSetDictionary
# define deflateCopy z_deflateCopy
# define deflateReset z_deflateReset
# define deflateParams z_deflateParams
# define deflateBound z_deflateBound
# define deflatePrime z_deflatePrime
# define inflateInit2_ z_inflateInit2_
# define inflateSetDictionary z_inflateSetDictionary
# define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint
# define inflateCopy z_inflateCopy
# define inflateReset z_inflateReset
# define inflateBack z_inflateBack
# define inflateBackEnd z_inflateBackEnd
# define compress z_compress
# define compress2 z_compress2
# define compressBound z_compressBound
# define uncompress z_uncompress
# define adler32 z_adler32
# define crc32 z_crc32
# define get_crc_table z_get_crc_table
# define zError z_zError
# define alloc_func z_alloc_func
# define free_func z_free_func
# define in_func z_in_func
# define out_func z_out_func
# define Byte z_Byte
# define uInt z_uInt
# define uLong z_uLong
# define Bytef z_Bytef
# define charf z_charf
# define intf z_intf
# define uIntf z_uIntf
# define uLongf z_uLongf
# define voidpf z_voidpf
# define voidp z_voidp
#endif
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
#endif
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
# define OS2
#endif
#if defined(_WINDOWS) && !defined(WINDOWS)
# define WINDOWS
#endif
#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
# ifndef WIN32
# define WIN32
# endif
#endif
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
# ifndef SYS16BIT
# define SYS16BIT
# endif
# endif
#endif
/*
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
* than 64k bytes at a time (needed on systems with 16-bit int).
*/
#ifdef SYS16BIT
# define MAXSEG_64K
#endif
#ifdef MSDOS
# define UNALIGNED_OK
#endif
#ifdef __STDC_VERSION__
# ifndef STDC
# define STDC
# endif
# if __STDC_VERSION__ >= 199901L
# ifndef STDC99
# define STDC99
# endif
# endif
#endif
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
# define STDC
#endif
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
# define STDC
#endif
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
# define STDC
#endif
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
# define STDC
#endif
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
# define STDC
#endif
#ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# define const /* note: need a more gentle solution here */
# endif
#endif
/* Some Mac compilers merge all .h files incorrectly: */
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
# define NO_DUMMY_DECL
#endif
/* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL
# ifdef MAXSEG_64K
# define MAX_MEM_LEVEL 8
# else
# define MAX_MEM_LEVEL 9
# endif
#endif
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
* created by gzip. (Files created by minigzip can still be extracted by
* gzip.)
*/
#ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
/* The memory requirements for deflate are (in bytes):
(1 << (windowBits+2)) + (1 << (memLevel+9))
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
plus a few kilobytes for small objects. For example, if you want to reduce
the default memory requirements from 256K to 128K, compile with
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes
for small objects.
*/
/* Type declarations */
#ifndef OF /* function prototypes */
# ifdef STDC
# define OF(args) args
# else
# define OF(args) ()
# endif
#endif
/* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
* just define FAR to be empty.
*/
#ifdef SYS16BIT
# if defined(M_I86SM) || defined(M_I86MM)
/* MSC small or medium model */
# define SMALL_MEDIUM
# ifdef _MSC_VER
# define FAR _far
# else
# define FAR far
# endif
# endif
# if (defined(__SMALL__) || defined(__MEDIUM__))
/* Turbo C small or medium model */
# define SMALL_MEDIUM
# ifdef __BORLANDC__
# define FAR _far
# else
# define FAR far
# endif
# endif
#endif
#if defined(WINDOWS) || defined(WIN32)
/* If building or using zlib as a DLL, define ZLIB_DLL.
* This is not mandatory, but it offers a little performance increase.
*/
# ifdef ZLIB_DLL
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
# ifdef ZLIB_INTERNAL
# define ZEXTERN extern __declspec(dllexport)
# else
# define ZEXTERN extern __declspec(dllimport)
# endif
# endif
# endif /* ZLIB_DLL */
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
* define ZLIB_WINAPI.
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
*/
# ifdef ZLIB_WINAPI
# ifdef FAR
# undef FAR
# endif
# include <windows.h>
/* No need for _export, use ZLIB.DEF instead. */
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
# define ZEXPORT WINAPI
# ifdef WIN32
# define ZEXPORTVA WINAPIV
# else
# define ZEXPORTVA FAR CDECL
# endif
# endif
#endif
#if defined (__BEOS__)
# ifdef ZLIB_DLL
# ifdef ZLIB_INTERNAL
# define ZEXPORT __declspec(dllexport)
# define ZEXPORTVA __declspec(dllexport)
# else
# define ZEXPORT __declspec(dllimport)
# define ZEXPORTVA __declspec(dllimport)
# endif
# endif
#endif
#ifndef ZEXTERN
# define ZEXTERN extern
#endif
#ifndef ZEXPORT
# define ZEXPORT
#endif
#ifndef ZEXPORTVA
# define ZEXPORTVA
#endif
#ifndef FAR
# define FAR
#endif
#if !defined(__MACTYPES__)
typedef unsigned char Byte; /* 8 bits */
#endif
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
#ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR
#else
typedef Byte FAR Bytef;
#endif
typedef char FAR charf;
typedef int FAR intf;
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
#ifdef STDC
typedef void const *voidpc;
typedef void FAR *voidpf;
typedef void *voidp;
#else
typedef Byte const *voidpc;
typedef Byte FAR *voidpf;
typedef Byte *voidp;
#endif
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
# include <sys/types.h> /* for off_t */
# include <unistd.h> /* for SEEK_* and off_t */
# ifdef VMS
# include <unixio.h> /* for off_t */
# endif
# define z_off_t off_t
#endif
#ifndef SEEK_SET
# define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif
#ifndef z_off_t
# define z_off_t long
#endif
#if defined(__OS400__)
# define NO_vsnprintf
#endif
#if defined(__MVS__)
# define NO_vsnprintf
# ifdef FAR
# undef FAR
# endif
#endif
/* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__)
# pragma map(deflateInit_,"DEIN")
# pragma map(deflateInit2_,"DEIN2")
# pragma map(deflateEnd,"DEEND")
# pragma map(deflateBound,"DEBND")
# pragma map(inflateInit_,"ININ")
# pragma map(inflateInit2_,"ININ2")
# pragma map(inflateEnd,"INEND")
# pragma map(inflateSync,"INSY")
# pragma map(inflateSetDictionary,"INSEDI")
# pragma map(compressBound,"CMBND")
# pragma map(inflate_table,"INTABL")
# pragma map(inflate_fast,"INFA")
# pragma map(inflate_copyright,"INCOPY")
#endif
#endif /* ZCONF_H */

File diff suppressed because it is too large Load diff