B2BITS FIX Antenna HFT  1.0.13
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Macros | Typedefs | Functions
platform_linux.h File Reference
#include <time.h>
#include <sched.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/types.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <memory.h>
#include <stdio.h>
#include <ctype.h>
#include <pthread.h>
#include <stdint.h>
#include <sys/mman.h>
#include "extensions.h"
#include <cstring>
+ Include dependency graph for platform_linux.h:

Macros

#define __USE_GNU
 
#define _SNPRINTF   snprintf
 
#define ALLOC_BIG_CHUNK   malloc
 
#define atomic_bool_compare_swap32(ptr, oldval, newval)   __sync_bool_compare_and_swap( (ptr), (oldval), (newval) )
 
#define atomic_bool_compare_swap64(ptr, oldval, newval)   __sync_bool_compare_and_swap( (ptr), (oldval), (newval) )
 
#define atomic_clear_bit(ptr, bit)   __sync_and_and_fetch((ptr), ~(1<<(bit)))
 
#define atomic_decr32(ptr)   __sync_sub_and_fetch( (ptr), 1 )
 
#define atomic_incr32(ptr)   __sync_add_and_fetch( (ptr), 1 )
 
#define atomic_incr64(ptr)   __sync_add_and_fetch( (ptr), 1 )
 
#define atomic_set_bit(ptr, bit)   __sync_or_and_fetch((ptr), 1<<(bit))
 
#define ATOMIC_T   long
 
#define atomic_test_and_clear_bit(ptr, bit)   ( !! (__sync_fetch_and_and((ptr), ~(1<<(bit))) & (1<<(bit))) )
 
#define ATOMIC_TEST_AND_SET(x)   (!__sync_lock_test_and_set((x), 1))
 
#define atomic_test_and_set_bit(ptr, bit)   ( ! (__sync_fetch_and_or((ptr), 1<<(bit)) & (1<<(bit))) )
 
#define BARRIER()   asm volatile ("" : : : "memory")
 
#define CALLOC   calloc
 
#define CLOSESOCKET   close
 
#define cpu_relax()   asm volatile("pause\n": : :"memory")
 
#define ERRNO   errno
 
#define FLATTEN   __attribute__ ((flatten))
 
#define FREE   free
 
#define HOT   __attribute__ ((hot))
 
#define likely(x)   __builtin_expect(!!(x), 1)
 
#define MALLOC   malloc
 
#define MB()   __sync_synchronize()
 
#define MEMCPY   memcpy
 
#define MEMMOVE   memmove
 
#define MEMSET   memset
 
#define popcnt64   __builtin_popcountll
 
#define PRAGMA_SIMD
 
#define prefetch(x)   __builtin_prefetch((const void *) (x))
 
#define PREFETCH_STRIDE   32
 
#define RD_LOCK   pthread_rwlock_rdlock
 
#define RD_UNLOCK   pthread_rwlock_unlock
 
#define read_prefetch(x)   __builtin_prefetch((const void *) (x), 0)
 
#define REALLOC   realloc
 
#define RWLOCK_FINI(x)   pthread_rwlock_destroy(x)
 
#define RWLOCK_INIT(x)   pthread_rwlock_init((x), 0)
 
#define RWLOCK_T   pthread_rwlock_t
 
#define SPIN_LOCK   sharp_spin_lock
 
#define SPIN_TRYLOCK   sharp_spin_trylock
 
#define SPIN_UNLOCK   sharp_spin_unlock
 
#define SPINLOCK_FINI(x)   sharp_spin_destroy(x)
 
#define SPINLOCK_INIT(x)   sharp_spin_init((x), 0)
 
#define SPINLOCK_T   sharp_spinlock_t
 
#define test_bit(ptr, bit)   (!!(*(ptr) & (1<<(bit))))
 
#define test_mask(ptr, mask)   (!!(*(ptr) & (mask)))
 
#define unlikely(x)   __builtin_expect(!!(x), 0)
 
#define WR_LOCK   pthread_rwlock_wrlock
 
#define WR_UNLOCK   pthread_rwlock_unlock
 
#define write_prefetch(x)   __builtin_prefetch((const void *) (x), 1)
 

Typedefs

typedef volatile unsigned ATOMIC32_T
 
typedef volatile unsigned long long ATOMIC64_T
 
typedef atom_t sharp_spinlock_t
 
typedef int(* SOCKET_accept )(int fd, struct sockaddr *addr, socklen_t *addrlen)
 
typedef int(* SOCKET_bind )(int fd, const struct sockaddr *addr, socklen_t addrlen)
 
typedef int(* SOCKET_close )(int fd)
 
typedef int(* SOCKET_connect )(int fd, const struct sockaddr *addr, socklen_t addrlen)
 
typedef int(* SOCKET_getsockopt )(int s, int level, int optname, void *optval, socklen_t *optlen)
 
typedef int(* SOCKET_listen )(int fd, int backlog)
 
typedef ssize_t(* SOCKET_recv )(int fd, void *buf, size_t size, int flags)
 
typedef int(* SOCKET_select )(int n, fd_set_t *inp, fd_set_t *outp, fd_set_t *exp, struct timeval *tvp)
 
typedef ssize_t(* SOCKET_send )(int fd, const void *buf, size_t len, int flags)
 
typedef int(* SOCKET_setsockopt )(int s, int level, int optname, const void *optval, socklen_t optlen)
 

Functions

static uint64_t cheap_rdtsc () throw ()
 
static uint64_t get_nanosec_stable () throw ()
 
static time_t get_seconds () throw ()
 
void install_signal_handlers (int traceOnFailts, int traceOnSigUSR2)
 
void ipc_socket_init (void)
 
static void prefetch_range (void *addr, size_t len)
 
static uint64_t rdtsc () throw ()
 
static int sharp_spin_destroy (sharp_spinlock_t *) throw ()
 
static int sharp_spin_init (sharp_spinlock_t *l, int) throw ()
 
static int sharp_spin_lock (sharp_spinlock_t *l) throw ()
 
static int sharp_spin_trylock (sharp_spinlock_t *l) throw ()
 
static int sharp_spin_unlock (sharp_spinlock_t *l) throw ()
 
static void sleepms (int ms) throw ()
 

Macro Definition Documentation

#define __USE_GNU
#define _SNPRINTF   snprintf
#define ALLOC_BIG_CHUNK   malloc
#define atomic_bool_compare_swap32 (   ptr,
  oldval,
  newval 
)    __sync_bool_compare_and_swap( (ptr), (oldval), (newval) )
#define atomic_bool_compare_swap64 (   ptr,
  oldval,
  newval 
)    __sync_bool_compare_and_swap( (ptr), (oldval), (newval) )
#define atomic_clear_bit (   ptr,
  bit 
)    __sync_and_and_fetch((ptr), ~(1<<(bit)))
#define atomic_decr32 (   ptr)    __sync_sub_and_fetch( (ptr), 1 )

Referenced by __attribute__().

#define atomic_incr32 (   ptr)    __sync_add_and_fetch( (ptr), 1 )

Referenced by __attribute__().

#define atomic_incr64 (   ptr)    __sync_add_and_fetch( (ptr), 1 )
#define atomic_set_bit (   ptr,
  bit 
)    __sync_or_and_fetch((ptr), 1<<(bit))
#define ATOMIC_T   long
#define atomic_test_and_clear_bit (   ptr,
  bit 
)    ( !! (__sync_fetch_and_and((ptr), ~(1<<(bit))) & (1<<(bit))) )
#define ATOMIC_TEST_AND_SET (   x)    (!__sync_lock_test_and_set((x), 1))
#define atomic_test_and_set_bit (   ptr,
  bit 
)    ( ! (__sync_fetch_and_or((ptr), 1<<(bit)) & (1<<(bit))) )
#define BARRIER ( )    asm volatile ("" : : : "memory")
#define CALLOC   calloc
#define CLOSESOCKET   close
#define cpu_relax ( )    asm volatile("pause\n": : :"memory")
#define ERRNO   errno
int FLATTEN   __attribute__ ((flatten))
#define FREE   free
#define HOT   __attribute__ ((hot))
#define likely (   x)    __builtin_expect(!!(x), 1)
#define MALLOC   malloc
#define MB ( )    __sync_synchronize()
#define MEMCPY   memcpy
#define MEMMOVE   memmove
#define MEMSET   memset
#define popcnt64   __builtin_popcountll
#define PRAGMA_SIMD
#define prefetch (   x)    __builtin_prefetch((const void *) (x))

Referenced by prefetch_range().

#define PREFETCH_STRIDE   32

Referenced by prefetch_range().

#define RD_LOCK   pthread_rwlock_rdlock
#define RD_UNLOCK   pthread_rwlock_unlock
#define read_prefetch (   x)    __builtin_prefetch((const void *) (x), 0)
#define REALLOC   realloc
#define RWLOCK_FINI (   x)    pthread_rwlock_destroy(x)
#define RWLOCK_INIT (   x)    pthread_rwlock_init((x), 0)
#define RWLOCK_T   pthread_rwlock_t
#define SPIN_LOCK   sharp_spin_lock
#define SPIN_TRYLOCK   sharp_spin_trylock
#define SPIN_UNLOCK   sharp_spin_unlock
#define SPINLOCK_FINI (   x)    sharp_spin_destroy(x)
#define SPINLOCK_INIT (   x)    sharp_spin_init((x), 0)
#define SPINLOCK_T   sharp_spinlock_t
#define test_bit (   ptr,
  bit 
)    (!!(*(ptr) & (1<<(bit))))
#define test_mask (   ptr,
  mask 
)    (!!(*(ptr) & (mask)))
#define unlikely (   x)    __builtin_expect(!!(x), 0)
#define WR_LOCK   pthread_rwlock_wrlock
#define WR_UNLOCK   pthread_rwlock_unlock
#define write_prefetch (   x)    __builtin_prefetch((const void *) (x), 1)

Typedef Documentation

typedef volatile unsigned ATOMIC32_T
typedef volatile unsigned long long ATOMIC64_T
typedef int(* SOCKET_accept)(int fd, struct sockaddr *addr, socklen_t *addrlen)
typedef int(* SOCKET_bind)(int fd, const struct sockaddr *addr, socklen_t addrlen)
typedef int(* SOCKET_close)(int fd)
typedef int(* SOCKET_connect)(int fd, const struct sockaddr *addr, socklen_t addrlen)
typedef int(* SOCKET_getsockopt)(int s, int level, int optname, void *optval, socklen_t *optlen)
typedef int(* SOCKET_listen)(int fd, int backlog)
typedef ssize_t(* SOCKET_recv)(int fd, void *buf, size_t size, int flags)
typedef int(* SOCKET_select)(int n, fd_set_t *inp, fd_set_t *outp, fd_set_t *exp, struct timeval *tvp)
typedef ssize_t(* SOCKET_send)(int fd, const void *buf, size_t len, int flags)
typedef int(* SOCKET_setsockopt)(int s, int level, int optname, const void *optval, socklen_t optlen)

Function Documentation

static uint64_t cheap_rdtsc ( )
throw (
)
inlinestatic

Referenced by get_cheap_nanosec().

static uint64_t get_nanosec_stable ( )
throw (
)
inlinestatic
static time_t get_seconds ( )
throw (
)
inlinestatic
void install_signal_handlers ( int  traceOnFailts,
int  traceOnSigUSR2 
)
void ipc_socket_init ( void  )
static void prefetch_range ( void *  addr,
size_t  len 
)
inlinestatic

References prefetch, and PREFETCH_STRIDE.

static uint64_t rdtsc ( )
throw (
)
inlinestatic

Referenced by get_nanosec().

static int sharp_spin_destroy ( sharp_spinlock_t )
throw (
)
static
static int sharp_spin_init ( sharp_spinlock_t l,
int   
)
throw (
)
static

References atom_write.

static int sharp_spin_lock ( sharp_spinlock_t l)
throw (
)
static
static int sharp_spin_trylock ( sharp_spinlock_t l)
throw (
)
static
static int sharp_spin_unlock ( sharp_spinlock_t l)
throw (
)
static
static void sleepms ( int  ms)
throw (
)
inlinestatic

References usleep().

Referenced by sleepUntil().