mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 00:33:09 +00:00
reduce platform.h
This commit is contained in:
parent
30d4b78096
commit
a0ef833174
1 changed files with 1 additions and 61 deletions
|
@ -20,27 +20,7 @@
|
|||
#ifndef PLATFORM_H_INCLUDED
|
||||
#define PLATFORM_H_INCLUDED
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
// Disable some silly and noisy warnings from MSVC compiler
|
||||
#pragma warning(disable: 4127) // Conditional expression is constant
|
||||
#pragma warning(disable: 4146) // Unary minus operator applied to unsigned type
|
||||
#pragma warning(disable: 4800) // Forcing value to bool 'true' or 'false'
|
||||
#pragma warning(disable: 4996) // Function _ftime() may be unsafe
|
||||
|
||||
// MSVC does not support <inttypes.h>
|
||||
typedef signed __int8 int8_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef signed __int16 int16_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef signed __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef signed __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
#else
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32 // Linux - Unix
|
||||
|
||||
|
@ -71,46 +51,6 @@ typedef void*(*pt_start_fn)(void*);
|
|||
# define thread_join(x) pthread_join(x, NULL)
|
||||
|
||||
#else // Windows and MinGW
|
||||
|
||||
# include <sys/timeb.h>
|
||||
|
||||
inline int64_t system_time_to_msec() {
|
||||
_timeb t;
|
||||
_ftime(&t);
|
||||
return t.time * 1000LL + t.millitm;
|
||||
}
|
||||
|
||||
#ifndef NOMINMAX
|
||||
# define NOMINMAX // disable macros min() and max()
|
||||
#endif
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#undef WIN32_LEAN_AND_MEAN
|
||||
#undef NOMINMAX
|
||||
|
||||
// We use critical sections on Windows to support Windows XP and older versions.
|
||||
// Unfortunately, cond_wait() is racy between lock_release() and WaitForSingleObject()
|
||||
// but apart from this they have the same speed performance of SRW locks.
|
||||
typedef CRITICAL_SECTION Lock;
|
||||
typedef HANDLE WaitCondition;
|
||||
typedef HANDLE NativeHandle;
|
||||
|
||||
// On Windows 95 and 98 parameter lpThreadId may not be null
|
||||
inline DWORD* dwWin9xKludge() { static DWORD dw; return &dw; }
|
||||
|
||||
# define lock_init(x) InitializeCriticalSection(&(x))
|
||||
# define lock_grab(x) EnterCriticalSection(&(x))
|
||||
# define lock_release(x) LeaveCriticalSection(&(x))
|
||||
# define lock_destroy(x) DeleteCriticalSection(&(x))
|
||||
# define cond_init(x) { x = CreateEvent(0, FALSE, FALSE, 0); }
|
||||
# define cond_destroy(x) CloseHandle(x)
|
||||
# define cond_signal(x) SetEvent(x)
|
||||
# define cond_wait(x,y) { lock_release(y); WaitForSingleObject(x, INFINITE); lock_grab(y); }
|
||||
# define cond_timedwait(x,y,z) { lock_release(y); WaitForSingleObject(x,z); lock_grab(y); }
|
||||
# define thread_create(x,f,t) (x = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)f,t,0,dwWin9xKludge()))
|
||||
# define thread_join(x) { WaitForSingleObject(x, INFINITE); CloseHandle(x); }
|
||||
|
||||
#endif
|
||||
|
||||
#endif // #ifndef PLATFORM_H_INCLUDED
|
||||
|
|
Loading…
Add table
Reference in a new issue