B2BITS FIX Antenna HFT  1.0.16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions | Variables
b2b_platform.h File Reference
#include "platform_align.h"
#include <memory.h>
#include "printf.h"
#include <float.h>
#include <stdexcept>
#include "B2BITS_V12_Defines.h"
#include <B2BITS_String.h>
#include <B2BITS_FIXFieldValue.h>
#include "thread_specific_iface.h"
+ Include dependency graph for b2b_platform.h:
+ This graph shows which files directly or indirectly include this file:

Classes

struct  AppStatus
 The user application status struct. More...
 
class  auto_lock_knock_t2< lock_t >
 
class  auto_lock_t< lock_t >
 
class  auto_lock_t2< lock_t >
 
class  auto_lock_t2< SPINLOCK_T >
 
class  auto_lock_t< SPINLOCK_T >
 
class  auto_plock_t2< lock_t >
 
class  auto_read_lock_t< rwlock_t >
 
class  auto_read_lock_t2< rwlock_t >
 
class  auto_write_lock_t< rwlock_t >
 
class  auto_write_lock_t2< rwlock_t >
 
struct  Bilist
 
struct  DynShortStr< StringLength >
 
struct  DynShortStrWrapper< StringLength >
 
struct  PlatformProps
 Platform configuration parameters. More...
 
class  rwlock_t< lock_t >
 
struct  ShortStr< StringLength >
 
struct  ShortStrCtor< StringLength >
 
struct  ShortStrRef
 
struct  ShortStrRefCtor
 
class  spinlock
 
class  spinlock_reentrant
 
struct  StrRef
 
struct  StrRefCtor
 
class  Switchable< ObjT >
 

Namespaces

 Utils
 Utils namespace.
 
 Utils::Log
 Logging system namespace.
 

Macros

#define _LONG32
 
#define APICALL
 
#define BILISTOF(Bilist_member_ptr, T_Container)   CONTAINEROF(Bilist_member_ptr, T_Container, bilist)
 
#define CONTAINEROF(Member_ptr, T_Container, member_name)   ((T_Container*)(((char*) (Member_ptr)) - OFFSETOF(T_Container, member_name)))
 
#define DEBUG_OUTPUT(x)
 
#define DO_DBG(_thetext)   _thetext
 
#define FD_CLR_OP   FD_CLR
 
#define FD_ISSET_OP   FD_ISSET
 
#define FD_SET_OP   FD_SET
 
#define fd_set_t   fd_set
 
#define FD_ZERO_OP(x, srv)   FD_ZERO(x)
 
#define LOG_FILE_MAX_SIZE   100000000
 
#define OFFSETOF(T_struct, member_name)   ((size_t) &((T_struct*)0)->member_name)
 
#define SAFE_SNPRINTF(ptr, sz, fmt,...)   handle_snprintf_error( _SNPRINTF(ptr, sz, fmt, ##__VA_ARGS__), ptr, sz )
 
#define SAFE_VSNPRINTF(ptr, sz, fmt, args)   handle_snprintf_error( vsnprintf(ptr, sz, fmt, args), ptr, sz )
 
#define SCALE_MULTIPLIER   10000
 
#define scaled_to_int_pair(v)   ((int) ((v) / SCALE_MULTIPLIER)), ((unsigned) ((std::abs(v)) % SCALE_MULTIPLIER))
 
#define scaled_to_int_triple(v)   ( v < 0 ? "-" : ""), ((int) ((std::abs(v)) / SCALE_MULTIPLIER)), ((unsigned) ((std::abs(v)) % SCALE_MULTIPLIER))
 
#define SOCKET_T   SOCKET
 
#define SVN_REVISION   304
 

Typedefs

typedef auto_lock_t< spinlockAutoLock
 
typedef auto_lock_t2< spinlockAutoLock2
 
typedef auto_lock_t
< spinlock_reentrant
AutoLockRe
 
typedef auto_lock_knock_t2
< spinlock_reentrant
AutoLockRe2
 
typedef auto_lock_t< SPINLOCK_TAutoLockT
 
typedef auto_lock_t2< SPINLOCK_TAutoLockT2
 
typedef auto_plock_t2< spinlockAutoPLock2
 
typedef struct Bilist Bilist
 
typedef void(* EXIT_HANDLER_CB )()
 
typedef void(* HANDLE_CMD_CB )(void *sock, char *cmd_buf)
 
typedef int long32
 
typedef scaled64_t price_scaled_t
 
typedef auto_read_lock_t< rwlockReadLock
 
typedef auto_read_lock_t2< rwlockReadLock2
 
typedef rwlock_t< spinlockrwlock
 
typedef int64_t scaled64_t
 
typedef auto_write_lock_t< rwlockWriteLock
 
typedef auto_write_lock_t2
< rwlock
WriteLock2
 

Enumerations

enum  PlatformLogLevel {
  LOG_LEVEL_ALWAYS = 0, LOG_LEVEL_FATAL, LOG_LEVEL_ERROR, LOG_LEVEL_WARN,
  LOG_LEVEL_INFO, LOG_LEVEL_DEBUG
}
 

Functions

struct __attribute__ ((aligned(64))) CachelineAtomic
 
 _Pragma ("pack(1)")
 
 _Pragma ("pack()")
 
static int bitCount (uint64_t mask)
 
static void clearEvenBits (uint64_t *mask)
 
static void clearOddBits (uint64_t *mask)
 
static scaled64_t dbl2int64_scaleup (double dbl)
 
 DECLARE_PER_CPU (thread_id_t, __this_thread_id)
 
void V12_API disable_onload_in_current_thread ()
 
void V12_API disable_onload_spin_in_current_thread ()
 
static scaled64_t double_to_scaled64 (double v)
 
static uint64_t get_cheap_nanosec () throw ()
 
static uint64_t get_millisec () throw ()
 
static uint64_t get_nanosec () throw ()
 
static int get_seconds_from_nanosec ()
 
enum PlatformLogLevel getLogLevel (const char *param)
 
static int getUTCTimestampWithMs (char *out)
 
static void halt ()
 
static int handle_snprintf_error (int snprintf_retval, char *ptr, int sz)
 
void V12_API init_thread (const char *name, bool useAsyncLogger=true, bool setWin32ThreadName=true)
 
void V12_API initHandlers (bool traceOnFaults, bool traceOnAbort, bool traceOnSigUSR2)
 
void V12_API initialize_on_start (uint64_t timeCalibrationCPUMask, uint64_t assignCPUMaskAfterCalib)
 Performs the startup early initialization. More...
 
void V12_API initialize_on_start (ThreadAffMgr *threadAffMgr)
 
void V12_API initialize_on_start_engine (void)
 
static scaled64_t int_to_scaled64 (int v)
 
int V12_API isRiskCheckThreadsReady ()
 
static uint64_t nextBit (uint64_t *mask)
 
static uint64_t nextBitReversed (uint64_t *mask)
 
void V12_API platform_initialize (Utils::Log::LogCategory *engineLog, const char *logLevel="FOLLOW_FIXENGINE", EXIT_HANDLER_CB exitHandlerCb=NULL, HANDLE_CMD_CB handlerCmdCb=NULL)
 Performs the platform initialization using g_platformProps. More...
 
void V12_API print_sys_time_info ()
 
static void printUTCTimestampWithMs (FILE *f)
 
static scaled64_t round_scaled64 (scaled64_t v)
 
static double scaled64_to_double (scaled64_t v)
 
template<typename SCALED_T >
static double scaled_to_double (SCALED_T v)
 
void V12_API setProcessAffinityCPUMask (uint64_t mask)
 
void V12_API setProcessAffinityCPUMask_Verbose (uint64_t mask)
 
void V12_API setThreadAffinityCPUMask (uint64_t mask, pthread_t thread=0)
 
void V12_API setThreadAffinityCPUMask_Verbose (uint64_t mask, pthread_t thread, const char *thread_name)
 
void V12_API setThreadAffinityCPUs (int *cpuNumArray)
 
void V12_API setThreadRealtimePrio_Verbose (int realtimePrio, const char *thread_name)
 
static void sleepns (uint64_t delta_ns) throw ()
 
static void sleepUntil (uint64_t ns, uint64_t delta) throw ()
 
static int sprintfTimeStamp (int year, int month, int day, int hour, int minute, int second, char *buf) throw ()
 
static int sprintfTimeStampWithMSec (int year, int month, int day, int hour, int minute, int second, int msecond, char *buf) throw ()
 
static void terminateApp ()
 
static thread_id_t thread_id () throw ()
 
static void ull_memcpy (void *dst, const void *src, int size) throw ()
 

Variables

PlatformProps V12_API g_platformProps
 
static const int64_t MAX_SCALED64_INT_PART = 0x7fffffffffffffffULL / 10000
 
static const int64_t MAX_SCALED64_VALUE = 0x7fffffffffffffffULL
 
pthread_t riskCheckThreadId
 
uint64_t times [20]
 

Macro Definition Documentation

#define _LONG32
#define APICALL
#define BILISTOF (   Bilist_member_ptr,
  T_Container 
)    CONTAINEROF(Bilist_member_ptr, T_Container, bilist)
#define CONTAINEROF (   Member_ptr,
  T_Container,
  member_name 
)    ((T_Container*)(((char*) (Member_ptr)) - OFFSETOF(T_Container, member_name)))
#define DEBUG_OUTPUT (   x)
#define DO_DBG (   _thetext)    _thetext
#define FD_CLR_OP   FD_CLR
#define FD_ISSET_OP   FD_ISSET
#define FD_SET_OP   FD_SET
#define fd_set_t   fd_set
#define FD_ZERO_OP (   x,
  srv 
)    FD_ZERO(x)
#define LOG_FILE_MAX_SIZE   100000000
#define OFFSETOF (   T_struct,
  member_name 
)    ((size_t) &((T_struct*)0)->member_name)
#define SAFE_SNPRINTF (   ptr,
  sz,
  fmt,
  ... 
)    handle_snprintf_error( _SNPRINTF(ptr, sz, fmt, ##__VA_ARGS__), ptr, sz )
#define SAFE_VSNPRINTF (   ptr,
  sz,
  fmt,
  args 
)    handle_snprintf_error( vsnprintf(ptr, sz, fmt, args), ptr, sz )
#define SCALE_MULTIPLIER   10000
#define scaled_to_int_pair (   v)    ((int) ((v) / SCALE_MULTIPLIER)), ((unsigned) ((std::abs(v)) % SCALE_MULTIPLIER))
#define scaled_to_int_triple (   v)    ( v < 0 ? "-" : ""), ((int) ((std::abs(v)) / SCALE_MULTIPLIER)), ((unsigned) ((std::abs(v)) % SCALE_MULTIPLIER))
#define SOCKET_T   SOCKET
#define SVN_REVISION   304

Typedef Documentation

typedef struct Bilist Bilist
typedef void(* EXIT_HANDLER_CB)()
typedef void(* HANDLE_CMD_CB)(void *sock, char *cmd_buf)
typedef int long32

Enumeration Type Documentation

Enumerator
LOG_LEVEL_ALWAYS 
LOG_LEVEL_FATAL 
LOG_LEVEL_ERROR 
LOG_LEVEL_WARN 
LOG_LEVEL_INFO 
LOG_LEVEL_DEBUG 

Function Documentation

__attribute__ ( (aligned(64))  )
_Pragma ( "pack(1)"  )
_Pragma ( "pack()"  )
static int bitCount ( uint64_t  mask)
inlinestatic
static void clearEvenBits ( uint64_t mask)
inlinestatic

References nextBit().

static void clearOddBits ( uint64_t mask)
inlinestatic

References nextBit().

static scaled64_t dbl2int64_scaleup ( double  dbl)
inlinestatic
DECLARE_PER_CPU ( thread_id_t  ,
__this_thread_id   
)
void V12_API disable_onload_in_current_thread ( )
void V12_API disable_onload_spin_in_current_thread ( )
static scaled64_t double_to_scaled64 ( double  v)
inlinestatic

References SCALE_MULTIPLIER.

static uint64_t get_cheap_nanosec ( )
throw (
)
inlinestatic
static uint64_t get_millisec ( )
throw (
)
inlinestatic
static uint64_t get_nanosec ( )
throw (
)
inlinestatic
static int get_seconds_from_nanosec ( )
inlinestatic

References get_nanosec().

Referenced by CmiProductCatalog::addSymbol().

enum PlatformLogLevel getLogLevel ( const char *  param)
static int getUTCTimestampWithMs ( char *  out)
inlinestatic
static void halt ( )
inlinestatic

Referenced by fifo_create().

static int handle_snprintf_error ( int  snprintf_retval,
char *  ptr,
int  sz 
)
inlinestatic
void V12_API init_thread ( const char *  name,
bool  useAsyncLogger = true,
bool  setWin32ThreadName = true 
)
void V12_API initHandlers ( bool  traceOnFaults,
bool  traceOnAbort,
bool  traceOnSigUSR2 
)
void V12_API initialize_on_start ( uint64_t  timeCalibrationCPUMask,
uint64_t  assignCPUMaskAfterCalib 
)

Performs the startup early initialization.

Should be called before the platform and the engine initialization.

Parameters
timeCalibrationCPUMaskthe CPU affinity mask applied for rdtsc time calibration must be non-zero to perform the calibration.
assignCPUMaskAfterCalibthe CPU affinity mask applied after rdtsc time calibration must be non-zero to perform the calibration.
void V12_API initialize_on_start ( ThreadAffMgr *  threadAffMgr)
void V12_API initialize_on_start_engine ( void  )
static scaled64_t int_to_scaled64 ( int  v)
inlinestatic

References SCALE_MULTIPLIER.

int V12_API isRiskCheckThreadsReady ( )
static uint64_t nextBit ( uint64_t mask)
inlinestatic

Referenced by clearEvenBits(), and clearOddBits().

static uint64_t nextBitReversed ( uint64_t mask)
inlinestatic
void V12_API platform_initialize ( Utils::Log::LogCategory engineLog,
const char *  logLevel = "FOLLOW_FIXENGINE",
EXIT_HANDLER_CB  exitHandlerCb = NULL,
HANDLE_CMD_CB  handlerCmdCb = NULL 
)

Performs the platform initialization using g_platformProps.

Should be called before the engine initialization.

Parameters
engineLogthe log category that will be used by the platform logging functions. See sockets_logging.h
logLevel,thelog level name, its valid values are: "FOLLOW_FIXENGINE", "ALWAYS", "FATAL", "ERROR", "WARNING", "INFO", "DEBUG"
exitHandlerCbthe exit handler callback. It is invoked by the platform when the signal (Linux: SIGTERM,SIGINT; Windows: CTRL_C,CTRL_BREAK,other) is received.
handlerCmdCbthe command handler callback of the command shell. It is invoked by the platform when a command is received.
void V12_API print_sys_time_info ( )
static void printUTCTimestampWithMs ( FILE *  f)
inlinestatic
static scaled64_t round_scaled64 ( scaled64_t  v)
inlinestatic
static double scaled64_to_double ( scaled64_t  v)
inlinestatic

References SCALE_MULTIPLIER.

template<typename SCALED_T >
static double scaled_to_double ( SCALED_T  v)
inlinestatic

References SCALE_MULTIPLIER.

void V12_API setProcessAffinityCPUMask ( uint64_t  mask)
void V12_API setProcessAffinityCPUMask_Verbose ( uint64_t  mask)
void V12_API setThreadAffinityCPUMask ( uint64_t  mask,
pthread_t  thread = 0 
)
void V12_API setThreadAffinityCPUMask_Verbose ( uint64_t  mask,
pthread_t  thread,
const char *  thread_name 
)
void V12_API setThreadAffinityCPUs ( int *  cpuNumArray)
void V12_API setThreadRealtimePrio_Verbose ( int  realtimePrio,
const char *  thread_name 
)
static void sleepns ( uint64_t  delta_ns)
throw (
)
inlinestatic

References get_nanosec(), and sleepUntil().

static void sleepUntil ( uint64_t  ns,
uint64_t  delta 
)
throw (
)
inlinestatic

References cpu_relax, get_nanosec(), and sleepms().

Referenced by sleepns().

static int sprintfTimeStamp ( int  year,
int  month,
int  day,
int  hour,
int  minute,
int  second,
char *  buf 
)
throw (
)
inlinestatic
static int sprintfTimeStampWithMSec ( int  year,
int  month,
int  day,
int  hour,
int  minute,
int  second,
int  msecond,
char *  buf 
)
throw (
)
inlinestatic

References sprintfTimeStamp().

Referenced by getUTCTimestampWithMs().

static void terminateApp ( )
inlinestatic
static thread_id_t thread_id ( )
throw (
)
inlinestatic
static void ull_memcpy ( void *  dst,
const void *  src,
int  size 
)
throw (
)
inlinestatic

Variable Documentation

PlatformProps V12_API g_platformProps
const int64_t MAX_SCALED64_INT_PART = 0x7fffffffffffffffULL / 10000
static
const int64_t MAX_SCALED64_VALUE = 0x7fffffffffffffffULL
static

Referenced by dbl2int64_scaleup().

pthread_t riskCheckThreadId
uint64_t times[20]