diff options
author | Simon Howard | 2009-03-12 22:20:07 +0000 |
---|---|---|
committer | Simon Howard | 2009-03-12 22:20:07 +0000 |
commit | 6e2c404f64f39e059848bc66b707dfe979f044ff (patch) | |
tree | cd0aba502696ceef12bd311d4576fd46c4dd5c02 /src | |
parent | 20cb00076d39bcb8a5c2e82912af8200c97034cb (diff) | |
parent | 535c64b336ce59b4e18819544cd2a1129ae97c61 (diff) | |
download | chocolate-doom-6e2c404f64f39e059848bc66b707dfe979f044ff.tar.gz chocolate-doom-6e2c404f64f39e059848bc66b707dfe979f044ff.tar.bz2 chocolate-doom-6e2c404f64f39e059848bc66b707dfe979f044ff.zip |
Update from trunk.
Subversion-branch: /branches/raven-branch
Subversion-revision: 1467
Diffstat (limited to 'src')
-rw-r--r-- | src/i_main.c | 93 | ||||
-rw-r--r-- | src/w_file_win32.c | 6 |
2 files changed, 74 insertions, 25 deletions
diff --git a/src/i_main.c b/src/i_main.c index d7cdcef6..a0b0bfd5 100644 --- a/src/i_main.c +++ b/src/i_main.c @@ -24,7 +24,6 @@ // //----------------------------------------------------------------------------- - #include "config.h" #include "SDL.h" @@ -53,46 +52,90 @@ void D_DoomMain (void); -#if !defined(_WIN32) && !defined(HAVE_SCHED_SETAFFINITY) -#warning No known way to set processor affinity on this platform. -#warning You may experience crashes due to SDL_mixer. -#endif +#if defined(_WIN32) -int main(int argc, char **argv) -{ - // save arguments +typedef BOOL WINAPI (*SetAffinityFunc)(HANDLE hProcess, DWORD_PTR mask); - myargc = argc; - myargv = argv; +// This is a bit more complicated than it really needs to be. We really +// just need to call the SetProcessAffinityMask function, but that +// function doesn't exist on systems before Windows 2000. Instead, +// dynamically look up the function and call the pointer to it. This +// way, the program will run on older versions of Windows (Win9x, etc.) -#ifdef _WIN32 +static void LockCPUAffinity(void) +{ + HMODULE kernel32_dll; + SetAffinityFunc SetAffinity; + + // Find the kernel interface DLL. - // Set the process affinity mask so that all threads - // run on the same processor. This is a workaround for a bug in - // SDL_mixer that causes occasional crashes. + kernel32_dll = LoadLibrary("kernel32.dll"); - if (!SetProcessAffinityMask(GetCurrentProcess(), 1)) + if (kernel32_dll == NULL) { - fprintf(stderr, "Failed to set process affinity mask (%d)\n", - (int) GetLastError()); + // This should never happen... + + fprintf(stderr, "Failed to load kernel32.dll\n"); + return; } -#endif + // Find the SetProcessAffinityMask function. -#ifdef HAVE_SCHED_SETAFFINITY + SetAffinity = GetProcAddress(kernel32_dll, "SetProcessAffinityMask"); - // Linux version: + // If the function was not found, we are on an old (Win9x) system + // that doesn't have this function. That's no problem, because + // those systems don't support SMP anyway. + if (SetAffinity != NULL) { - cpu_set_t set; + if (!SetAffinity(GetCurrentProcess(), 1)) + { + fprintf(stderr, "Failed to set process affinity (%d)\n", + (int) GetLastError()); + } + } +} - CPU_ZERO(&set); - CPU_SET(0, &set); +#elif defined(HAVE_SCHED_SETAFFINITY) - sched_setaffinity(getpid(), sizeof(set), &set); - } +// Unix (Linux) version: + +static void LockCPUAffinity(void) +{ + cpu_set_t set; + + CPU_ZERO(&set); + CPU_SET(0, &set); + + sched_setaffinity(getpid(), sizeof(set), &set); +} + +#else + +#warning No known way to set processor affinity on this platform. +#warning You may experience crashes due to SDL_mixer. + +static void LockCPUAffinity(void) +{ + fprintf(stderr, + "WARNING: No known way to set processor affinity on this platform.\n" + " You may experience crashes due to SDL_mixer.\n"); +} #endif +int main(int argc, char **argv) +{ + // save arguments + + myargc = argc; + myargv = argv; + + // Only schedule on a single core, if we have multiple + // cores. This is to work around a bug in SDL_mixer. + + LockCPUAffinity(); + // start doom D_DoomMain (); diff --git a/src/w_file_win32.c b/src/w_file_win32.c index 05d3c445..d5e60579 100644 --- a/src/w_file_win32.c +++ b/src/w_file_win32.c @@ -35,6 +35,12 @@ #include "w_file.h" #include "z_zone.h" +// This constant doesn't exist in VC6: + +#ifndef INVALID_SET_FILE_POINTER +#define INVALID_SET_FILE_POINTER 0xffffffff +#endif + typedef struct { wad_file_t wad; |