129 lines
2.5 KiB
C++
129 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include <queue>
|
|
|
|
#ifdef _WIN32
|
|
#define VC_EXTRALEAN
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <Windows.h>
|
|
#include <winsock2.h>
|
|
#include <ws2tcpip.h>
|
|
|
|
#define THREADCALL WINAPI
|
|
#define STRCASECMP _stricmp
|
|
|
|
#define I64FMT "%016I64X"
|
|
#define I64FMTD "%I64u"
|
|
#define SI64FMTD "%I64d"
|
|
#else
|
|
// Linux includes
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
#include <dirent.h>
|
|
|
|
#define THREADCALL
|
|
#define STRCASECMP strcasecmp
|
|
#define Sleep(ms) usleep((ms) * 1000)
|
|
#define CreateDirectory(path, attr) mkdir(path, 0755)
|
|
#define _snprintf snprintf
|
|
|
|
#define I64FMT "%016lX"
|
|
#define I64FMTD "%lu"
|
|
#define SI64FMTD "%ld"
|
|
|
|
// Windows types for Linux
|
|
typedef int BOOL;
|
|
typedef unsigned long DWORD;
|
|
#define TRUE 1
|
|
#define FALSE 0
|
|
#endif
|
|
|
|
#if defined(_DEBUG) || defined(DEBUG)
|
|
# include <cassert>
|
|
# include "DebugUtils.h"
|
|
|
|
# define ASSERT assert
|
|
# define TRACE FormattedDebugString
|
|
|
|
// Enables tracing to stdout.
|
|
// Preferable with the VS debugger (is thrown in the "output" window), but
|
|
// it can be spammy otherwise (especially if you don't need it enabled).
|
|
# define USE_SQL_TRACE
|
|
|
|
// Ensure both typically used debug defines behave as intended
|
|
# ifndef DEBUG
|
|
# define DEBUG
|
|
# endif
|
|
|
|
# ifndef _DEBUG
|
|
# define _DEBUG
|
|
# endif
|
|
|
|
#else
|
|
# define ASSERT
|
|
# define TRACE
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
// Ignore the warning "nonstandard extension used: enum '<enum name>' used in qualified name"
|
|
// Sometimes it's necessary to avoid collisions, but aside from that, specifying the enumeration helps make code intent clearer.
|
|
#pragma warning(disable: 4482)
|
|
#endif
|
|
|
|
#define STR(str) #str
|
|
#define STRINGIFY(str) STR(str)
|
|
|
|
#include <thread>
|
|
#include <chrono>
|
|
#include <atomic>
|
|
#include <mutex>
|
|
|
|
class Guard
|
|
{
|
|
public:
|
|
Guard(std::recursive_mutex& mutex) : target(mutex) { target.lock(); }
|
|
Guard(std::recursive_mutex* mutex) : target(*mutex) { target.lock(); }
|
|
~Guard() { target.unlock(); }
|
|
|
|
protected:
|
|
std::recursive_mutex& target;
|
|
};
|
|
|
|
#ifdef _WIN32
|
|
#define sleep(ms) Sleep(ms)
|
|
#else
|
|
#define sleep(ms) usleep((ms) * 1000)
|
|
#endif
|
|
|
|
#ifdef min
|
|
#undef min
|
|
#endif
|
|
|
|
#ifdef max
|
|
#undef max
|
|
#endif
|
|
|
|
// define compiler-specific types
|
|
#include "types.h"
|
|
|
|
#include <random>
|
|
#include <memory>
|
|
#include <map>
|
|
#include <list>
|
|
#include <vector>
|
|
|
|
#include "tstring.h"
|
|
#include "globals.h"
|
|
#include "Atomic.h"
|
|
#include "Thread.h"
|
|
#include "Network.h"
|
|
#include "TimeThread.h"
|