1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
4 // Copyright(C) 1993-1996 Id Software, Inc.
5 // Copyright(C) 2005 Simon Howard
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 // Main program, simply calls D_DoomMain high level loop.
25 //-----------------------------------------------------------------------------
35 #define WIN32_LEAN_AND_MEAN
39 #ifdef HAVE_SCHED_SETAFFINITY
51 typedef BOOL
WINAPI (*SetAffinityFunc
)(HANDLE hProcess
, DWORD_PTR mask
);
53 // This is a bit more complicated than it really needs to be. We really
54 // just need to call the SetProcessAffinityMask function, but that
55 // function doesn't exist on systems before Windows 2000. Instead,
56 // dynamically look up the function and call the pointer to it. This
57 // way, the program will run on older versions of Windows (Win9x, etc.)
59 static void LockCPUAffinity(void)
62 SetAffinityFunc SetAffinity
;
64 // Find the kernel interface DLL.
66 kernel32_dll
= LoadLibrary("kernel32.dll");
68 if (kernel32_dll
== NULL
)
70 // This should never happen...
72 fprintf(stderr
, "Failed to load kernel32.dll\n");
76 // Find the SetProcessAffinityMask function.
78 SetAffinity
= GetProcAddress(kernel32_dll
, "SetProcessAffinityMask");
80 // If the function was not found, we are on an old (Win9x) system
81 // that doesn't have this function. That's no problem, because
82 // those systems don't support SMP anyway.
84 if (SetAffinity
!= NULL
)
86 if (!SetAffinity(GetCurrentProcess(), 1))
88 fprintf(stderr
, "Failed to set process affinity (%d)\n",
89 (int) GetLastError());
94 #elif defined(HAVE_SCHED_SETAFFINITY)
96 // Unix (Linux) version:
98 static void LockCPUAffinity(void)
105 sched_setaffinity(getpid(), sizeof(set
), &set
);
110 #warning No known way to set processor affinity on this platform.
111 #warning You may experience crashes due to SDL_mixer.
113 static void LockCPUAffinity(void)
116 "WARNING: No known way to set processor affinity on this platform.\n"
117 " You may experience crashes due to SDL_mixer.\n");
122 int main(int argc
, char **argv
)
129 // Only schedule on a single core, if we have multiple
130 // cores. This is to work around a bug in SDL_mixer.