diff --git a/base/basictypes.h b/base/basictypes.h index 421d69aa88..e0bb39e3a7 100644 --- a/base/basictypes.h +++ b/base/basictypes.h @@ -87,4 +87,7 @@ inline uint64 swap64(const uint8* _pData) {return swap64(*(const uint64*)_pData) #define __THREAD __thread #endif +// For really basic windows code compat +typedef char TCHAR; + #endif // _BASE_BASICTYPES diff --git a/base/display.cpp b/base/display.cpp index 0955677943..bc0b73ef56 100644 --- a/base/display.cpp +++ b/base/display.cpp @@ -2,6 +2,7 @@ int dp_xres; int dp_yres; + int pixel_xres; int pixel_yres; diff --git a/base/logging.h b/base/logging.h index 435e72a8a5..915a52163b 100644 --- a/base/logging.h +++ b/base/logging.h @@ -12,11 +12,18 @@ // Logging #ifdef _WIN32 +#undef Crash + +#ifdef _M_X64 +inline void Crash() { DebugBreak(); } +#else inline void Crash() { __asm { int 3 }; } +#endif #else #ifdef ANDROID +#undef Crash inline void Crash() { char *p = (char *)1337; diff --git a/base/mutex.h b/base/mutex.h index ebceda318b..d4f7d9b9da 100644 --- a/base/mutex.h +++ b/base/mutex.h @@ -6,6 +6,17 @@ #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include + +// Zap stupid windows defines +// Should move these somewhere clever. +#undef p +#undef MIN +#undef MAX +#undef min +#undef max +#undef DrawText +#undef itoa + #else #include #include @@ -57,6 +68,10 @@ public: #endif } + mutexType &native_handle() { + return mut_; + } + private: mutexType mut_; DISALLOW_COPY_AND_ASSIGN(recursive_mutex); @@ -71,10 +86,55 @@ private: recursive_mutex &mtx_; }; -#undef p -#undef MIN -#undef MAX -#undef min -#undef max -#undef DrawText -#undef itoa \ No newline at end of file + +// Like a Windows event, or a modern condition variable. + +class event { +public: +#ifdef _WIN32 +#else +#endif + event() { +#ifdef _WIN32 + event_ = CreateEvent(0, FALSE, FALSE, 0); +#else + pthread_cond_init(&event_, NULL); +#endif + } + ~event() { +#ifdef _WIN32 + CloseHandle(event_); +#else + pthread_cond_destroy(&event_); +#endif + } + + void notify_one() { +#ifdef _WIN32 + SetEvent(event_); +#else + pthread_cond_signal(&event_); +#endif + } + + // notify_all is not really possible to implement with win32 events? + + void wait(recursive_mutex &mtx) { + // broken +#ifdef _WIN32 + //mtx.unlock(); + WaitForSingleObject(event_, INFINITE); + ResetEvent(event_); // necessary? + // mtx.lock(); +#else + pthread_cond_wait(&event_, &mtx.native_handle()); +#endif + } + +private: +#ifdef _WIN32 + HANDLE event_; +#else + pthread_cond_t event_; +#endif +}; \ No newline at end of file diff --git a/base/threadutil.h b/base/threadutil.h index 15e6a477d1..fe8d9bac00 100644 --- a/base/threadutil.h +++ b/base/threadutil.h @@ -1,3 +1,38 @@ #pragma once -void setCurrentThreadName(const char *name); \ No newline at end of file +#include + +#ifdef _WIN32 +#include +#else + +#include + +#ifndef _POSIX_THREADS +#error unsupported platform (no pthreads?) +#endif + +#include + +#endif + +void setCurrentThreadName(const char *name); + +/* +class thread { +private: +#ifdef _WIN32 + typedef HANDLE thread_; +#else + typedef pthread_t thread_; +#endif + +public: + //void run(std::function threadFunc) { + // func_ = + //} + + void wait() { + + } +};*/ \ No newline at end of file diff --git a/net/resolve.cpp b/net/resolve.cpp index 9d56f38e54..725173dc4e 100644 --- a/net/resolve.cpp +++ b/net/resolve.cpp @@ -1,4 +1,4 @@ -#include "net/resolve.h" + #include "net/resolve.h" #include #include @@ -8,9 +8,12 @@ #ifndef _WIN32 #include #include // gethostbyname +#include #else #include #include +#undef min +#undef max #endif