Commit 0d44815b authored by Rich Prohaska's avatar Rich Prohaska Committed by Yoni Fogel

merge some tokudb.1032 into 1032b. addresses #1032

git-svn-id: file:///svn/toku/tokudb.1032b@7778 c7de825b-a66e-492c-adef-691d508d4ae1
parent ef434529
This diff is collapsed.
#if !defined(TOKU_OS_INTERFACE_H)
#define TOKU_OS_INTERFACE_H
#if defined __cplusplus
extern "C" {
#endif
#include "os-types.h"
// Returns: the current process id
int os_getpid(void);
// Returns: the current thread id
int os_gettid(void);
// Returns: the number of processors in the system
int os_get_number_processors(void);
// Returns: the number of active processors in the system
int os_get_number_active_processors(void);
// Returns: the system page size
int os_get_pagesize(void);
// Returns: the total number of bytes of physical memory
uint64_t os_get_phys_memory_size(void);
// Returns: 0 on success
// sets fsize to the number of bytes in a file
int os_get_file_size(int fildes, int64_t *fsize);
// Returns: 0 on success
// Initializes id as a unique fileid for fildes on success.
int os_get_unique_file_id(int fildes, struct fileid *id);
//Locks a file (should not be open to begin with).
//Returns: file descriptor (or -1 on error)
int os_lock_file(char *name);
//Unlocks and closes a file locked by os_lock_on_file
int os_unlock_file(int fildes);
int os_mkdir(const char *pathname, mode_t mode);
// Get the current process user and kernel use times
int os_get_process_times(struct timeval *usertime, struct timeval *kerneltime);
// Get the current in memory size (in bytes) of the current process
int os_get_rss(int64_t *rss);
// Get the maximum in memory size (in bytes) of the current process
int os_get_max_rss(int64_t *maxrss);
int os_initialize_settings(int verbosity);
#if defined __cplusplus
};
#endif
#endif
#ifndef TOKU_PORTABILITY_H
#define TOKU_PORTABILITY_H
#if defined __cplusplus
extern "C" {
#endif
// Portability layer
#define DEV_NULL_FILE "/dev/null"
#if defined(_MSC_VER)
// Microsoft compiler
#define TOKU_WINDOWS 1
#endif
#if defined(__INTEL_COMPILER)
// Intel compiler
#if defined(__ICL)
#define TOKU_WINDOWS 1
#endif
#undef DEV_NULL_FILE
#define DEV_NULL_FILE "NUL"
#endif
#if defined(TOKU_WINDOWS)
// Windows
// ntohl and htonl are defined in winsock.h
#include <winsock.h>
#include <direct.h>
#include <sys/types.h>
#include "stdint.h"
#include "inttypes.h"
#include "toku_pthread.h"
#include "unistd.h"
#include "misc.h"
#define UNUSED_WARNING(a) a=a /* To make up for missing attributes */
#if defined(__ICL)
#define __attribute__(x) /* Nothing */
#endif
#elif defined(__INTEL_COMPILER)
#if defined(__ICC)
// Intel linux
#include <stdint.h>
#include <inttypes.h>
#include <unistd.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/time.h>
#endif
#elif defined(__GNUC__)
// GCC linux
#include <stdint.h>
#include <inttypes.h>
#include <unistd.h>
#include <sys/types.h>
// Define ntohl using arpa/inet.h
#include <arpa/inet.h>
#include <sys/time.h>
#else
#error Not ICC and not GNUC. What compiler?
#endif
#include "os.h"
#define UU(x) x __attribute__((__unused__))
#if defined __cplusplus
};
#endif
#endif
# -*- Mode: Makefile -*-
.DEFAULT_GOAL=install
TOKUROOT=../
INCLUDEDIRS=-I$(TOKUROOT)include/linux -I$(TOKUROOT)newbrt
include $(TOKUROOT)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 = tokulinux.$(AEXT)
install: $(TARGET)
$(MAYBEATSIGN)cp $(TARGET) $(LIBPORTABILITY)
$(TARGET): $(OBJS)
clean:
$(MAYBEATSIGN)rm -rf $(TARGET) $(LIBPORTABILITY)
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <syscall.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <assert.h>
#include "portability.h"
#include "os.h"
int
os_getpid(void) {
return getpid();
}
int
os_gettid(void) {
return syscall(__NR_gettid);
}
int
os_get_number_processors(void) {
return sysconf(_SC_NPROCESSORS_CONF);
}
int
os_get_number_active_processors(void) {
return sysconf(_SC_NPROCESSORS_ONLN);
}
int
os_get_pagesize(void) {
return sysconf(_SC_PAGESIZE);
}
uint64_t
os_get_phys_memory_size(void) {
uint64_t npages = sysconf(_SC_PHYS_PAGES);
uint64_t pagesize = sysconf(_SC_PAGESIZE);
return npages*pagesize;
}
int
os_get_file_size(int fildes, int64_t *fsize) {
struct stat sbuf;
int r = fstat(fildes, &sbuf);
if (r==0) {
*fsize = sbuf.st_size;
}
return r;
}
int
os_get_unique_file_id(int fildes, struct fileid *id) {
struct stat statbuf;
memset(id, 0, sizeof(*id));
int r=fstat(fildes, &statbuf);
if (r==0) {
memset(id, 0, sizeof(*id));
id->st_dev = statbuf.st_dev;
id->st_ino = statbuf.st_ino;
}
return r;
}
int
os_lock_file(char *name) {
int r;
int fd = open(name, O_RDWR|O_CREAT, S_IRUSR | S_IWUSR);
if (fd>=0) {
r = flock(fd, LOCK_EX | LOCK_NB);
if (r!=0) {
r = errno; //Save errno from flock.
close(fd);
fd = -1; //Disable fd.
errno = r;
}
}
return fd;
}
int
os_unlock_file(int fildes) {
int r = flock(fildes, LOCK_UN);
if (r==0) r = close(fildes);
return r;
}
int
os_mkdir(const char *pathname, mode_t mode) {
int r = mkdir(pathname, mode);
return r;
}
int
os_get_process_times(struct timeval *usertime, struct timeval *kerneltime) {
int r;
struct rusage rusage;
r = getrusage(RUSAGE_SELF, &rusage);
if (r == -1)
return errno;
if (usertime)
*usertime = rusage.ru_utime;
if (kerneltime)
*kerneltime = rusage.ru_stime;
return 0;
}
int
os_initialize_settings(int UU(verbosity)) {
int r = 0;
static int initialized = 0;
assert(initialized==0);
initialized=1;
return r;
}
int
os_get_max_rss(int64_t *maxrss) {
char statusname[100];
sprintf(statusname, "/proc/%d/status", getpid());
FILE *f = fopen(statusname, "r");
if (f == NULL)
return errno;
int r = ENOENT;
char line[100];
while (fgets(line, sizeof line, f)) {
r = sscanf(line, "VmHWM:\t%lld kB\n", (long long *) maxrss);
if (r == 1) {
*maxrss *= 1<<10;
r = 0;
break;
}
}
fclose(f);
return r;
}
int
os_get_rss(int64_t *rss) {
char statusname[100];
sprintf(statusname, "/proc/%d/status", getpid());
FILE *f = fopen(statusname, "r");
if (f == NULL)
return errno;
int r = ENOENT;
char line[100];
while (fgets(line, sizeof line, f)) {
r = sscanf(line, "VmRSS:\t%lld kB\n", (long long *) rss);
if (r == 1) {
*rss *= 1<<10;
r = 0;
break;
}
}
fclose(f);
return r;
}
#if !defined(OS_INTERFACE_LINUX_H)
#define OS_INTERFACE_LINUX_H
#include <sys/types.h>
typedef int os_handle_t;
struct fileid {
dev_t st_dev; /* device and inode are enough to uniquely identify a file in unix. */
ino_t st_ino;
};
#if !defined(O_BINARY)
#define O_BINARY 0
#endif
#endif
CPPFLAGS = -I../../include
CFLAGS = -Wall -Werror -g -O0
LDFLAGS = ../tokulinux.a
SRCS = $(wildcard test-*.c)
TARGETS = $(patsubst %.c,%,$(SRCS))
all: $(TARGETS)
%: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< $(LDFLAGS)
clean:
rm -rf $(TARGETS)
\ No newline at end of file
#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <assert.h>
#include "os.h"
int main(void) {
assert(os_get_pagesize() == getpagesize());
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include <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 main(void) {
int64_t rss;
os_get_max_rss(&rss);
printf("%"PRId64"\n", rss);
do_mallocs();
os_get_max_rss(&rss);
printf("%"PRId64"\n", rss);
return 0;
}
#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <assert.h>
#include "os.h"
#include <syscall.h>
int os_getpid(void);
static int gettid(void) {
return syscall(__NR_gettid);
}
int main(void) {
assert(os_getpid() == getpid());
assert(os_gettid() == gettid());
return 0;
}
#define _GNU_SOURCE 1
#include <toku_pthread.h>
int toku_pthread_yield(void) {
return pthread_yield();
}
#ifndef _TOKU_PTHREAD_H
#define _TOKU_PTHREAD_H
#if defined __cplusplus
extern "C" {
#endif
#include <pthread.h>
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;
int toku_pthread_yield(void);
static inline
int toku_pthread_attr_init(toku_pthread_attr_t *attr) {
return pthread_attr_init(attr);
}
static inline
int toku_pthread_attr_destroy(toku_pthread_attr_t *attr) {
return pthread_attr_destroy(attr);
}
static inline
int toku_pthread_attr_getstacksize(toku_pthread_attr_t *attr, size_t *stacksize) {
return pthread_attr_getstacksize(attr, stacksize);
}
static inline
int toku_pthread_attr_setstacksize(toku_pthread_attr_t *attr, size_t stacksize) {
return 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_create(thread, attr, start_function, arg);
}
static inline
int toku_pthread_join(toku_pthread_t thread, void **value_ptr) {
return pthread_join(thread, value_ptr);
}
static inline
toku_pthread_t toku_pthread_self(void) {
return 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_mutex_init(mutex, attr);
}
static inline
int toku_pthread_mutex_destroy(toku_pthread_mutex_t *mutex) {
return pthread_mutex_destroy(mutex);
}
static inline
int toku_pthread_mutex_lock(toku_pthread_mutex_t *mutex) {
return pthread_mutex_lock(mutex);
}
int toku_pthread_mutex_trylock(toku_pthread_mutex_t *mutex);
static inline
int toku_pthread_mutex_unlock(toku_pthread_mutex_t *mutex) {
return pthread_mutex_unlock(mutex);
}
static inline
int toku_pthread_cond_init(toku_pthread_cond_t *cond, const toku_pthread_condattr_t *attr) {
return pthread_cond_init(cond, attr);
}
static inline
int toku_pthread_cond_destroy(toku_pthread_cond_t *cond) {
return pthread_cond_destroy(cond);
}
static inline
int toku_pthread_cond_wait(toku_pthread_cond_t *cond, toku_pthread_mutex_t *mutex) {
return pthread_cond_wait(cond, mutex);
}
static inline
int toku_pthread_cond_signal(toku_pthread_cond_t *cond) {
return pthread_cond_signal(cond);
}
static inline
int toku_pthread_cond_broadcast(toku_pthread_cond_t *cond) {
return pthread_cond_broadcast(cond);
}
#if defined __cplusplus
};
#endif
#endif
# On cygwin do:
# make CYGWIN=cygwin check
# -*- Mode: Makefile -*-
# For verbose output do
# make VERBOSE=1
# For very verbose output do
# make VERBOSE=2
.DEFAULT_GOAL= build
TOKUROOT=../
INCLUDEDIRS=-I.
COMBINE=1
#TODO: Replace DEPEND_COMPILE with auto-dependancy generation.
DEPEND_COMPILE += \
$(wildcard *.h) \
log_header.h \
# keep this line so I can have a \ on the previous line
# For CIL do
# make CIL=1
NEWBRT = newbrt.$(AEXT)
#All executables need to statically link to newbrt
LINK_FILES += $(NEWBRT)
# GCOV_FLAGS = -fprofile-arcs -ftest-coverage
# PROF_FLAGS = -pg
OPTFLAGS = -O3
SKIP_NEWBRTRULE=1
include $(TOKUROOT)include/Makefile.include
ifeq ($(VERBOSE),2)
VERBVERBOSE=-v
MAYBEATSIGN=
else
ifeq ($(VERBOSE),1)
VERBVERBOSE=-q
MAYBEATSIGN=
else
VERBVERBOSE=-q
MAYBEATSIGN=@
endif
endif
#CFLAG default options
WERROR = -Werror
WALL = -Wall -Wextra -Wcast-align -Wbad-function-cast
FORMAT = -Wmissing-format-attribute
VISIBILITY= -fvisibility=hidden
FPICFLAGS = -fPIC
SHADOW = -Wshadow
SYMBOLS = -g3 -ggdb3
PORTABILITY=
SKIP_WARNING=
COMBINE_C = -combine -c
LINK_FILES= -lz -lpthread
C99 = -std=c99
#Tools
VGRIND = valgrind --quiet --error-exitcode=1 --leak-check=yes
ifeq ($(CC),icc)
#icc only:
OPTFLAGS = -O3 -ip
COMBINE_C = -ipo-c
FORMAT= #No argument for extra format warnings.
WALL = -Wall -Wcheck # '-Wextra' becomes '-Wcheck' in icc
SYMBOLS= -g -debug all -inline-debug-info
PORTABILITY=-diag-enable port-win
ifneq ($(CYGWIN),)
#Cygwin
ICC_NOWARN=-Qdiag-disable:
else
#Linux
ICC_NOWARN=-diag-disable #Need the space
endif
SKIP_WARNING += $(ICC_NOWARN)177 # Don't complain about static variables that are not used.
#SKIP_WARNING += $(ICC_NOWARN)188 # Don't complain about enumerated type mixed with another type.
SKIP_WARNING += $(ICC_NOWARN)589 # Don't complain about goto into a block that skips initializing variables. GCC catches the actual uninitialized variables.
SKIP_WARNING += $(ICC_NOWARN)869 # Don't complain about unused variables (since we defined __attribute__ to be nothing.)
SKIP_WARNING += $(ICC_NOWARN)981 # Don't complain about "operands are evaluated in unspecified order". This seems to be generated whenever more than one argument to a function or operand is computed by function call.
SKIP_WARNING += $(ICC_NOWARN)1324 # Don't complain about rdtsc clobbering its registers more than once.
endif
ifneq ($(CYGWIN),)
#Cygwin (Windows) Must override some settings
CYG_ADD_LIBZ=/usr/lib/libz.a
VGRIND =#No Valgrind in cygwin
FPICFLAGS=#FPIC is default and not allowed as an option.
VISIBILITY=#Not supported
SHADOW=#Not supported
ifeq ($(CC),icc)
#Cygwin icc only
C99 = -Qstd=c99
OPTFLAGS = -Ox -Qip -Qipo2
COMBINE_C = -Qipo-c
WERROR = -WX # Windows icc version of -Werror
SYMBOLS= -Zi -debug:all -Qinline-debug-info
PORTABILITY=
LINK_FILES=#Not supported
SKIP_WARNING += $(ICC_NOWARN)1786 # Don't complain about 'read/write/other standards' being deprecated
else
#Cygwin gcc only
FORMAT = -Wno-format
endif
endif
CFLAGS = $(WALL) $(WERROR) $(FORMAT) $(VISIBILITY) $(FPICFLAGS) $(SHADOW)
CFLAGS += $(OPTFLAGS) $(GCOV_FLAGS) $(PROF_FLAGS)
CFLAGS += $(SYMBOLS) $(SKIP_WARNING) $(C99)
LDFLAGS = $(OPTFLAGS) $(SYMBOLS) $(GCOV_FLAGS) $(PROF_FLAGS) $(LINK_FILES)
# Need XOPEN_SOURCE=600 to get strtoll()
CPPFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_XOPEN_SOURCE=600
# Add -Wconversion
# When debugging, try: valgrind --show-reachable=yes --leak-check=full ./brt-test
ifdef BRT_FANOUT
CPPFLAGS += -DBRT_FANOUT=$(BRT_FANOUT)
endif
BINS_RAW= \
brtdump \
tdb_logprint \
tdb-recover \
# Intentionally left blank
# BINS will be defined automatically.
ifeq ($(CIL),1)
CC=../../cil/cil-1.3.6/bin/cilly --merge --keepmerged
endif
BINS_O = $(patsubst %,%.$(OEXT),$(BINS_RAW))
# When debugging, try: valgrind --show-reachable=yes --leak-check=full ./brt-test
BINS= brtdump \
tdb_logprint \
# Intentionally left blank
.PHONY: build default bins libs
build default: bins libs tdb-recover tdb_logprint $(TEST_OFILES)
cd tests;$(MAKE) build
build default: bins libs $(TEST_NEWBRT)
$(MAYBEATSIGN)cd tests;$(MAKE) build
BRT_SOURCES = \
block_allocator \
......@@ -122,6 +40,7 @@ BRT_SOURCES = \
brt-serialize \
brt-verify \
brt \
brt-test-helpers \
cachetable \
fifo \
fingerprint \
......@@ -135,82 +54,52 @@ BRT_SOURCES = \
omt \
recover \
roll \
threadpool \
toku_assert \
ybt \
x1764 \
trace_mem \
threadpool \
# keep this line so I can ha vea \ on the previous line
ifeq ($(CIL),1)
OFILES = $(patsubst %,%.o,$(BRT_SOURCES))
else
OFILES = newbrt.o
endif
TEST_OFILES = brt-test-helpers.o
x1764 \
ybt \
# keep this line so I can have a \ on the previous line
HFILES = $(wildcard *.h)
TEST_NEWBRT = brt-test-helpers.$(OEXT)
BRT_C_FILES = $(patsubst %,%.c,$(BRT_SOURCES))
BRT_O_FILES = $(patsubst %,%.$(OEXT),$(BRT_SOURCES))
ifeq ($(CIL),1)
else
newbrt.o: $(BRT_C_FILES) $(HFILES)
$(CC) $(COMBINE_C) $(CFLAGS) $(CPPFLAGS) $(BRT_C_FILES) -o $@
endif
tdb_logprint.o: log-internal.h brttypes.h log.h kv-pair.h log_header.h
tdb_logprint: $(OFILES) $(CYG_ADD_LIBZ)
newbrt.o: $(BRT_C_FILES) $(DEPEND_COMPILE)
$(MAYBEATSIGN)$(CC) $(BRT_C_FILES) $(COMBINE_C) $(O_FROM_C_FLAGS)
recover.o: log_header.h log-internal.h log.h brttypes.h kv-pair.h memory.h key.h cachetable.h
tdb-recover: $(OFILES) $(CYG_ADD_LIBZ)
roll.o: log_header.h log-internal.h log.h brttypes.h kv-pair.h memory.h key.h cachetable.h omt.h bread.h
ifneq ($(CYGWIN),)
$(NEWBRT): $(BRT_O_FILES)
else ifeq ($(CC),icc)
$(NEWBRT): $(BRT_O_FILES)
else ifeq ($(COMBINE),0)
$(NEWBRT): $(BRT_O_FILES)
else
$(NEWBRT): newbrt.o
endif
log_code.o: log_header.h wbuf.h log-internal.h rbuf.h
log_code.$(OEXT): log_header.h wbuf.h log-internal.h rbuf.h
log_header.h: log_code.c
@echo generated log_code.c so log_header.c was also generated
log_code.c: logformat
./logformat
log_code.c: logformat$(BINSUF)
$(MAYBEATSIGN)./logformat
#Needs to be done manually since it does not include newbrt.
logformat$(BINSUF): logformat.c $(LIBPORTABILITY)
$(MAYBEATSIGN)$(CC) $< $(BIN_FROM_O_FLAGS_NOLIB) $(LIBPORTABILITY)
libs: $(OFILES) $(CYG_ADD_LIBZ)
libs: $(NEWBRT)
bins: $(BINS)
# Put the benchmarktest_256 first since it takes the longest (and we want to use parallelism in the make)
# Put check_benchmarktest_256 first because it is long-running (and therefore on the critical path, so get it started)
check: bins
cd tests;$(MAKE) check
check-fanout:
let BRT_FANOUT=4; \
while [ $$BRT_FANOUT -le 16 ] ;do \
$(MAKE) clean; $(MAKE) check BRT_FANOUT=$$BRT_FANOUT; \
let BRT_FANOUT=BRT_FANOUT+1; \
done
BRT_INTERNAL_H_INCLUDES = brt-internal.h cachetable.h fifo.h omt.h brt.h brt-search.h brttypes.h ybt.h log.h ../include/db.h kv-pair.h memory.h mempool.h leafentry.h log_header.h
brt-test-helpers.o: $(BRT_INTERNAL_H_INCLUDES) toku_assert.h
logformat: logformat.c
brt-serialize-test.o: $(BRT_INTERNAL_H_INCLUDES)
$(OFILES): $(BRT_INTERNAL_H_INCLUDES)
test_toku_malloc_plain_free: newbrt.o
cachetable-test.o: cachetable.h memory.h
cachetable-test: $(OFILES) $(CYG_ADD_LIBZ)
cachetable-test2.o: cachetable.h memory.h
cachetable-test2: $(OFILES) $(CYG_ADD_LIBZ)
test-assert: newbrt.o
brtdump: $(OFILES) $(CYG_ADD_LIBZ)
test_oexcl: test_oexcl.o newbrt.o
$(MAYBEATSIGN)cd tests;$(MAKE) check
%$(BINSUF): $(NEWBRT) $(LIBPORTABILITY)
checko2:
ifeq ($(OPTFLAGS),-O3)
......@@ -221,17 +110,13 @@ endif
clean: clean-local clean-tests
clean-tests:
cd tests;$(MAKE) clean
$(MAYBEATSIGN)cd tests;$(MAKE) clean
clean-local:
rm -rf $(BINS) *.o *.bb *.bbg *.da *.gcov *.gcno *.gcda
rm -rf test_oexcl.c.tmp *.brt
rm -rf *.obj *.pdb *.ilk *.exe
rm -rf log_code.c log_header.h logformat
$(MAYBEATSIGN)rm -rf $(NEWBRT)
$(MAYBEATSIGN)rm -rf test_oexcl.c.tmp *.brt
$(MAYBEATSIGN)rm -rf log_code.c log_header.h logformat
# After doing (cd ../src/tests;make test_log5.recover), run these. The files should have no differences.
testdump: brtdump
./brtdump ../src/tests/dir.test_log5.c.tdb.recover/foo.db > dump.r && ./brtdump ../src/tests/dir.test_log5.c.tdb/foo.db > dump.o && diff dump.o dump.r
testdump: brtdump$(BINSUF)
$(MAYBEATSIGN)./brtdump ../src/tests/dir.test_log5.c.tdb.recover/foo.db > dump.r && ./brtdump ../src/tests/dir.test_log5.c.tdb/foo.db > dump.$(OEXT) && diff dump.$(OEXT) dump.r
TAGS: ../*/*.c ../*/*.h
etags ../*/*.c ../*/*.h
ofiles: $(OFILES)
......@@ -43,13 +43,13 @@ static void maybe_preallocate_in_file (int fd, u_int64_t size) {
}
// This mutex protects pwrite from running in parallel, and also protects modifications to the block allocator.
static pthread_mutex_t pwrite_mutex = PTHREAD_MUTEX_INITIALIZER;
static toku_pthread_mutex_t pwrite_mutex = TOKU_PTHREAD_MUTEX_INITIALIZER;
static int pwrite_is_locked=0;
static inline void
lock_for_pwrite (void) {
// Locks the pwrite_mutex.
int r = pthread_mutex_lock(&pwrite_mutex);
int r = toku_pthread_mutex_lock(&pwrite_mutex);
assert(r==0);
pwrite_is_locked = 1;
}
......@@ -57,7 +57,7 @@ lock_for_pwrite (void) {
static inline void
unlock_for_pwrite (void) {
pwrite_is_locked = 0;
int r = pthread_mutex_unlock(&pwrite_mutex);
int r = toku_pthread_mutex_unlock(&pwrite_mutex);
assert(r==0);
}
......
......@@ -16,10 +16,10 @@ typedef struct ctpair_rwlock *CTPAIR_RWLOCK;
struct ctpair_rwlock {
int pinned; // the number of readers
int want_pin; // the number of blocked readers
pthread_cond_t wait_pin;
toku_pthread_cond_t wait_pin;
int writer; // the number of writers
int want_write; // the number of blocked writers
pthread_cond_t wait_write;
toku_pthread_cond_t wait_write;
};
// initialize a read write lock
......@@ -29,9 +29,9 @@ void
ctpair_rwlock_init(CTPAIR_RWLOCK rwlock) {
int r;
rwlock->pinned = rwlock->want_pin = 0;
r = pthread_cond_init(&rwlock->wait_pin, 0); assert(r == 0);
r = toku_pthread_cond_init(&rwlock->wait_pin, 0); assert(r == 0);
rwlock->writer = rwlock->want_write = 0;
r = pthread_cond_init(&rwlock->wait_write, 0); assert(r == 0);
r = toku_pthread_cond_init(&rwlock->wait_write, 0); assert(r == 0);
}
// destroy a read write lock
......@@ -42,18 +42,18 @@ ctpair_rwlock_destroy(CTPAIR_RWLOCK rwlock) {
int r;
assert(rwlock->pinned == 0 && rwlock->want_pin == 0);
assert(rwlock->writer == 0 && rwlock->want_write == 0);
r = pthread_cond_destroy(&rwlock->wait_pin); assert(r == 0);
r = pthread_cond_destroy(&rwlock->wait_write); assert(r == 0);
r = toku_pthread_cond_destroy(&rwlock->wait_pin); assert(r == 0);
r = toku_pthread_cond_destroy(&rwlock->wait_write); assert(r == 0);
}
// obtain a read lock
// expects: mutex is locked
static inline void ctpair_read_lock(CTPAIR_RWLOCK rwlock, pthread_mutex_t *mutex) {
static inline void ctpair_read_lock(CTPAIR_RWLOCK rwlock, toku_pthread_mutex_t *mutex) {
if (rwlock->writer || rwlock->want_write) {
rwlock->want_pin++;
while (rwlock->writer || rwlock->want_write) {
int r = pthread_cond_wait(&rwlock->wait_pin, mutex); assert(r == 0);
int r = toku_pthread_cond_wait(&rwlock->wait_pin, mutex); assert(r == 0);
}
rwlock->want_pin--;
}
......@@ -66,18 +66,18 @@ static inline void ctpair_read_lock(CTPAIR_RWLOCK rwlock, pthread_mutex_t *mutex
static inline void ctpair_read_unlock(CTPAIR_RWLOCK rwlock) {
rwlock->pinned--;
if (rwlock->pinned == 0 && rwlock->want_write) {
int r = pthread_cond_signal(&rwlock->wait_write); assert(r == 0);
int r = toku_pthread_cond_signal(&rwlock->wait_write); assert(r == 0);
}
}
// obtain a write lock
// expects: mutex is locked
static inline void ctpair_write_lock(CTPAIR_RWLOCK rwlock, pthread_mutex_t *mutex) {
static inline void ctpair_write_lock(CTPAIR_RWLOCK rwlock, toku_pthread_mutex_t *mutex) {
if (rwlock->pinned || rwlock->writer) {
rwlock->want_write++;
while (rwlock->pinned || rwlock->writer) {
int r = pthread_cond_wait(&rwlock->wait_write, mutex); assert(r == 0);
int r = toku_pthread_cond_wait(&rwlock->wait_write, mutex); assert(r == 0);
}
rwlock->want_write--;
}
......@@ -91,9 +91,9 @@ static inline void ctpair_write_unlock(CTPAIR_RWLOCK rwlock) {
rwlock->writer--;
if (rwlock->writer == 0) {
if (rwlock->want_write) {
int r = pthread_cond_signal(&rwlock->wait_write); assert(r == 0);
int r = toku_pthread_cond_signal(&rwlock->wait_write); assert(r == 0);
} else if (rwlock->want_pin) {
int r = pthread_cond_broadcast(&rwlock->wait_pin); assert(r == 0);
int r = toku_pthread_cond_broadcast(&rwlock->wait_pin); assert(r == 0);
}
}
}
......
......@@ -6,9 +6,9 @@
typedef struct writequeue *WRITEQUEUE;
struct writequeue {
PAIR head, tail; // head and tail of the linked list of pair's
pthread_cond_t wait_read; // wait for read
toku_pthread_cond_t wait_read; // wait for read
int want_read; // number of threads waiting to read
pthread_cond_t wait_write; // wait for write
toku_pthread_cond_t wait_write; // wait for write
int want_write; // number of threads waiting to write
int ninq; // number of pairs in the queue
char closed; // kicks waiting threads off of the write queue
......@@ -21,9 +21,9 @@ struct writequeue {
static void writequeue_init(WRITEQUEUE wq) {
wq->head = wq->tail = 0;
int r;
r = pthread_cond_init(&wq->wait_read, 0); assert(r == 0);
r = toku_pthread_cond_init(&wq->wait_read, 0); assert(r == 0);
wq->want_read = 0;
r = pthread_cond_init(&wq->wait_write, 0); assert(r == 0);
r = toku_pthread_cond_init(&wq->wait_write, 0); assert(r == 0);
wq->want_write = 0;
wq->ninq = 0;
wq->closed = 0;
......@@ -35,8 +35,8 @@ static void writequeue_init(WRITEQUEUE wq) {
static void writequeue_destroy(WRITEQUEUE wq) {
assert(wq->head == 0 && wq->tail == 0);
int r;
r = pthread_cond_destroy(&wq->wait_read); assert(r == 0);
r = pthread_cond_destroy(&wq->wait_write); assert(r == 0);
r = toku_pthread_cond_destroy(&wq->wait_read); assert(r == 0);
r = toku_pthread_cond_destroy(&wq->wait_write); assert(r == 0);
}
// close the writequeue
......@@ -45,8 +45,8 @@ static void writequeue_destroy(WRITEQUEUE wq) {
static void writequeue_set_closed(WRITEQUEUE wq) {
wq->closed = 1;
int r;
r = pthread_cond_broadcast(&wq->wait_read); assert(r == 0);
r = pthread_cond_broadcast(&wq->wait_write); assert(r == 0);
r = toku_pthread_cond_broadcast(&wq->wait_read); assert(r == 0);
r = toku_pthread_cond_broadcast(&wq->wait_write); assert(r == 0);
}
// determine whether or not the write queue is empty
......@@ -70,7 +70,7 @@ static void writequeue_enq(WRITEQUEUE wq, PAIR pair) {
wq->tail = pair;
wq->ninq++;
if (wq->want_read) {
int r = pthread_cond_signal(&wq->wait_read); assert(r == 0);
int r = toku_pthread_cond_signal(&wq->wait_read); assert(r == 0);
}
}
......@@ -80,12 +80,12 @@ static void writequeue_enq(WRITEQUEUE wq, PAIR pair) {
// write queue and return it
// returns: 0 if success, otherwise an error
static int writequeue_deq(WRITEQUEUE wq, pthread_mutex_t *mutex, PAIR *pairptr) {
static int writequeue_deq(WRITEQUEUE wq, toku_pthread_mutex_t *mutex, PAIR *pairptr) {
while (writequeue_empty(wq)) {
if (wq->closed)
return EINVAL;
wq->want_read++;
int r = pthread_cond_wait(&wq->wait_read, mutex); assert(r == 0);
int r = toku_pthread_cond_wait(&wq->wait_read, mutex); assert(r == 0);
wq->want_read--;
}
PAIR pair = wq->head;
......@@ -101,9 +101,9 @@ static int writequeue_deq(WRITEQUEUE wq, pthread_mutex_t *mutex, PAIR *pairptr)
// suspend the writer thread
// expects: the mutex is locked
static void writequeue_wait_write(WRITEQUEUE wq, pthread_mutex_t *mutex) {
static void writequeue_wait_write(WRITEQUEUE wq, toku_pthread_mutex_t *mutex) {
wq->want_write++;
int r = pthread_cond_wait(&wq->wait_write, mutex); assert(r == 0);
int r = toku_pthread_cond_wait(&wq->wait_write, mutex); assert(r == 0);
wq->want_write--;
}
......@@ -112,7 +112,7 @@ static void writequeue_wait_write(WRITEQUEUE wq, pthread_mutex_t *mutex) {
static void writequeue_wakeup_write(WRITEQUEUE wq) {
if (wq->want_write) {
int r = pthread_cond_broadcast(&wq->wait_write); assert(r == 0);
int r = toku_pthread_cond_broadcast(&wq->wait_write); assert(r == 0);
}
}
......@@ -74,7 +74,7 @@ struct cachetable {
long size_writing; // the sum of the sizes of the pairs being written
LSN lsn_of_checkpoint; // the most recent checkpoint in the log.
TOKULOGGER logger;
pthread_mutex_t mutex; // coarse lock that protects the cachetable, the cachefiles, and the pair's
toku_pthread_mutex_t mutex; // coarse lock that protects the cachetable, the cachefiles, and the pair's
struct writequeue wq; // write queue for the writer threads
THREADPOOL threadpool; // pool of writer threads
char checkpointing; // checkpoint in progress
......@@ -84,7 +84,7 @@ struct cachetable {
static inline void cachetable_lock(CACHETABLE ct __attribute__((unused))) {
#if DO_CACHETABLE_LOCK
int r = pthread_mutex_lock(&ct->mutex); assert(r == 0);
int r = toku_pthread_mutex_lock(&ct->mutex); assert(r == 0);
#endif
}
......@@ -92,7 +92,7 @@ static inline void cachetable_lock(CACHETABLE ct __attribute__((unused))) {
static inline void cachetable_unlock(CACHETABLE ct __attribute__((unused))) {
#if DO_CACHETABLE_LOCK
int r = pthread_mutex_unlock(&ct->mutex); assert(r == 0);
int r = toku_pthread_mutex_unlock(&ct->mutex); assert(r == 0);
#endif
}
......@@ -105,11 +105,6 @@ static inline void cachetable_wait_write(CACHETABLE ct) {
}
}
struct fileid {
dev_t st_dev; /* device and inode are enough to uniquely identify a file in unix. */
ino_t st_ino;
};
struct cachefile {
CACHEFILE next;
u_int64_t refcount; /* CACHEFILEs are shared. Use a refcount to decide when to really close it.
......@@ -156,7 +151,7 @@ int toku_create_cachetable(CACHETABLE *result, long size_limit, LSN initial_lsn,
t->checkpointing = 0;
int r;
writequeue_init(&t->wq);
r = pthread_mutex_init(&t->mutex, 0); assert(r == 0);
r = toku_pthread_mutex_init(&t->mutex, 0); assert(r == 0);
// set the max number of writeback threads to min(MAX_WRITER_THREADS,nprocs_online)
int nprocs = sysconf(_SC_NPROCESSORS_ONLN);
......@@ -969,7 +964,7 @@ int toku_cachetable_close (CACHETABLE *tp) {
cachetable_unlock(t);
threadpool_destroy(&t->threadpool);
writequeue_destroy(&t->wq);
r = pthread_mutex_destroy(&t->mutex); assert(r == 0);
r = toku_pthread_mutex_destroy(&t->mutex); assert(r == 0);
toku_free(t->table);
toku_free(t);
*tp = 0;
......@@ -1118,7 +1113,7 @@ FILENUM toku_cachefile_filenum (CACHEFILE cf) {
// The writer thread waits for work in the write queue and writes the pair
static void *cachetable_writer(void *arg) {
// printf("%lu:%s:start %p\n", pthread_self(), __FUNCTION__, arg);
// printf("%lu:%s:start %p\n", toku_pthread_self(), __FUNCTION__, arg);
CACHETABLE ct = arg;
int r;
cachetable_lock(ct);
......@@ -1132,7 +1127,7 @@ static void *cachetable_writer(void *arg) {
cachetable_write_pair(ct, p);
}
cachetable_unlock(ct);
// printf("%lu:%s:exit %p\n", pthread_self(), __FUNCTION__, arg);
// printf("%lu:%s:exit %p\n", toku_pthread_self(), __FUNCTION__, arg);
return arg;
}
......
......@@ -12,7 +12,7 @@
#if !defined(TOKU_WINDOWS)
#include <dirent.h>
#include <inttypes.h>
#include <pthread.h>
#include <toku_pthread.h>
#include <sys/file.h>
#include <sys/resource.h>
#include <sys/time.h>
......
This diff is collapsed.
......@@ -156,5 +156,57 @@ void* le_any_val (LEAFENTRY le);
u_int32_t le_any_vallen (LEAFENTRY le);
u_int64_t le_any_xid (LEAFENTRY le);
void *latest_key_le_committed(u_int32_t klen, void *kval, u_int32_t vallen, void *val);
void *latest_key_le_both(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval, u_int32_t plen, void *pval);
void *latest_key_le_provdel(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval);
void *latest_key_le_provpair(TXNID xid, u_int32_t klen, void *kval, u_int32_t plen, void *pval);
u_int32_t latest_keylen_le_committed(u_int32_t klen, void *kval, u_int32_t vallen, void *val);
u_int32_t latest_keylen_le_both(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval, u_int32_t plen, void *pval);
u_int32_t latest_keylen_le_provdel(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval);
u_int32_t latest_keylen_le_provpair(TXNID xid, u_int32_t klen, void *kval, u_int32_t plen, void *pval);
void *latest_val_le_committed(u_int32_t klen, void *kval, u_int32_t vallen, void *val);
void *latest_val_le_both(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval, u_int32_t plen, void *pval);
void *latest_val_le_provdel(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval);
void *latest_val_le_provpair(TXNID xid, u_int32_t klen, void *kval, u_int32_t plen, void *pval);
u_int32_t latest_vallen_le_committed(u_int32_t klen, void *kval, u_int32_t vallen, void *val);
u_int32_t latest_vallen_le_both(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval, u_int32_t plen, void *pval);
u_int32_t latest_vallen_le_provdel(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval);
u_int32_t latest_vallen_le_provpair(TXNID xid, u_int32_t klen, void *kval, u_int32_t plen, void *pval);
u_int64_t latest_xid_le_committed(u_int32_t klen, void *kval, u_int32_t vallen, void *val);
u_int64_t latest_xid_le_both(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval, u_int32_t plen, void *pval);
u_int64_t latest_xid_le_provdel(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval);
u_int64_t latest_xid_le_provpair(TXNID xid, u_int32_t klen, void *kval, u_int32_t plen, void *pval);
//
void *any_key_le_committed(u_int32_t klen, void *kval, u_int32_t vallen, void *val);
void *any_key_le_both(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval, u_int32_t plen, void *pval);
void *any_key_le_provdel(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval);
void *any_key_le_provpair(TXNID xid, u_int32_t klen, void *kval, u_int32_t plen, void *pval);
u_int32_t any_keylen_le_committed(u_int32_t klen, void *kval, u_int32_t vallen, void *val);
u_int32_t any_keylen_le_both(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval, u_int32_t plen, void *pval);
u_int32_t any_keylen_le_provdel(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval);
u_int32_t any_keylen_le_provpair(TXNID xid, u_int32_t klen, void *kval, u_int32_t plen, void *pval);
void *any_val_le_committed(u_int32_t klen, void *kval, u_int32_t vallen, void *val);
void *any_val_le_both(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval, u_int32_t plen, void *pval);
void *any_val_le_provdel(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval);
void *any_val_le_provpair(TXNID xid, u_int32_t klen, void *kval, u_int32_t plen, void *pval);
u_int32_t any_vallen_le_committed(u_int32_t klen, void *kval, u_int32_t vallen, void *val);
u_int32_t any_vallen_le_both(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval, u_int32_t plen, void *pval);
u_int32_t any_vallen_le_provdel(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval);
u_int32_t any_vallen_le_provpair(TXNID xid, u_int32_t klen, void *kval, u_int32_t plen, void *pval);
u_int64_t any_xid_le_committed(u_int32_t klen, void *kval, u_int32_t vallen, void *val);
u_int64_t any_xid_le_both(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval, u_int32_t plen, void *pval);
u_int64_t any_xid_le_provdel(TXNID xid, u_int32_t klen, void *kval, u_int32_t clen, void *cval);
u_int64_t any_xid_le_provpair(TXNID xid, u_int32_t klen, void *kval, u_int32_t plen, void *pval);
#endif
......@@ -10,7 +10,7 @@
#include "memarena.h"
#include <stdio.h>
#if !defined(TOKU_WINDOWS)
#include <pthread.h>
#include <toku_pthread.h>
#endif
#include <sys/types.h>
#include <string.h>
......@@ -24,16 +24,16 @@
#define LOGGER_BUF_SIZE (1<<24)
struct mylock {
pthread_mutex_t lock;
toku_pthread_mutex_t lock;
int is_locked;
};
static inline int ml_init(struct mylock *l) {
l->is_locked=0;
return pthread_mutex_init(&l->lock, 0);
return toku_pthread_mutex_init(&l->lock, 0);
}
static inline int ml_lock(struct mylock *l) {
int r = pthread_mutex_lock(&l->lock);
int r = toku_pthread_mutex_lock(&l->lock);
assert(l->is_locked==0);
l->is_locked=1;
return r;
......@@ -41,11 +41,11 @@ static inline int ml_lock(struct mylock *l) {
static inline int ml_unlock(struct mylock *l) {
assert(l->is_locked==1);
l->is_locked=0;
return pthread_mutex_unlock(&l->lock);
return toku_pthread_mutex_unlock(&l->lock);
}
static inline int ml_destroy(struct mylock *l) {
assert(l->is_locked==0);
return pthread_mutex_destroy(&l->lock);
return toku_pthread_mutex_destroy(&l->lock);
}
......
#ifndef PORTABILITY_H
#define PORTABILITY_H
// Portability layer
#if defined(__INTEL_COMPILER)
#if !defined(__ICL) && !defined(__ICC)
#error Which intel compiler?
#endif
#if defined(__ICL) && defined(__ICC)
#error Cannot distinguish between windows and linux intel compiler
#endif
#if defined(__ICL)
//Windows Intel Compiler
#define TOKU_WINDOWS
//Define standard integer types.
typedef __int8 int8_t;
typedef unsigned __int8 u_int8_t;
typedef __int16 int16_t;
typedef unsigned __int16 u_int16_t;
typedef __int32 int32_t;
typedef unsigned __int32 u_int32_t;
typedef __int64 int64_t;
typedef unsigned __int64 u_int64_t;
//Define printf types.
#define PRId64 "I64d"
#define PRIu64 "I64u"
#define PRId32 "d"
#define PRIu32 "u"
//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
#define srandom srand
#define random rand
#define FAKE_WINDOWS_STUBS 0 // Disable these fakes.
#if FAKE_WINDOWS_STUBS == 1
//#define chmod(a,b) (void)0 /* Remove temporarily till compatibility layer exists */
//Define chmod
typedef int mode_t;
static inline
int
chmod(const char *path, mode_t mode) {
//TODO: Write API to support what we really need.
//Linux version supports WRITE/EXECUTE/READ bits separately for user/group/world
//windows _chmod supports WRITE/READ bits separately for ?? one type (user? world?)
//See _chmod in sys/stat.h
//Supports setting read/write mode (not separately for user/group/world)
return 0;
}
#define S_IRUSR 0
#define S_IRGRP 0
#define S_IROTH 0
//Fake typedefs to skip warnings.
typedef size_t ssize_t;
typedef int pthread_cond_t;
typedef void* pthread_mutex_t;
struct timeval {
int tv_sec;
int tv_usec;
};
#endif //FAKE_WINDOWS_STUBS
#endif //Windows Intel Compiler
// Intel compiler.
// Define ntohl using bswap.
// Define __attribute__ to be null
#include <sys/types.h>
static inline
u_int32_t
ntohl(u_int32_t x) {
return _bswap(x);
}
static inline
u_int32_t
htonl(u_int32_t x) {
return _bswap(x);
}
#define __attribute__(x)
#elif defined __GNUC__
// Gcc:
// Define ntohl using arpa/inet.h
#include <arpa/inet.h>
#else
#error Not ICC and not GNUC. What compiler?
#endif
// This hack is to avoid initializing variables that gcc can figure out are not used in an undefined way.
// But some compiler cannot figure it out, so we initialize the value to zero.
#if defined __INTEL_COMPILER
#define MAYBE_INIT(n) = n
#elif defined __GNUC__
#define MAYBE_INIT(n)
#endif
#endif
......@@ -8,7 +8,7 @@
*****************************************
*
* TokuDB employs readers/writers locks for the ephemeral locks (e.g.,
* on BRT nodes) Why not just use the pthread_rwlock API?
* on BRT nodes) Why not just use the toku_pthread_rwlock API?
*
* 1) we need multiprocess rwlocks (not just multithreaded)
*
......
.DEFAULT_GOAL=build
TOKUROOT=../../
INCLUDEDIRS=-I. -I..
include $(TOKUROOT)include/Makefile.include
CPPFLAGS += -D_GNU_SOURCE
ifeq ($(CC),icc)
SKIP_WARNING += $(ICC_NOWARN)1418 #Non static functions do not need prototypes.
endif
# On cygwin do:
# make CYGWIN=cygwin check
......@@ -6,108 +16,10 @@
# For very verbose output do
# make VERBOSE=2
# GCOV_FLAGS = -fprofile-arcs -ftest-coverage
# PROF_FLAGS = -pg
OPTFLAGS = -O3
ifeq ($(VERBOSE),2)
VERBVERBOSE=-v
else
ifeq ($(VERBOSE),1)
VERBVERBOSE=-q
else
VERBVERBOSE=-q
endif
endif
#CFLAG default options
WERROR = -Werror
WALL = -Wall -Wextra -Wcast-align -Wbad-function-cast -Wmissing-noreturn
FORMAT = -Wmissing-format-attribute
VISIBILITY= -fvisibility=hidden
FPICFLAGS = -fPIC
SHADOW = -Wshadow
SYMBOLS = -g3 -ggdb3
PORTABILITY=
SKIP_WARNING=
COMBINE_C = -combine -c
LINK_FILES= -lz -lpthread
C99 = -std=c99
#Tools
VGRIND = valgrind --quiet --error-exitcode=1 --leak-check=yes --suppressions=../valgrind.suppressions
ifeq ($(CC),icc)
#icc only:
OPTFLAGS = -O3 -ip -ipo2
COMBINE_C = -ipo-c
FORMAT= #No argument for extra format warnings.
WALL = -Wall -Wcheck # '-Wextra' becomes '-Wcheck' in icc
SYMBOLS= -g -debug all -inline-debug-info
PORTABILITY=-diag-enable port-win
ifneq ($(CYGWIN),)
#Cygwin
ICC_NOWARN=-Qdiag-disable:
else
#Linux
ICC_NOWARN=-diag-disable #Need the space
endif
SKIP_WARNING += $(ICC_NOWARN)177 # Don't complain about static variables that are not used.
#SKIP_WARNING += $(ICC_NOWARN)188 # Don't complain about enumerated type mixed with another type.
SKIP_WARNING += $(ICC_NOWARN)589 # Don't complain about goto into a block that skips initializing variables. GCC catches the actual uninitialized variables.
SKIP_WARNING += $(ICC_NOWARN)869 # Don't complain about unused variables (since we defined __attribute__ to be nothing.)
SKIP_WARNING += $(ICC_NOWARN)981 # Don't complain about "operands are evaluated in unspecified order". This seems to be generated whenever more than one argument to a function or operand is computed by function call.
SKIP_WARNING += $(ICC_NOWARN)1324 # Don't complain about rdtsc clobbering its registers more than once.
endif
ifneq ($(CYGWIN),)
#Cygwin (Windows) Must override some settings
CYG_ADD_LIBZ=/usr/lib/libz.a
VGRIND =#No Valgrind in cygwin
FPICFLAGS=#FPIC is default and not allowed as an option.
VISIBILITY=#Not supported
SHADOW=#Not supported
ifeq ($(CC),icc)
#Cygwin icc only
C99 = -Qstd=c99
OPTFLAGS = -Ox -Qip -Qipo2
COMBINE_C = -Qipo-c
WERROR = -WX # Windows icc version of -Werror
SYMBOLS= -Zi -debug:all -Qinline-debug-info
PORTABILITY=
LINK_FILES=#Not supported
SKIP_WARNING += $(ICC_NOWARN)1786 # Don't complain about 'read/write/other standards' being deprecated
else
#Cygwin gcc only
FORMAT = -Wno-format
endif
endif
CFLAGS = $(WALL) $(WERROR) $(FORMAT) $(VISIBILITY) $(FPICFLAGS) $(SHADOW)
CFLAGS += $(OPTFLAGS) $(GCOV_FLAGS) $(PROF_FLAGS)
CFLAGS += $(SYMBOLS) $(SKIP_WARNING) $(C99)
LDFLAGS = $(OPTFLAGS) $(SYMBOLS) $(GCOV_FLAGS) $(PROF_FLAGS) $(LINK_FILES)
# Need XOPEN_SOURCE=600 to get strtoll()
CPPFLAGS += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_XOPEN_SOURCE=600
CPPFLAGS += -D_GNU_SOURCE -I..
# Add -Wconversion
HERE=newbrt/tests
ifeq ($(SUMMARIZE),1)
SUMMARIZE_CMD = ;if test $$? = 0; then printf "%-60sPASS\n" $(HERE)/$@; else printf "%-60sFAIL\n" $(HERE)/$@ ; test 0 = 1; fi
else
SUMMARIZE_CMD =
endif
# Put these one-per-line so that if we insert a new one the svn diff can understand it better.
# Also keep them sorted.
REGRESSION_TESTS = \
REGRESSION_TESTS_RAW = \
block_allocator_test \
bread-test \
brt-serialize-test \
......@@ -121,7 +33,6 @@ REGRESSION_TESTS = \
brt-test3 \
brt-test4 \
brt-test5 \
test-dump-brt \
cachetable-rwlock-test \
cachetable-writequeue-test \
threadpool-test \
......@@ -136,8 +47,6 @@ REGRESSION_TESTS = \
cachetable-count-pinned-test \
cachetable-debug-test \
cachetable-debug-test \
cachetable-unpin-and-remove-test \
dup-delete-all \
fifo-test \
list-test \
keyrange \
......@@ -167,89 +76,55 @@ REGRESSION_TESTS = \
# This line intentially kept commented so I can have a \ on the end of the previous line
# Add in the binaries that must be run in various ways.
BINS = $(REGRESSION_TESTS) \
BINS_RAW = $(REGRESSION_TESTS_RAW) \
benchmark-test \
cachetable-scan \
# This line intentially kept commented so I can have a \ on the end of the previous line
# BINS will be defined by adding .exe if appropriate.
CHECKS = \
benchmarktest_256 \
test-assertA test-assertB \
$(REGRESSION_TESTS) \
benchmarktest_256 \
test-assertA \
test-assertB \
$(REGRESSION_TESTS) \
# This line intentially kept commented so I can have a \ on the previous line
ifeq ($(CIL),1)
CC=../../../cil/cil-1.3.6/bin/cilly --merge --keepmerged
endif
#CHECKS will be defined automatically.
build: $(BINS)
check: $(patsubst %,check_%,$(CHECKS))
check_fail:
test 0 = 1 $(SUMMARIZE_CMD)
$(MAYBEATSIGN)test 0 = 1 $(SUMMARIZE_CMD)
check_ok:
test 0 = 0 $(SUMMARIZE_CMD)
$(MAYBEATSIGN)test 0 = 0 $(SUMMARIZE_CMD)
check_benchmarktest_256: benchmark-test
$(VGRIND) ./benchmark-test $(VERBVERBOSE) --valsize 256 --verify 1 $(SUMMARIZE_CMD)
check_benchmarktest_256: benchmark-test$(BINSUF)
$(MAYBEATSIGN)$(VGRIND) ./$< $(VERBVERBOSE) --valsize 256 --verify 1 $(SUMMARIZE_CMD)
check_test-assertA: test-assert
check_test-assertA: test-assert$(BINSUF)
@# no arguments, should err
$(VGRIND) ./test-assert > /dev/null 2>&1 ; test $$? = 1 $(SUMMARIZE_CMD)
check_test-assertB: test-assert
$(MAYBEATSIGN)$(VGRIND) ./$< > /dev/null 2>&1 ; test $$? = 1 $(SUMMARIZE_CMD)
check_test-assertB: test-assert$(BINSUF)
@# one argument, not "ok" should err
@rm -f test-assert.out
($(VGRIND) ./test-assert notok) > test-assert.out 2>&1 ; test $$? = 1 && fgrep failed test-assert.out > /dev/null $(SUMMARIZE_CMD)
check_test-assertC: tst-assert
$(MAYBEATSIGN)($(VGRIND) ./$< notok) > test-assert.out 2>&1 ; test $$? = 1 && fgrep failed test-assert.out > /dev/null $(SUMMARIZE_CMD)
check_test-assertC: test-assert$(BINSUF)
check_test-assert$(BINSUF): test-assert$(BINSUF)
@# one argument, "ok" should not error
$(MAYBEATSIGN)$(VGRIND) ./$< ok $(SUMMARIZE_CMD)
check_%$(BINSUF): %$(BINSUF)
$(MAYBEATSIGN)$(VGRIND) ./$< $(VERBVERBOSE) $(SUMMARIZE_CMD)
check_test-assert: test-assert
@# one argument, "ok" should not error
$(DVGRIND) ./test-assert ok $(SUMMARIZE_CMD)
check_%: %
$(VGRIND) ./$< $(VERBVERBOSE) $(SUMMARIZE_CMD)
benchmark-test.o: ../brt.h ../brt-search.h ../../include/db.h
ifeq ($(CIL),1)
BRT_SOURCES = \
block_allocator \
bread \
brt-serialize \
brt-verify \
brt \
cachetable \
fifo \
fingerprint \
key \
leafentry \
log \
log_code \
memory \
memarena \
mempool \
omt \
recover \
roll \
toku_assert \
ybt \
x1764 \
trace_mem \
threadpool \
# keep this line so I can ha vea \ on the previous line
$(BINS): $(patsubst %,../%.o,$(BRT_SOURCES)) $(CYG_ADD_LIBZ)
else
$(BINS): ../newbrt.o $(CYG_ADD_LIBZ)
endif
benchmark-test.$(OEXT): ../brt.h ../brt-search.h ../../include/db.h
test-inc-split test-del-inorder: ../brt-test-helpers.o
LINK_FILES += ../newbrt.$(AEXT)
clean:
rm -rf $(BINS) *.o *.bb *.bbg *.da *.gcov *.gcno *.gcda
rm -rf test_oexcl.c.tmp *.brt *.dir *.tdb *.dat *.out
rm -rf *.exe *.pdb *.ilk *.obj
rm -f cachetable-fd-test.ctest2.data
$(MAYBEATSIGN)rm -rf *.dir
$(MAYBEATSIGN)rm -f cachetable-fd-test.ctest2.data test_oexcl.c.tmp
$(MAYBEATSIGN)rm -f *.brt *.tdb *.dat *.data *.out
foo: ../cachetable.$(OEXT) ../fifo.$(OEXT) ../fingerprint.$(OEXT) ../key.$(OEXT) ../memory.$(OEXT) ../memarena.$(OEXT) ../mempool.$(OEXT) ../omt.$(OEXT) ../toku_assert.$(OEXT) ../ybt.$(OEXT) ../x1764.$(OEXT) ../trace_mem.$(OEXT) ../threadpool.$(OEXT)
foo: ../cachetable.o ../fifo.o ../fingerprint.o ../key.o ../memory.o ../memarena.o ../mempool.o ../omt.o ../toku_assert.o ../ybt.o ../x1764.o ../trace_mem.o ../threadpool.o
#include "../portability.h"
#include "portability.h"
#include <assert.h>
#include <fcntl.h>
......
......@@ -8,22 +8,22 @@
// global data, especially between the test thread and the cachetable
// writeback threads
pthread_mutex_t test_mutex;
toku_pthread_mutex_t test_mutex;
static inline void test_mutex_init() {
int r = pthread_mutex_init(&test_mutex, 0); assert(r == 0);
int r = toku_pthread_mutex_init(&test_mutex, 0); assert(r == 0);
}
static inline void test_mutex_destroy() {
int r = pthread_mutex_destroy(&test_mutex); assert(r == 0);
int r = toku_pthread_mutex_destroy(&test_mutex); assert(r == 0);
}
static inline void test_mutex_lock() {
int r = pthread_mutex_lock(&test_mutex); assert(r == 0);
int r = toku_pthread_mutex_lock(&test_mutex); assert(r == 0);
}
static inline void test_mutex_unlock() {
int r = pthread_mutex_unlock(&test_mutex); assert(r == 0);
int r = toku_pthread_mutex_unlock(&test_mutex); assert(r == 0);
}
enum { KEYLIMIT = 4, TRIALLIMIT=256000 };
......@@ -100,7 +100,7 @@ static void test_rename (void) {
test_mutex_lock();
while (n_keys >= KEYLIMIT) {
test_mutex_unlock();
pthread_yield();
toku_pthread_yield();
test_mutex_lock();
}
assert(n_keys<KEYLIMIT);
......
......@@ -53,20 +53,20 @@ test_simple_write_lock (void) {
struct rw_event {
int e;
struct ctpair_rwlock the_rwlock;
pthread_mutex_t mutex;
toku_pthread_mutex_t mutex;
};
static void
rw_event_init (struct rw_event *rwe) {
rwe->e = 0;
ctpair_rwlock_init(&rwe->the_rwlock);
int r = pthread_mutex_init(&rwe->mutex, 0); assert(r == 0);
int r = toku_pthread_mutex_init(&rwe->mutex, 0); assert(r == 0);
}
static void
rw_event_destroy (struct rw_event *rwe) {
ctpair_rwlock_destroy(&rwe->the_rwlock);
int r = pthread_mutex_destroy(&rwe->mutex); assert(r == 0);
int r = toku_pthread_mutex_destroy(&rwe->mutex); assert(r == 0);
}
static void *
......@@ -74,15 +74,15 @@ test_writer_priority_thread (void *arg) {
struct rw_event *rwe = arg;
int r;
r = pthread_mutex_lock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&rwe->mutex); assert(r == 0);
ctpair_write_lock(&rwe->the_rwlock, &rwe->mutex);
rwe->e++; assert(rwe->e == 3);
r = pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
sleep(1);
r = pthread_mutex_lock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&rwe->mutex); assert(r == 0);
rwe->e++; assert(rwe->e == 4);
ctpair_write_unlock(&rwe->the_rwlock);
r = pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
return arg;
}
......@@ -95,35 +95,35 @@ test_writer_priority (void) {
int r;
rw_event_init(rwe);
r = pthread_mutex_lock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&rwe->mutex); assert(r == 0);
ctpair_read_lock(&rwe->the_rwlock, &rwe->mutex);
sleep(1);
rwe->e++; assert(rwe->e == 1);
r = pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
pthread_t tid;
r = pthread_create(&tid, 0, test_writer_priority_thread, rwe);
toku_pthread_t tid;
r = toku_pthread_create(&tid, 0, test_writer_priority_thread, rwe);
sleep(1);
r = pthread_mutex_lock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&rwe->mutex); assert(r == 0);
rwe->e++; assert(rwe->e == 2);
r = pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
sleep(1);
r = pthread_mutex_lock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&rwe->mutex); assert(r == 0);
ctpair_read_unlock(&rwe->the_rwlock);
r = pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
sleep(1);
r = pthread_mutex_lock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&rwe->mutex); assert(r == 0);
ctpair_read_lock(&rwe->the_rwlock, &rwe->mutex);
rwe->e++; assert(rwe->e == 5);
r = pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
sleep(1);
r = pthread_mutex_lock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&rwe->mutex); assert(r == 0);
ctpair_read_unlock(&rwe->the_rwlock);
r = pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
void *ret;
r = pthread_join(tid, &ret); assert(r == 0);
r = toku_pthread_join(tid, &ret); assert(r == 0);
rw_event_destroy(rwe);
}
......@@ -135,12 +135,12 @@ test_single_writer_thread (void *arg) {
struct rw_event *rwe = arg;
int r;
r = pthread_mutex_lock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&rwe->mutex); assert(r == 0);
ctpair_write_lock(&rwe->the_rwlock, &rwe->mutex);
rwe->e++; assert(rwe->e == 3);
assert(ctpair_writers(&rwe->the_rwlock) == 1);
ctpair_write_unlock(&rwe->the_rwlock);
r = pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
return arg;
}
......@@ -152,25 +152,25 @@ test_single_writer (void) {
rw_event_init(rwe);
assert(ctpair_writers(&rwe->the_rwlock) == 0);
r = pthread_mutex_lock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&rwe->mutex); assert(r == 0);
ctpair_write_lock(&rwe->the_rwlock, &rwe->mutex);
assert(ctpair_writers(&rwe->the_rwlock) == 1);
sleep(1);
rwe->e++; assert(rwe->e == 1);
r = pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
pthread_t tid;
r = pthread_create(&tid, 0, test_single_writer_thread, rwe);
toku_pthread_t tid;
r = toku_pthread_create(&tid, 0, test_single_writer_thread, rwe);
sleep(1);
r = pthread_mutex_lock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&rwe->mutex); assert(r == 0);
rwe->e++; assert(rwe->e == 2);
assert(ctpair_writers(&rwe->the_rwlock) == 1);
assert(ctpair_users(&rwe->the_rwlock) == 2);
ctpair_write_unlock(&rwe->the_rwlock);
r = pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
r = toku_pthread_mutex_unlock(&rwe->mutex); assert(r == 0);
void *ret;
r = pthread_join(tid, &ret); assert(r == 0);
r = toku_pthread_join(tid, &ret); assert(r == 0);
assert(ctpair_writers(&rwe->the_rwlock) == 0);
rw_event_destroy(rwe);
......
......@@ -9,22 +9,22 @@
// global data, especially between the test thread and the cachetable
// writeback threads
pthread_mutex_t test_mutex;
toku_pthread_mutex_t test_mutex;
static inline void test_mutex_init() {
int r = pthread_mutex_init(&test_mutex, 0); assert(r == 0);
int r = toku_pthread_mutex_init(&test_mutex, 0); assert(r == 0);
}
static inline void test_mutex_destroy() {
int r = pthread_mutex_destroy(&test_mutex); assert(r == 0);
int r = toku_pthread_mutex_destroy(&test_mutex); assert(r == 0);
}
static inline void test_mutex_lock() {
int r = pthread_mutex_lock(&test_mutex); assert(r == 0);
int r = toku_pthread_mutex_lock(&test_mutex); assert(r == 0);
}
static inline void test_mutex_unlock() {
int r = pthread_mutex_unlock(&test_mutex); assert(r == 0);
int r = toku_pthread_mutex_unlock(&test_mutex); assert(r == 0);
}
#endif
......@@ -198,14 +198,14 @@ static void test0 (void) {
expect1(2); /* 2 is the oldest unpinned item. */
r=toku_cachetable_put(f, make_blocknum(6), h6, make_item(6), test_object_size, flush, fetch, t3); /* 6P 5U 4P 3U 1P */
assert(r==0);
while (expect_n_flushes != 0) pthread_yield();
while (expect_n_flushes != 0) toku_pthread_yield();
assert(expect_n_flushes==0);
expect1(3);
r=toku_cachetable_put(f, make_blocknum(7), h7, make_item(7), test_object_size, flush, fetch, t3);
assert(r==0);
while (expect_n_flushes != 0) pthread_yield();
while (expect_n_flushes != 0) toku_pthread_yield();
assert(expect_n_flushes==0);
r=toku_cachetable_unpin(f, make_blocknum(7), h7, CACHETABLE_DIRTY, test_object_size); /* 7U 6P 5U 4P 1P */
assert(r==0);
......@@ -231,7 +231,7 @@ static void test0 (void) {
assert(did_fetch.b==2); /* Expect that 2 is fetched in. */
assert(((struct item *)item_v)->key.b==2);
assert(strcmp(((struct item *)item_v)->something,"something")==0);
while (expect_n_flushes != 0) pthread_yield();
while (expect_n_flushes != 0) toku_pthread_yield();
assert(expect_n_flushes==0);
}
......@@ -624,7 +624,7 @@ static void test_size_flush() {
int n_entries, hash_size; long size_current, size_limit;
toku_cachetable_get_state(t, &n_entries, &hash_size, &size_current, &size_limit);
while (n_entries != min2(i+1, n)) {
pthread_yield();
toku_pthread_yield();
toku_cachetable_get_state(t, &n_entries, 0, 0, 0);
}
assert(n_entries == min2(i+1, n));
......
......@@ -8,22 +8,22 @@
// global data, especially between the test thread and the cachetable
// writeback threads
pthread_mutex_t test_mutex;
toku_pthread_mutex_t test_mutex;
static inline void test_mutex_init() {
int r = pthread_mutex_init(&test_mutex, 0); assert(r == 0);
int r = toku_pthread_mutex_init(&test_mutex, 0); assert(r == 0);
}
static inline void test_mutex_destroy() {
int r = pthread_mutex_destroy(&test_mutex); assert(r == 0);
int r = toku_pthread_mutex_destroy(&test_mutex); assert(r == 0);
}
static inline void test_mutex_lock() {
int r = pthread_mutex_lock(&test_mutex); assert(r == 0);
int r = toku_pthread_mutex_lock(&test_mutex); assert(r == 0);
}
static inline void test_mutex_unlock() {
int r = pthread_mutex_unlock(&test_mutex); assert(r == 0);
int r = toku_pthread_mutex_unlock(&test_mutex); assert(r == 0);
}
static const int test_object_size = 1;
......@@ -48,7 +48,7 @@ static void print_ints(void) {
}
static void item_becomes_present(CACHEFILE cf, CACHEKEY key) {
while (n_present >= N_PRESENT_LIMIT) pthread_yield();
while (n_present >= N_PRESENT_LIMIT) toku_pthread_yield();
test_mutex_lock();
assert(n_present<N_PRESENT_LIMIT);
present_items[n_present].cf = cf;
......
......@@ -36,9 +36,9 @@ static void
test_simple_enq_deq (int n) {
struct writequeue writequeue, *wq = &writequeue;
int r;
pthread_mutex_t mutex;
toku_pthread_mutex_t mutex;
r = pthread_mutex_init(&mutex, 0); assert(r == 0);
r = toku_pthread_mutex_init(&mutex, 0); assert(r == 0);
writequeue_init(wq);
assert(writequeue_empty(wq));
PAIR pairs[n];
......@@ -56,7 +56,7 @@ test_simple_enq_deq (int n) {
}
assert(writequeue_empty(wq));
writequeue_destroy(wq);
r = pthread_mutex_destroy(&mutex); assert(r == 0);
r = toku_pthread_mutex_destroy(&mutex); assert(r == 0);
}
// setting the wq closed should cause deq to return EINVAL
......@@ -75,19 +75,19 @@ test_set_closed (void) {
struct writequeue_with_mutex {
struct writequeue writequeue;
pthread_mutex_t mutex;
toku_pthread_mutex_t mutex;
};
static void
writequeue_with_mutex_init (struct writequeue_with_mutex *wqm) {
writequeue_init(&wqm->writequeue);
int r = pthread_mutex_init(&wqm->mutex, 0); assert(r == 0);
int r = toku_pthread_mutex_init(&wqm->mutex, 0); assert(r == 0);
}
static void
writequeue_with_mutex_destroy (struct writequeue_with_mutex *wqm) {
writequeue_destroy(&wqm->writequeue);
int r = pthread_mutex_destroy(&wqm->mutex); assert(r == 0);
int r = toku_pthread_mutex_destroy(&wqm->mutex); assert(r == 0);
}
static void *
......@@ -95,11 +95,11 @@ test_set_closed_waiter(void *arg) {
struct writequeue_with_mutex *wqm = arg;
int r;
r = pthread_mutex_lock(&wqm->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&wqm->mutex); assert(r == 0);
PAIR p;
r = writequeue_deq(&wqm->writequeue, &wqm->mutex, &p);
assert(r == EINVAL);
r = pthread_mutex_unlock(&wqm->mutex); assert(r == 0);
r = toku_pthread_mutex_unlock(&wqm->mutex); assert(r == 0);
return arg;
}
......@@ -109,12 +109,12 @@ test_set_closed_thread (void) {
int r;
writequeue_with_mutex_init(wqm);
pthread_t tid;
r = pthread_create(&tid, 0, test_set_closed_waiter, wqm); assert(r == 0);
toku_pthread_t tid;
r = toku_pthread_create(&tid, 0, test_set_closed_waiter, wqm); assert(r == 0);
sleep(1);
writequeue_set_closed(&wqm->writequeue);
void *ret;
r = pthread_join(tid, &ret);
r = toku_pthread_join(tid, &ret);
assert(r == 0 && ret == wqm);
writequeue_with_mutex_destroy(wqm);
}
......@@ -126,14 +126,14 @@ test_set_closed_thread (void) {
// writers when the wq size <= 1/2 of the wq limit
struct rwfc {
pthread_mutex_t mutex;
toku_pthread_mutex_t mutex;
struct writequeue writequeue;
int current, limit;
};
static void rwfc_init (struct rwfc *rwfc, int limit) {
int r;
r = pthread_mutex_init(&rwfc->mutex, 0); assert(r == 0);
r = toku_pthread_mutex_init(&rwfc->mutex, 0); assert(r == 0);
writequeue_init(&rwfc->writequeue);
rwfc->current = 0; rwfc->limit = limit;
}
......@@ -142,7 +142,7 @@ static void
rwfc_destroy (struct rwfc *rwfc) {
int r;
writequeue_destroy(&rwfc->writequeue);
r = pthread_mutex_destroy(&rwfc->mutex); assert(r == 0);
r = toku_pthread_mutex_destroy(&rwfc->mutex); assert(r == 0);
}
static void *
......@@ -151,16 +151,16 @@ rwfc_reader (void *arg) {
int r;
while (1) {
PAIR ctpair;
r = pthread_mutex_lock(&rwfc->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&rwfc->mutex); assert(r == 0);
r = writequeue_deq(&rwfc->writequeue, &rwfc->mutex, &ctpair);
if (r == EINVAL) {
r = pthread_mutex_unlock(&rwfc->mutex); assert(r == 0);
r = toku_pthread_mutex_unlock(&rwfc->mutex); assert(r == 0);
break;
}
if (2*rwfc->current-- > rwfc->limit && 2*rwfc->current <= rwfc->limit) {
writequeue_wakeup_write(&rwfc->writequeue);
}
r = pthread_mutex_unlock(&rwfc->mutex); assert(r == 0);
r = toku_pthread_mutex_unlock(&rwfc->mutex); assert(r == 0);
destroy_pair(ctpair);
usleep(random() % 100);
}
......@@ -172,25 +172,25 @@ test_flow_control (int limit, int n) {
struct rwfc my_rwfc, *rwfc = &my_rwfc;
int r;
rwfc_init(rwfc, limit);
pthread_t tid;
r = pthread_create(&tid, 0, rwfc_reader, rwfc); assert(r == 0);
toku_pthread_t tid;
r = toku_pthread_create(&tid, 0, rwfc_reader, rwfc); assert(r == 0);
sleep(1); // this is here to block the reader on the first deq
int i;
for (i=0; i<n; i++) {
PAIR ctpair = new_pair();
r = pthread_mutex_lock(&rwfc->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&rwfc->mutex); assert(r == 0);
writequeue_enq(&rwfc->writequeue, ctpair);
rwfc->current++;
while (rwfc->current >= rwfc->limit) {
// printf("%d - %d %d\n", i, rwfc->current, rwfc->limit);
writequeue_wait_write(&rwfc->writequeue, &rwfc->mutex);
}
r = pthread_mutex_unlock(&rwfc->mutex); assert(r == 0);
r = toku_pthread_mutex_unlock(&rwfc->mutex); assert(r == 0);
// usleep(random() % 1);
}
writequeue_set_closed(&rwfc->writequeue);
void *ret;
r = pthread_join(tid, &ret); assert(r == 0);
r = toku_pthread_join(tid, &ret); assert(r == 0);
rwfc_destroy(rwfc);
}
......
......@@ -5,15 +5,15 @@
#include <string.h>
#include <errno.h>
#include <malloc.h>
#include <pthread.h>
#include <toku_pthread.h>
#include "threadpool.h"
int verbose = 0;
struct my_threadpool {
THREADPOOL threadpool;
pthread_mutex_t mutex;
pthread_cond_t wait;
toku_pthread_mutex_t mutex;
toku_pthread_cond_t wait;
int closed;
};
......@@ -22,23 +22,23 @@ my_threadpool_init (struct my_threadpool *my_threadpool, int max_threads) {
int r;
r = threadpool_create(&my_threadpool->threadpool, max_threads); assert(r == 0);
assert(my_threadpool != 0);
r = pthread_mutex_init(&my_threadpool->mutex, 0); assert(r == 0);
r = pthread_cond_init(&my_threadpool->wait, 0); assert(r == 0);
r = toku_pthread_mutex_init(&my_threadpool->mutex, 0); assert(r == 0);
r = toku_pthread_cond_init(&my_threadpool->wait, 0); assert(r == 0);
my_threadpool->closed = 0;
}
static void
my_threadpool_destroy (struct my_threadpool *my_threadpool) {
int r;
r = pthread_mutex_lock(&my_threadpool->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&my_threadpool->mutex); assert(r == 0);
my_threadpool->closed = 1;
r = pthread_cond_broadcast(&my_threadpool->wait); assert(r == 0);
r = pthread_mutex_unlock(&my_threadpool->mutex); assert(r == 0);
r = toku_pthread_cond_broadcast(&my_threadpool->wait); assert(r == 0);
r = toku_pthread_mutex_unlock(&my_threadpool->mutex); assert(r == 0);
if (verbose) printf("current %d\n", threadpool_get_current_threads(my_threadpool->threadpool));
threadpool_destroy(&my_threadpool->threadpool); assert(my_threadpool->threadpool == 0);
r = pthread_mutex_destroy(&my_threadpool->mutex); assert(r == 0);
r = pthread_cond_destroy(&my_threadpool->wait); assert(r == 0);
r = toku_pthread_mutex_destroy(&my_threadpool->mutex); assert(r == 0);
r = toku_pthread_cond_destroy(&my_threadpool->wait); assert(r == 0);
}
static void *
......@@ -46,12 +46,12 @@ fbusy (void *arg) {
struct my_threadpool *my_threadpool = arg;
int r;
r = pthread_mutex_lock(&my_threadpool->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&my_threadpool->mutex); assert(r == 0);
while (!my_threadpool->closed) {
r = pthread_cond_wait(&my_threadpool->wait, &my_threadpool->mutex); assert(r == 0);
r = toku_pthread_cond_wait(&my_threadpool->wait, &my_threadpool->mutex); assert(r == 0);
}
r = pthread_mutex_unlock(&my_threadpool->mutex); assert(r == 0);
if (verbose) printf("%lu:%s:exit\n", pthread_self(), __FUNCTION__);
r = toku_pthread_mutex_unlock(&my_threadpool->mutex); assert(r == 0);
if (verbose) printf("%lu:%s:exit\n", toku_pthread_self(), __FUNCTION__);
return arg;
}
......@@ -60,13 +60,13 @@ fidle (void *arg) {
struct my_threadpool *my_threadpool = arg;
int r;
r = pthread_mutex_lock(&my_threadpool->mutex); assert(r == 0);
r = toku_pthread_mutex_lock(&my_threadpool->mutex); assert(r == 0);
threadpool_set_thread_idle(my_threadpool->threadpool);
while (!my_threadpool->closed) {
r = pthread_cond_wait(&my_threadpool->wait, &my_threadpool->mutex); assert(r == 0);
r = toku_pthread_cond_wait(&my_threadpool->wait, &my_threadpool->mutex); assert(r == 0);
}
r = pthread_mutex_unlock(&my_threadpool->mutex); assert(r == 0);
if (verbose) printf("%lu:%s:exit\n", pthread_self(), __FUNCTION__);
r = toku_pthread_mutex_unlock(&my_threadpool->mutex); assert(r == 0);
if (verbose) printf("%lu:%s:exit\n", toku_pthread_self(), __FUNCTION__);
return arg;
}
......
......@@ -7,11 +7,11 @@ struct threadpool {
int max_threads;
int current_threads;
int busy_threads;
pthread_t pids[];
toku_pthread_t pids[];
};
int threadpool_create(THREADPOOL *threadpoolptr, int max_threads) {
size_t size = sizeof (struct threadpool) + max_threads*sizeof (pthread_t);
size_t size = sizeof (struct threadpool) + max_threads*sizeof (toku_pthread_t);
struct threadpool *threadpool = malloc(size);
if (threadpool == 0)
return ENOMEM;
......@@ -30,7 +30,7 @@ void threadpool_destroy(THREADPOOL *threadpoolptr) {
int i;
for (i=0; i<threadpool->current_threads; i++) {
int r; void *ret;
r = pthread_join(threadpool->pids[i], &ret);
r = toku_pthread_join(threadpool->pids[i], &ret);
assert(r == 0);
}
*threadpoolptr = 0;
......@@ -39,7 +39,7 @@ void threadpool_destroy(THREADPOOL *threadpoolptr) {
void threadpool_maybe_add(THREADPOOL threadpool, void *(*f)(void *), void *arg) {
if ((threadpool->current_threads == 0 || threadpool->busy_threads < threadpool->current_threads) && threadpool->current_threads < threadpool->max_threads) {
int r = pthread_create(&threadpool->pids[threadpool->current_threads], 0, f, arg);
int r = toku_pthread_create(&threadpool->pids[threadpool->current_threads], 0, f, arg);
if (r == 0) {
threadpool->current_threads++;
threadpool_set_thread_busy(threadpool);
......
# -*- Mode: Makefile -*-
.DEFAULT_GOAL=install
TOKUROOT=../
INCLUDEDIRS=-I.
SKIP_LIBPORTABILITYRULE=1
include $(TOKUROOT)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 = tokuwindows.$(AEXT)
install: $(LIBPORTABILITY)
$(LIBPORTABILITY): $(TARGET)
$(MAYBEATSIGN)cp $< $@
$(TARGET): $(OBJS)
clean:
$(MAYBEATSIGN)rm -rf $(TARGET) $(LIBPORTABILITY)
#ifndef _TOKU_DIRENT_H
#define _TOKU_DIRENT_H
//The DIR functions do not exist in windows, but the Linux API ends up
//just using a wrapper. We might convert these into an os_* type api.
DIR *opendir(const char *name);
struct dirent *readdir(DIR *dir);
int closedir(DIR *dir);
#ifndef NAME_MAX
#define NAME_MAX 255
#endif
#endif
#ifndef _INTTYPES_H
#define _INTTYPES_H
#include <stdint.h>
//Define printf types.
#define PRId64 "I64d"
#define PRIu64 "I64u"
#define PRIx64 "I64x"
#define PRId32 "d"
#define PRIu32 "u"
#endif
#ifndef _MISC_H
#define _MISC_H
#include "os.h"
#include <sys/stat.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 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
//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);
//snprintf
//TODO: Put in its own file, or define a snprintf function based on _vsnprintf
//in its own file
#define snprintf(str, size, fmt, ...) _snprintf(str, size, fmt, __VA_ARGS__)
//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 1
#endif
char *realpath(const char *path, char *resolved_path);
int unsetenv(const char *name);
int setenv(const char *name, const char *value, int overwrite);
#endif
#if !defined(OS_INTERFACE_WINDOWS_H)
#define OS_INTERFACE_WINDOWS_H
#include <stdlib.h>
#include <direct.h>
// define an OS handle
typedef void *os_handle_t;
typedef int pid_t;
typedef int mode_t;
struct fileid {
uint32_t st_dev;
uint64_t st_ino;
uint64_t st_creat;
};
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;
#endif
#include <windows.h>
#include <stdint.h>
#include <inttypes.h>
#include <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
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
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;
}
#ifndef _STDINT_H
#define _STDINT_H
#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
#endif
# -*- Mode: Makefile -*-
.DEFAULT_GOAL=all
TOKUROOT=../../
INCLUDEDIRS=-I$(TOKUROOT)include/windows -I$(TOKUROOT)newbrt
include $(TOKUROOT)include/Makefile.include
SKIP_WARNING += $(ICC_NOWARN)1418 #Non static functions do not need prototypes.
SRCS = $(wildcard test-*.c)
BINS_RAW = $(patsubst %.c,%,$(SRCS))
#Bins will be generated.
$(BINS): $(LIBPORTABILITY)
$(BINS): CFLAGS+=-DTESTDIR=\"dir.$<.dir\"
all: $(BINS)
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <fcntl.h>
#include "portability.h"
#include "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 main(int argc, char *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 = os_mkdir(TESTDIR, 0777); assert(r==0);
found = walk(TESTDIR);
assert(found == 0);
//Try to delete the empty directory
system("rm -rf " TESTDIR);
r = 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;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fcntl.h>
#include "portability.h"
#include "os.h"
int verbose=0;
//TODO: Test that different files are different,
// other stuff
static void test_handles(const char *fname) {
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 = os_get_unique_file_id(fd, &id_base);
assert(r==0);
for (i=0; i < 1<<16; i++) {
r = os_get_unique_file_id(fd, &id);
assert(r==0);
assert(memcmp(&id, &id_base, sizeof(id))==0);
}
r = close(fd);
assert(r==0);
}
int main(int argc, char *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("junk");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <assert.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#if 0 && defined _WIN32
#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 main(void) {
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);
r = write(fd, junk, sizeof junk);
assert(r == sizeof junk);
}
struct stat filestat;
r = 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 = 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;
}
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
int main(int argc, char *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;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#ifdef _WIN32
#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 main(void) {
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 = 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 defined(_WIN32)
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;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#ifdef _WIN32
#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 main(void) {
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 defined(_WIN32)
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;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fcntl.h>
#include "portability.h"
#include "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 main(int argc, char *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;
}
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <assert.h>
#include <windows.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 main(void) {
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;
}
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <assert.h>
#include <windows.h>
#include "toku_pthread.h"
static void *myfunc1(void *arg) {
printf("%s %p %lu\n", __FUNCTION__, arg, GetCurrentThreadId());
fflush(stdout);
Sleep(10*1000);
return arg;
}
static void *myfunc2(void *arg) {
printf("%s %p %lu\n", __FUNCTION__, arg, GetCurrentThreadId());
fflush(stdout);
Sleep(10*1000);
return arg;
}
int main(void) {
#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;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#include <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 main(void) {
int64_t rss;
os_get_max_rss(&rss);
printf("%I64d\n", rss);
do_mallocs();
os_get_max_rss(&rss);
printf("%I64d\n", rss);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fcntl.h>
#include "portability.h"
#include "os.h"
int verbose;
int main(int argc, char *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;
}
#include <portability.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <sys/stat.h>
void test_stat(char *dirname) {
int r;
struct stat s;
r = stat(dirname, &s);
printf("stat %s %d\n", dirname, r);
}
int main(void) {
int r;
test_stat(".");
r = os_mkdir("testdir", S_IRWXU);
assert(r == 0);
test_stat("testdir");
test_stat("./testdir");
test_stat("./testdir/");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "portability.h"
#include "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 main(int argc, char *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;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fcntl.h>
#include "portability.h"
int main(void) {
int r;
int fd;
struct fileid fid;
fd = open(DEV_NULL_FILE, O_RDWR);
assert(fd != -1);
r = os_get_unique_file_id(fd, &fid);
printf("%s:%d %d\n", __FILE__, __LINE__, r);
r = close(fd);
assert(r != -1);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fcntl.h>
#include <windows.h>
#include <winsock.h>
int verbose;
int usleep(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 main(int argc, char *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=%u\n", s);
for (i=0; i<1000; i++) {
if (verbose) {
printf("usleep %d\n", i); fflush(stdout);
}
usleep(s, n);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fcntl.h>
#include "portability.h"
#include "os.h"
int verbose;
int main(int argc, char *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;
}
#include <windows.h>
#include <assert.h>
#include <errno.h>
#include <toku_pthread.h>
int
toku_pthread_mutex_init(toku_pthread_mutex_t *mutex, const toku_pthread_mutexattr_t *attr) {
assert(attr == NULL);
// assert(!mutex->initialized);
InitializeCriticalSection(&mutex->section);
mutex->initialized = TRUE;
return 0;
}
int
toku_pthread_mutex_destroy(toku_pthread_mutex_t *mutex) {
assert(mutex->initialized);
DeleteCriticalSection(&mutex->section);
mutex->initialized = FALSE;
return 0;
}
int
toku_pthread_mutex_lock(toku_pthread_mutex_t *mutex) {
if (!mutex->initialized) {
int r = toku_pthread_mutex_init(mutex, NULL);
assert(r==0);
}
assert(mutex->initialized);
EnterCriticalSection(&mutex->section);
return 0;
}
#if 0
int
toku_pthread_mutex_trylock(toku_pthread_mutex_t *mutex) {
int r = 0;
if (!TryEnterCriticalSection(&mutex->section))
r = EBUSY;
return r;
}
#endif
int
toku_pthread_mutex_unlock(toku_pthread_mutex_t *mutex) {
assert(mutex->initialized);
LeaveCriticalSection(&mutex->section);
return 0;
}
int
toku_pthread_attr_init(toku_pthread_attr_t *attr) {
attr->stacksize = 0;
return 0;
}
int
toku_pthread_attr_destroy(toku_pthread_attr_t *attr) {
attr = attr;
return 0;
}
int
toku_pthread_attr_setstacksize(toku_pthread_attr_t *attr, size_t stacksize) {
attr->stacksize = stacksize;
return 0;
}
int
toku_pthread_attr_getstacksize(toku_pthread_attr_t *attr, size_t *stacksize) {
*stacksize = attr->stacksize;
return 0;
}
static DWORD WINAPI
toku_pthread_start(LPVOID a) {
toku_pthread_t thread = (toku_pthread_t) a;
thread->ret = thread->f(thread->arg);
return 0;
}
int
toku_pthread_create(toku_pthread_t *threadptr, const toku_pthread_attr_t *attr, void *(*f)(void *), void *arg) {
size_t stacksize = 0;
toku_pthread_t thread = malloc(sizeof (struct toku_pthread));
if (thread == 0)
return ENOMEM;
if (attr)
stacksize = attr->stacksize;
thread->f = f;
thread->arg = arg;
// _beginthread or CreateThread
thread->handle = CreateThread(NULL, stacksize, toku_pthread_start, thread, 0, &thread->id);
*threadptr = thread;
return 0;
}
int
toku_pthread_join(toku_pthread_t thread, void **ret) {
WaitForSingleObject(thread->handle, INFINITE);
if (ret)
*ret = thread->ret;
free(thread);
return 0;
}
toku_pthread_t
toku_pthread_self(void) {
// lookup a pthread by thread id and return it
return 0;
}
#if 0
void
toku_pthread_exit(void *ret) {
toku_pthread_t self = toku_pthread_self();
thread->ret = ret;
// _endthread or ExitThread
ExitThread(0);
}
#endif
int
toku_pthread_cond_init(toku_pthread_cond_t *cond, const toku_pthread_condattr_t *attr) {
int r;
assert(attr == 0);
cond->events[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
if (cond->events[0] == NULL)
return GetLastError();
cond->events[1] = CreateEvent(NULL, TRUE, FALSE, NULL);
if (cond->events[1] == NULL) {
r = GetLastError();
CloseHandle(cond->events[0]);
return r;
}
cond->waiters = 0;
return 0;
}
int
toku_pthread_cond_destroy(toku_pthread_cond_t *cond) {
int i;
for (i=0; i<TOKU_PTHREAD_COND_NEVENTS; i++)
CloseHandle(cond->events[i]);
return 0;
}
int
toku_pthread_cond_wait(toku_pthread_cond_t *cond, toku_pthread_mutex_t *mutex) {
DWORD r;
cond->waiters++;
toku_pthread_mutex_unlock(mutex);
r = WaitForMultipleObjects(TOKU_PTHREAD_COND_NEVENTS, cond->events, FALSE, INFINITE);
toku_pthread_mutex_lock(mutex);
cond->waiters--;
if (cond->waiters == 0 && r == WAIT_OBJECT_0 + 1)
ResetEvent(cond->events[1]);
return 0;
}
int
toku_pthread_cond_broadcast(toku_pthread_cond_t *cond) {
if (cond->waiters > 0)
SetEvent(cond->events[1]);
return 0;
}
int
toku_pthread_cond_signal(toku_pthread_cond_t *cond) {
if (cond->waiters > 0)
SetEvent(cond->events[0]);
return 0;
}
int
toku_pthread_yield(void) {
Sleep(0);
return 0;
}
#ifndef _TOKU_PTHREAD_H
#define _TOKU_PTHREAD_H
#if defined __cplusplus
extern "C" {
#endif
// pthread types
typedef struct toku_pthread_attr {
SIZE_T stacksize;
} toku_pthread_attr_t;
typedef struct toku_pthread {
HANDLE handle;
DWORD id;
void *(*f)(void *);
void *arg;
void *ret;
} *toku_pthread_t;
typedef struct toku_pthread_mutexattr *toku_pthread_mutexattr_t;
typedef struct toku_pthread_mutex {
CRITICAL_SECTION section;
BOOL initialized;
} toku_pthread_mutex_t;
#define TOKU_PTHREAD_MUTEX_INITIALIZER { 0, 0 }
typedef struct toku_pthread_condattr *toku_pthread_condattr_t;
// WINNT >= 6 supports condition variables. For now, we use a couple of events.
#define TOKU_PTHREAD_COND_NEVENTS 2
typedef struct toku_pthread_cond {
#if 0
CONDITION_VARIABLE wcv;
#else
HANDLE events[TOKU_PTHREAD_COND_NEVENTS];
int waiters;
#endif
} toku_pthread_cond_t;
// pthread interface
int toku_pthread_yield(void);
int toku_pthread_attr_init(toku_pthread_attr_t *);
int toku_pthread_attr_destroy(toku_pthread_attr_t *);
int toku_pthread_attr_getstacksize(toku_pthread_attr_t *, size_t *stacksize);
int toku_pthread_attr_setstacksize(toku_pthread_attr_t *, size_t stacksize);
int toku_pthread_create(toku_pthread_t *thread, const toku_pthread_attr_t *attr, void *(*start_function)(void *), void *arg);
int toku_pthread_join(toku_pthread_t thread, void **value_ptr);
toku_pthread_t toku_pthread_self(void);
int toku_pthread_mutex_init(toku_pthread_mutex_t *mutex, const toku_pthread_mutexattr_t *attr);
int toku_pthread_mutex_destroy(toku_pthread_mutex_t *mutex);
int toku_pthread_mutex_lock(toku_pthread_mutex_t *mutex);
int toku_pthread_mutex_trylock(toku_pthread_mutex_t *mutex);
int toku_pthread_mutex_unlock(toku_pthread_mutex_t *mutex);
int toku_pthread_cond_init(toku_pthread_cond_t *cond, const toku_pthread_condattr_t *attr);
int toku_pthread_cond_destroy(toku_pthread_cond_t *cond);
int toku_pthread_cond_wait(toku_pthread_cond_t *cond, toku_pthread_mutex_t *mutex);
int toku_pthread_cond_signal(toku_pthread_cond_t *cond);
int toku_pthread_cond_broadcast(toku_pthread_cond_t *cond);
#if defined __cplusplus
};
#endif
#endif
#ifndef _TOKUWIN_UNISTD_H
#define _TOKUWIN_UNISTD_H
#include <io.h>
#include <stdio.h>
int
ftruncate(int fildes, int64_t offset);
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);
#endif
This diff is collapsed.
/* 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 */
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment