2013-04-16 23:57:27 -04:00
|
|
|
#ifndef TOKU_PORTABILITY_H
|
|
|
|
#define TOKU_PORTABILITY_H
|
|
|
|
|
2013-04-16 23:57:28 -04:00
|
|
|
// Tokutek portability layer
|
|
|
|
|
2013-04-16 23:59:09 -04:00
|
|
|
#if defined(__cplusplus) || defined(__cilkplusplus)
|
2013-04-16 23:57:27 -04:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-04-16 23:57:28 -04:00
|
|
|
#if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(__ICL))
|
2013-04-16 23:57:27 -04:00
|
|
|
|
|
|
|
#define TOKU_WINDOWS 1
|
2013-04-16 23:57:28 -04:00
|
|
|
#define DEV_NULL_FILE "NUL"
|
2013-04-16 23:57:27 -04:00
|
|
|
|
2013-04-16 23:59:06 -04:00
|
|
|
# if defined(_WIN64)
|
|
|
|
# define TOKU_WINDOWS_32 0
|
|
|
|
# define TOKU_WINDOWS_64 1
|
|
|
|
# else
|
|
|
|
# define TOKU_WINDOWS_32 1
|
|
|
|
# define TOKU_WINDOWS_64 2
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-04-16 23:57:28 -04:00
|
|
|
#else
|
2013-04-16 23:57:27 -04:00
|
|
|
|
2013-04-16 23:57:28 -04:00
|
|
|
#define TOKU_WINDOWS 0
|
2013-04-16 23:59:06 -04:00
|
|
|
#define TOKU_WINDOWS_32 0
|
|
|
|
#define TOKU_WINDOWS_64 0
|
2013-04-16 23:57:28 -04:00
|
|
|
#define DEV_NULL_FILE "/dev/null"
|
2013-04-16 23:57:27 -04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-04-16 23:57:28 -04:00
|
|
|
#if TOKU_WINDOWS
|
2013-04-16 23:57:27 -04:00
|
|
|
// Windows
|
|
|
|
|
2013-04-16 23:59:17 -04:00
|
|
|
#define DO_GCC_PRAGMA(x) /* Nothing */
|
|
|
|
|
2013-04-16 23:57:37 -04:00
|
|
|
#if defined(__ICL)
|
|
|
|
#define __attribute__(x) /* Nothing */
|
|
|
|
#endif
|
|
|
|
|
2013-04-16 23:59:22 -04:00
|
|
|
#include <malloc.h>
|
2013-04-16 23:57:54 -04:00
|
|
|
#include "toku_stdint.h"
|
2013-04-16 23:57:45 -04:00
|
|
|
|
|
|
|
#ifndef TOKU_OFF_T_DEFINED
|
|
|
|
#define TOKU_OFF_T_DEFINED
|
|
|
|
typedef int64_t toku_off_t;
|
|
|
|
#endif
|
|
|
|
|
2013-04-16 23:57:28 -04:00
|
|
|
#include <direct.h>
|
|
|
|
#include <sys/types.h>
|
2013-04-16 23:57:27 -04:00
|
|
|
#include "unistd.h"
|
|
|
|
#include "misc.h"
|
2013-04-16 23:57:28 -04:00
|
|
|
#include "toku_pthread.h"
|
2013-04-16 23:57:27 -04:00
|
|
|
|
|
|
|
#define UNUSED_WARNING(a) a=a /* To make up for missing attributes */
|
|
|
|
|
2013-04-16 23:59:09 -04:00
|
|
|
#define cast_to_typeof(v)
|
|
|
|
|
2013-04-16 23:57:27 -04:00
|
|
|
#elif defined(__INTEL_COMPILER)
|
|
|
|
|
2013-04-16 23:59:17 -04:00
|
|
|
#define DO_GCC_PRAGMA(x) /* Nothing */
|
|
|
|
|
2013-04-16 23:57:27 -04:00
|
|
|
#if defined(__ICC)
|
|
|
|
// Intel linux
|
|
|
|
|
2013-04-16 23:59:22 -04:00
|
|
|
#include <alloca.h>
|
2013-04-16 23:57:54 -04:00
|
|
|
#include <toku_stdint.h>
|
2013-04-16 23:57:27 -04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
2013-04-16 23:59:13 -04:00
|
|
|
#include <stdio.h>
|
2013-04-16 23:57:27 -04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-04-16 23:59:09 -04:00
|
|
|
#define cast_to_typeof(v) (__typeof__(v))
|
2013-04-16 23:57:27 -04:00
|
|
|
#elif defined(__GNUC__)
|
|
|
|
// GCC linux
|
|
|
|
|
2013-04-16 23:59:17 -04:00
|
|
|
#define DO_GCC_PRAGMA(x) _Pragma (#x)
|
|
|
|
|
2013-04-16 23:57:54 -04:00
|
|
|
#include <toku_stdint.h>
|
2013-04-16 23:57:27 -04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
2013-04-16 23:57:53 -04:00
|
|
|
#include <sys/stat.h>
|
2013-04-16 23:59:13 -04:00
|
|
|
#include <stdio.h>
|
2013-04-16 23:57:53 -04:00
|
|
|
#if __FreeBSD__
|
|
|
|
#include <stdarg.h>
|
|
|
|
#endif
|
2013-04-16 23:59:22 -04:00
|
|
|
#include <alloca.h>
|
2013-04-16 23:57:27 -04:00
|
|
|
|
2013-04-16 23:59:09 -04:00
|
|
|
#define cast_to_typeof(v) (__typeof__(v))
|
2013-04-16 23:57:27 -04:00
|
|
|
#else
|
|
|
|
|
|
|
|
#error Not ICC and not GNUC. What compiler?
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-04-16 23:57:45 -04:00
|
|
|
#ifndef TOKU_OFF_T_DEFINED
|
|
|
|
#define TOKU_OFF_T_DEFINED
|
|
|
|
typedef int64_t toku_off_t;
|
|
|
|
#endif
|
|
|
|
|
2013-04-16 23:57:28 -04:00
|
|
|
#include "toku_os.h"
|
2013-04-16 23:57:46 -04:00
|
|
|
#include "toku_htod.h"
|
2013-04-16 23:57:27 -04:00
|
|
|
|
|
|
|
#define UU(x) x __attribute__((__unused__))
|
|
|
|
|
2013-04-16 23:57:30 -04:00
|
|
|
// Deprecated functions.
|
2013-04-16 23:57:30 -04:00
|
|
|
#if !defined(TOKU_ALLOW_DEPRECATED)
|
2013-04-16 23:57:30 -04:00
|
|
|
# if defined(__ICL) //Windows Intel Compiler
|
2013-04-16 23:57:45 -04:00
|
|
|
# pragma deprecated (creat, fstat, stat, getpid, syscall, sysconf, mkdir, strdup)
|
2013-04-16 23:57:49 -04:00
|
|
|
# pragma poison off_t
|
|
|
|
# pragma poison pthread_attr_t pthread_t
|
|
|
|
# pragma poison pthread_mutexattr_t pthread_mutex_t
|
|
|
|
# pragma poison pthread_condattr_t pthread_cond_t
|
|
|
|
# pragma poison pthread_rwlockattr_t pthread_rwlock_t
|
2013-04-16 23:57:50 -04:00
|
|
|
# pragma poison timespec
|
2013-04-16 23:58:58 -04:00
|
|
|
# ifndef DONT_DEPRECATE_WRITES
|
|
|
|
# pragma poison write pwrite
|
|
|
|
# endif
|
2013-04-16 23:57:34 -04:00
|
|
|
# ifndef DONT_DEPRECATE_MALLOC
|
|
|
|
# pragma deprecated (malloc, free, realloc)
|
|
|
|
# endif
|
2013-04-16 23:58:58 -04:00
|
|
|
# ifndef TOKU_WINDOWS_ALLOW_DEPRECATED
|
|
|
|
# pragma poison dup2
|
|
|
|
# pragma poison _dup2
|
|
|
|
# endif
|
2013-04-16 23:57:30 -04:00
|
|
|
# else
|
2013-04-16 23:58:00 -04:00
|
|
|
int creat(const char *pathname, mode_t mode) __attribute__((__deprecated__));
|
|
|
|
int fstat(int fd, struct stat *buf) __attribute__((__deprecated__));
|
|
|
|
int stat(const char *path, struct stat *buf) __attribute__((__deprecated__));
|
|
|
|
int getpid(void) __attribute__((__deprecated__));
|
|
|
|
long int syscall(long int __sysno, ...) __attribute__((__deprecated__));
|
2013-04-16 23:57:34 -04:00
|
|
|
// Sadly, dlmalloc needs sysconf, and on linux this causes trouble with -combine. So let the warnings show up under windows only.
|
|
|
|
// long int sysconf(int) __attribute__((__deprecated__));
|
2013-04-16 23:58:00 -04:00
|
|
|
int mkdir(const char *pathname, mode_t mode) __attribute__((__deprecated__));
|
2013-04-16 23:58:58 -04:00
|
|
|
int dup2(int fd, int fd2) __attribute__((__deprecated__));
|
|
|
|
int _dup2(int fd, int fd2) __attribute__((__deprecated__));
|
2013-04-16 23:57:33 -04:00
|
|
|
// strdup is a macro in some libraries.
|
|
|
|
#undef strdup
|
|
|
|
char* strdup(const char *) __attribute__((__deprecated__));
|
|
|
|
#undef __strdup
|
|
|
|
char* __strdup(const char *) __attribute__((__deprecated__));
|
2013-04-16 23:58:58 -04:00
|
|
|
# ifndef DONT_DEPRECATE_WRITES
|
|
|
|
ssize_t write(int, const void *, size_t) __attribute__((__deprecated__));
|
|
|
|
ssize_t pwrite(int, const void *, size_t, off_t) __attribute__((__deprecated__));
|
|
|
|
#endif
|
2013-04-16 23:57:34 -04:00
|
|
|
# ifndef DONT_DEPRECATE_MALLOC
|
2013-04-16 23:58:59 -04:00
|
|
|
extern void *malloc(size_t) __THROW __attribute__((__deprecated__)) ;
|
|
|
|
extern void free(void*) __THROW __attribute__((__deprecated__));
|
|
|
|
extern void *realloc(void*, size_t) __THROW __attribute__((__deprecated__));
|
2013-04-16 23:57:34 -04:00
|
|
|
# endif
|
2013-04-16 23:57:30 -04:00
|
|
|
# endif
|
2013-04-16 23:57:30 -04:00
|
|
|
#endif
|
|
|
|
|
2013-04-16 23:57:34 -04:00
|
|
|
void *os_malloc(size_t);
|
|
|
|
void *os_realloc(void*,size_t);
|
|
|
|
void os_free(void*);
|
2013-04-16 23:59:11 -04:00
|
|
|
|
2013-04-16 23:58:55 -04:00
|
|
|
// full_pwrite and full_write performs a pwrite, and checks errors. It doesn't return unless all the data was written. */
|
2013-04-16 23:58:58 -04:00
|
|
|
void toku_os_full_pwrite (int fd, const void *buf, size_t len, toku_off_t off) __attribute__((__visibility__("default")));
|
|
|
|
void toku_os_full_write (int fd, const void *buf, size_t len) __attribute__((__visibility__("default")));
|
2013-04-16 23:59:11 -04:00
|
|
|
|
2013-04-16 23:59:01 -04:00
|
|
|
// os_write returns 0 on success, otherwise an errno.
|
2013-04-16 23:59:12 -04:00
|
|
|
ssize_t toku_os_pwrite (int fd, const void *buf, size_t len, toku_off_t off) __attribute__((__visibility__("default")));
|
2013-04-16 23:59:01 -04:00
|
|
|
int toku_os_write (int fd, const void *buf, size_t len) __attribute__((__visibility__("default")));
|
2013-04-16 23:58:52 -04:00
|
|
|
|
2013-04-16 23:59:13 -04:00
|
|
|
// wrappers around file system calls
|
|
|
|
FILE * toku_os_fdopen(int fildes, const char *mode);
|
|
|
|
FILE * toku_os_fopen(const char *filename, const char *mode);
|
|
|
|
int toku_os_open(const char *path, int oflag, int mode);
|
|
|
|
int toku_os_close(int fd);
|
|
|
|
int toku_os_fclose(FILE * stream);
|
2013-04-16 23:59:20 -04:00
|
|
|
ssize_t toku_os_read(int fd, void *buf, size_t count);
|
2013-04-16 23:59:34 -04:00
|
|
|
ssize_t toku_os_pread(int fd, void *buf, size_t count, off_t offset);
|
2013-04-16 23:59:13 -04:00
|
|
|
|
2013-04-16 23:58:52 -04:00
|
|
|
// wrapper around fsync
|
2013-04-16 23:59:02 -04:00
|
|
|
int toku_file_fsync_without_accounting(int fd);
|
2013-04-16 23:58:52 -04:00
|
|
|
int toku_file_fsync(int fd);
|
2013-04-16 23:57:34 -04:00
|
|
|
|
2013-04-16 23:59:16 -04:00
|
|
|
int toku_fsync_directory(const char *fname);
|
|
|
|
|
2013-04-16 23:59:04 -04:00
|
|
|
// get the number of fsync calls and the fsync times (total)
|
2013-04-16 23:58:52 -04:00
|
|
|
void toku_get_fsync_times(uint64_t *fsync_count, uint64_t *fsync_time);
|
|
|
|
|
2013-04-16 23:59:04 -04:00
|
|
|
// get the number of fsync calls and the fsync times for use by scheduler (subset of total)
|
|
|
|
void toku_get_fsync_sched(uint64_t *fsync_count, uint64_t *fsync_time);
|
|
|
|
|
2013-04-16 23:58:52 -04:00
|
|
|
// set a new fsync function (for debugging)
|
2013-04-16 23:57:34 -04:00
|
|
|
int toku_set_func_fsync (int (*fsync_function)(int));
|
2013-04-16 23:58:52 -04:00
|
|
|
|
2013-04-16 23:57:34 -04:00
|
|
|
int toku_set_func_malloc (void *(*)(size_t));
|
|
|
|
int toku_set_func_realloc (void *(*)(void*,size_t));
|
|
|
|
int toku_set_func_free (void (*)(void*));
|
2013-04-16 23:59:13 -04:00
|
|
|
int toku_set_func_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t));
|
|
|
|
int toku_set_func_full_pwrite (ssize_t (*)(int, const void *, size_t, toku_off_t));
|
|
|
|
int toku_set_func_write (ssize_t (*)(int, const void *, size_t));
|
|
|
|
int toku_set_func_full_write (ssize_t (*)(int, const void *, size_t));
|
|
|
|
int toku_set_func_fdopen (FILE * (*)(int, const char *));
|
|
|
|
int toku_set_func_fopen (FILE * (*)(const char *, const char *));
|
|
|
|
int toku_set_func_open (int (*)(const char *, int, int)); // variadic form not implemented until needed
|
|
|
|
int toku_set_func_fclose(int (*)(FILE*));
|
2013-04-16 23:59:20 -04:00
|
|
|
int toku_set_func_read(ssize_t (*)(int, void *, size_t));
|
2013-04-16 23:59:34 -04:00
|
|
|
int toku_set_func_pread (ssize_t (*)(int, void *, size_t, off_t));
|
2013-04-16 23:57:53 -04:00
|
|
|
int toku_portability_init (void);
|
|
|
|
int toku_portability_destroy (void);
|
|
|
|
|
2013-04-16 23:59:09 -04:00
|
|
|
#if defined(__cplusplus) || defined(__cilkplusplus)
|
2013-04-16 23:57:27 -04:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|