forked from 0ad/0ad
wsdl: cleanup semaphore code, move mouse functions near other "misc" functions
wpthread: document problem encountered with CreateThread win_internal: minor cleanup This was SVN commit r2009.
This commit is contained in:
parent
df38ee95a8
commit
9a75e31bbd
@ -26,7 +26,7 @@
|
||||
|
||||
|
||||
// Win32 socket decls aren't portable (e.g. problems with socklen_t)
|
||||
// => skip winsock.h; wsock.h should be used instead
|
||||
// => skip winsock.h; wposix wsock.h should be used instead
|
||||
#define _WINSOCKAPI_
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
@ -42,45 +42,45 @@
|
||||
|
||||
|
||||
|
||||
#define NOGDICAPMASKS // CC_*, LC_*, PC_*, CP_*, TC_*, RC_
|
||||
#define NOGDICAPMASKS // CC_*, LC_*, PC_*, CP_*, TC_*, RC_
|
||||
//#define NOVIRTUALKEYCODES // VK_*
|
||||
//#define NOWINMESSAGES // WM_*, EM_*, LB_*, CB_*
|
||||
//#define NOWINSTYLES // WS_*, CS_*, ES_*, LBS_*, SBS_*, CBS_*
|
||||
#define NOSYSMETRICS // SM_*
|
||||
#define NOMENUS // MF_*
|
||||
#define NOICONS // IDI_*
|
||||
#define NOKEYSTATES // MK_*
|
||||
#define NOSYSMETRICS // SM_*
|
||||
#define NOMENUS // MF_*
|
||||
#define NOICONS // IDI_*
|
||||
#define NOKEYSTATES // MK_*
|
||||
//#define NOSYSCOMMANDS // SC_*
|
||||
#define NORASTEROPS // Binary and Tertiary raster ops
|
||||
#define NORASTEROPS // Binary and Tertiary raster ops
|
||||
//#define NOSHOWWINDOW // SW_*
|
||||
#define OEMRESOURCE // OEM Resource values
|
||||
#define NOATOM // Atom Manager routines
|
||||
#define OEMRESOURCE // OEM Resource values
|
||||
#define NOATOM // Atom Manager routines
|
||||
//#define NOCLIPBOARD // Clipboard routines
|
||||
#define NOCOLOR // Screen colors
|
||||
#define NOCOLOR // Screen colors
|
||||
//#define NOCTLMGR // Control and Dialog routines
|
||||
#define NODRAWTEXT // DrawText() and DT_*
|
||||
#define NODRAWTEXT // DrawText() and DT_*
|
||||
//#define NOGDI // All GDI defines and routines
|
||||
//#define NOKERNEL // All KERNEL defines and routines
|
||||
//#define NOUSER // All USER defines and routines
|
||||
#define NONLS // All NLS defines and routines
|
||||
#define NONLS // All NLS defines and routines
|
||||
//#define NOMB // MB_* and MessageBox()
|
||||
#define NOMEMMGR // GMEM_*, LMEM_*, GHND, LHND, associated routines
|
||||
#define NOMETAFILE // typedef METAFILEPICT
|
||||
#define NOMINMAX // Macros min(a,b) and max(a,b)
|
||||
#define NOMEMMGR // GMEM_*, LMEM_*, GHND, LHND, associated routines
|
||||
#define NOMETAFILE // typedef METAFILEPICT
|
||||
#define NOMINMAX // Macros min(a,b) and max(a,b)
|
||||
//#define NOMSG // typedef MSG and associated routines
|
||||
#define NOOPENFILE // OpenFile(), OemToAnsi, AnsiToOem, and OF_*
|
||||
#define NOSCROLL // SB_* and scrolling routines
|
||||
#define NOSERVICE // All Service Controller routines, SERVICE_ equates, etc.
|
||||
#define NOOPENFILE // OpenFile(), OemToAnsi, AnsiToOem, and OF_*
|
||||
#define NOSCROLL // SB_* and scrolling routines
|
||||
#define NOSERVICE // All Service Controller routines, SERVICE_ equates, etc.
|
||||
//#define NOSOUND // Sound driver routines
|
||||
#define NOTEXTMETRIC // typedef TEXTMETRIC and associated routines
|
||||
#define NOTEXTMETRIC // typedef TEXTMETRIC and associated routines
|
||||
//#define NOWH // SetWindowsHook and WH_*
|
||||
#define NOWINOFFSETS // GWL_*, GCL_*, associated routines
|
||||
#define NOWINOFFSETS // GWL_*, GCL_*, associated routines
|
||||
//#define NOCOMM // COMM driver routines
|
||||
#define NOKANJI // Kanji support stuff.
|
||||
#define NOHELP // Help engine interface.
|
||||
#define NOPROFILER // Profiler interface.
|
||||
#define NODEFERWINDOWPOS // DeferWindowPos routines
|
||||
#define NOMCX // Modem Configuration Extensions
|
||||
#define NOKANJI // Kanji support stuff.
|
||||
#define NOHELP // Help engine interface.
|
||||
#define NOPROFILER // Profiler interface.
|
||||
#define NODEFERWINDOWPOS // DeferWindowPos routines
|
||||
#define NOMCX // Modem Configuration Extensions
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
@ -113,16 +113,16 @@ typedef DWORD ULONG_PTR;
|
||||
|
||||
typedef struct _MEMORYSTATUSEX
|
||||
{
|
||||
DWORD dwLength;
|
||||
DWORD dwMemoryLoad;
|
||||
DWORDLONG ullTotalPhys;
|
||||
DWORDLONG ullAvailPhys;
|
||||
DWORDLONG ullTotalPageFile;
|
||||
DWORDLONG ullAvailPageFile;
|
||||
DWORDLONG ullTotalVirtual;
|
||||
DWORDLONG ullAvailVirtual;
|
||||
DWORDLONG ullAvailExtendedVirtual;
|
||||
} MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
|
||||
DWORD dwLength;
|
||||
DWORD dwMemoryLoad;
|
||||
DWORDLONG ullTotalPhys;
|
||||
DWORDLONG ullAvailPhys;
|
||||
DWORDLONG ullTotalPageFile;
|
||||
DWORDLONG ullAvailPageFile;
|
||||
DWORDLONG ullTotalVirtual;
|
||||
DWORDLONG ullAvailVirtual;
|
||||
DWORDLONG ullAvailExtendedVirtual;
|
||||
} MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
|
||||
|
||||
#endif // #if WINVER < 0x500
|
||||
|
||||
@ -133,7 +133,7 @@ typedef struct _MEMORYSTATUSEX
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// MinGW headers are already fixed; only change on VC
|
||||
// MinGW headers are already correct; only change on VC
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#ifndef NTSTATUS
|
||||
@ -283,10 +283,11 @@ typedef struct _PROCESSOR_POWER_INFORMATION
|
||||
# define __inout_bcount(s)
|
||||
# define __deref_opt_out
|
||||
# define __deref_out
|
||||
#endif
|
||||
|
||||
// missing from dbghelp's list
|
||||
#define __out_xcount(s)
|
||||
# define __out_xcount(s)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// not defined by dbghelp; these values are taken from DIA cvconst.h
|
||||
|
@ -110,8 +110,13 @@ int pthread_create(pthread_t* thread, const void* attr, void*(*func)(void*), voi
|
||||
{
|
||||
UNUSED(attr);
|
||||
|
||||
// note: don't stack-allocate param: thread_start might not be called
|
||||
// in the new thread before we exit this stack frame.
|
||||
// notes:
|
||||
// - don't stack-allocate param: thread_start might not be called
|
||||
// in the new thread before we exit this stack frame.
|
||||
// - _beginthreadex has more overhead and no value added vs. CreateThread,
|
||||
// but the following problem is documented: when using the
|
||||
// statically-linked CRT, ExitThread leaks memory when CreateThread is
|
||||
// used instead of _beginthread(..ex also?).
|
||||
ThreadParam* param = new ThreadParam(func, user_arg);
|
||||
*thread = (pthread_t)_beginthreadex(0, 0, thread_start, (void*)param, 0, 0);
|
||||
return 0;
|
||||
|
@ -927,60 +927,6 @@ inline void SDL_Delay(Uint32 ms)
|
||||
|
||||
|
||||
|
||||
void* SDL_GL_GetProcAddress(const char* name)
|
||||
{
|
||||
return wglGetProcAddress(name);
|
||||
}
|
||||
|
||||
|
||||
SDL_sem* SDL_CreateSemaphore(int cnt)
|
||||
{
|
||||
return (SDL_sem*)CreateSemaphore(0, cnt, 0x7fffffff, 0);
|
||||
}
|
||||
|
||||
inline void SDL_DestroySemaphore(SDL_sem* sem)
|
||||
{
|
||||
CloseHandle((HANDLE)sem);
|
||||
}
|
||||
|
||||
int SDL_SemPost(SDL_sem* sem)
|
||||
{
|
||||
return ReleaseSemaphore((HANDLE)sem, 1, 0);
|
||||
}
|
||||
|
||||
int SDL_SemWait(SDL_sem* sem)
|
||||
{
|
||||
return WaitForSingleObject(sem, INFINITE);
|
||||
}
|
||||
|
||||
// users don't need to allocate SDL_Thread variables, so type = void
|
||||
// API returns SDL_Thread*, which is the HANDLE value itself.
|
||||
union pthread_sdl
|
||||
{
|
||||
pthread_t p;
|
||||
SDL_Thread* s;
|
||||
};
|
||||
|
||||
SDL_Thread* SDL_CreateThread(int(*func)(void*), void* param)
|
||||
{
|
||||
pthread_sdl u;
|
||||
if(pthread_create(&u.p, 0, (void*(*)(void*))func, param) < 0)
|
||||
return 0;
|
||||
return u.s;
|
||||
}
|
||||
|
||||
|
||||
int SDL_KillThread(SDL_Thread* thread)
|
||||
{
|
||||
pthread_sdl u;
|
||||
u.s = thread;
|
||||
pthread_cancel(u.p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
inline int SDL_WarpMouse(int x, int y)
|
||||
{
|
||||
return SetCursorPos(x, y);
|
||||
@ -1006,6 +952,92 @@ int SDL_ShowCursor(int toggle)
|
||||
|
||||
|
||||
|
||||
void* SDL_GL_GetProcAddress(const char* name)
|
||||
{
|
||||
return wglGetProcAddress(name);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
//
|
||||
// semaphores
|
||||
//
|
||||
|
||||
// note: implementing these in terms of pthread sem_t doesn't help;
|
||||
// this wrapper is very close to the Win32 routines.
|
||||
|
||||
union HANDLE_sem
|
||||
{
|
||||
HANDLE h;
|
||||
SDL_sem* s;
|
||||
};
|
||||
|
||||
SDL_sem* SDL_CreateSemaphore(int cnt)
|
||||
{
|
||||
HANDLE_sem u;
|
||||
u.h = CreateSemaphore(0, cnt, 0x7fffffff, 0);
|
||||
return u.s;
|
||||
}
|
||||
|
||||
inline void SDL_DestroySemaphore(SDL_sem* sem)
|
||||
{
|
||||
HANDLE_sem u;
|
||||
u.s = sem;
|
||||
CloseHandle(u.h);
|
||||
}
|
||||
|
||||
int SDL_SemPost(SDL_sem* sem)
|
||||
{
|
||||
HANDLE_sem u;
|
||||
u.s = sem;
|
||||
return ReleaseSemaphore(u.h, 1, 0);
|
||||
}
|
||||
|
||||
int SDL_SemWait(SDL_sem* sem)
|
||||
{
|
||||
HANDLE_sem u;
|
||||
u.s = sem;
|
||||
return WaitForSingleObject(u.h, INFINITE);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// threads
|
||||
//
|
||||
|
||||
|
||||
// users don't need to allocate SDL_Thread variables, so type = void
|
||||
// API returns SDL_Thread*, which is the HANDLE value itself.
|
||||
union pthread_sdl
|
||||
{
|
||||
pthread_t p;
|
||||
SDL_Thread* s;
|
||||
};
|
||||
|
||||
SDL_Thread* SDL_CreateThread(int(*func)(void*), void* param)
|
||||
{
|
||||
pthread_sdl u;
|
||||
if(pthread_create(&u.p, 0, (void*(*)(void*))func, param) < 0)
|
||||
return 0;
|
||||
return u.s;
|
||||
}
|
||||
|
||||
int SDL_KillThread(SDL_Thread* thread)
|
||||
{
|
||||
pthread_sdl u;
|
||||
u.s = thread;
|
||||
pthread_cancel(u.p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user