AndroidCommon.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #pragma once
  2. #ifdef __LP64__
  3. #define BF64
  4. #else
  5. #define BF32
  6. #endif
  7. #define BOOST_DETAIL_NO_CONTAINER_FWD
  8. #include <string>
  9. #include <stdint.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <pthread.h>
  13. #include <time.h>
  14. #include <assert.h>
  15. #include <sys/time.h>
  16. //#include <libkern/OSAtomic.h>
  17. #include <cstdlib>
  18. #include <unistd.h>
  19. #include <wchar.h>
  20. #include <math.h>
  21. #include <stdarg.h>
  22. #include <string.h>
  23. #include <pthread.h>
  24. #include <wctype.h>
  25. #include <stddef.h>
  26. //#define offsetof(type, member) __builtin_offsetof (type, member)
  27. extern "C"
  28. {
  29. //#define FFI_BUILDING
  30. //#include "third_party/libffi/x86_64-apple-darwin12.5.0/include/ffi.h"
  31. }
  32. #define BF_ENDIAN_LITTLE
  33. #define _NOEXCEPT noexcept
  34. #define NTAPI
  35. //#define FFI_STDCALL FFI_DEFAULT_ABI
  36. //#define FFI_THISCALL FFI_DEFAULT_ABI
  37. //#define FFI_FASTCALL FFI_DEFAULT_ABI
  38. #define INVALID_SOCKET -1
  39. typedef uint64_t uint64;
  40. typedef uint32_t uint32;
  41. typedef uint16_t uint16;
  42. typedef uint8_t uint8;
  43. typedef int64_t int64;
  44. typedef int32_t int32;
  45. typedef int16_t int16;
  46. typedef int8_t int8;
  47. typedef unsigned int uint;
  48. //#define BF_PLATFORM_SDL
  49. #define NOP
  50. //#define BF_NOTHROW throw ()
  51. //#define BF_NOTHROW noexcept
  52. #define BF_NOTHROW
  53. #ifdef BF64
  54. typedef int64 intptr;
  55. typedef uint64 uintptr;
  56. #else
  57. typedef int32 intptr;
  58. typedef uint32 uintptr;
  59. #endif
  60. typedef wchar_t* BSTR;
  61. typedef int HRESULT;
  62. typedef uint8 BYTE;
  63. typedef uint16 WORD;
  64. typedef uint32 DWORD;
  65. typedef int32 LONG;
  66. typedef pthread_key_t BFTlsKey;
  67. typedef pthread_t BF_THREADID;
  68. typedef pthread_t BF_THREADHANDLE;
  69. #define BF_HAS_TLS_DECLSPEC
  70. #define BF_TLS_DECLSPEC thread_local
  71. //:int64 abs(int64 val);
  72. #define _stricmp stricmp
  73. #define strnicmp strncasecmp
  74. struct IID
  75. {
  76. unsigned long Data1;
  77. unsigned short Data2;
  78. unsigned short Data3;
  79. unsigned char Data4[ 8 ];
  80. };
  81. typedef void* HANDLE;
  82. typedef void* HMODULE;
  83. // We only need the stdcall attribute for x32?
  84. //#define BFSTDCALL __attribute__((stdcall))
  85. //#include "../notwin/NotWin.h"
  86. #ifdef DEBUG
  87. #define _DEBUG
  88. #endif
  89. #define NOT_IMPL throw "Unimplemented";
  90. //ARM
  91. #if defined(__x86_64__) || defined(__i386__)
  92. #define BF_FULL_MEMORY_FENCE() __asm__ __volatile__("mfence": : :"memory")
  93. #define BF_SPINWAIT_NOP() __asm__ volatile ("pause\n" : : : "memory" );
  94. #else
  95. #define BF_FULL_MEMORY_FENCE() __sync_synchronize()
  96. #define BF_SPINWAIT_NOP() ((void) 0)
  97. #endif
  98. #define BF_COMPILER_FENCE() __asm__ __volatile__("": : :"memory")
  99. #define BF_THREAD_YIELD() sched_yield()
  100. #if defined _DEBUG || defined BF_DEBUG_ASSERTS
  101. #define BF_ASSERT(_Expression) (void)( (!!(_Expression)) || (Beefy::BFFatalError(#_Expression, __FILE__, __LINE__), 0) )
  102. #else
  103. #define BF_ASSERT(_Expression) (void)(0)
  104. #endif
  105. #define BF_ASSERT_REL(_Expression) (void)( (!!(_Expression)) || (Beefy::BFFatalError(#_Expression, __FILE__, __LINE__), 0) )
  106. #define BF_FATAL(msg) (void) ((Beefy::BFFatalError(msg, __FILE__, __LINE__), 0) )
  107. #if defined _DEBUG || defined BF_DEBUG_ASSERTS
  108. #define BF_DBG_FATAL(msg) (void) ((Beefy::BFFatalError(msg, __FILE__, __LINE__), 0) )
  109. #else
  110. #define BF_DBG_FATAL(msg)
  111. #endif
  112. #define BF_NOINLINE __attribute__ ((noinline))
  113. #define BF_NAKED
  114. #define stricmp strcasecmp
  115. #define _alloca alloca
  116. #define DIR_SEP_CHAR '/'
  117. #define DIR_SEP_CHAR_ALT '\\'
  118. static char* itoa(int value, char* str, int base)
  119. {
  120. if (base == 16)
  121. sprintf(str, "%X", value);
  122. else
  123. sprintf(str, "%d", value);
  124. return str;
  125. }