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 //-----------------------------------------------------------------------------
37 #if defined(_WIN32_WCE)
39 // Windows CE? I doubt it even supports SMP..
41 static void LockCPUAffinity(void)
47 #define WIN32_LEAN_AND_MEAN
50 typedef BOOL
WINAPI (*SetAffinityFunc
)(HANDLE hProcess
, DWORD_PTR mask
);
52 // This is a bit more complicated than it really needs to be. We really
53 // just need to call the SetProcessAffinityMask function, but that
54 // function doesn't exist on systems before Windows 2000. Instead,
55 // dynamically look up the function and call the pointer to it. This
56 // way, the program will run on older versions of Windows (Win9x, etc.)
58 static void LockCPUAffinity(void)
61 SetAffinityFunc SetAffinity
;
63 // Find the kernel interface DLL.
65 kernel32_dll
= LoadLibrary("kernel32.dll");
67 if (kernel32_dll
== NULL
)
69 // This should never happen...
71 fprintf(stderr
, "Failed to load kernel32.dll\n");
75 // Find the SetProcessAffinityMask function.
77 SetAffinity
= GetProcAddress(kernel32_dll
, "SetProcessAffinityMask");
79 // If the function was not found, we are on an old (Win9x) system
80 // that doesn't have this function. That's no problem, because
81 // those systems don't support SMP anyway.
83 if (SetAffinity
!= NULL
)
85 if (!SetAffinity(GetCurrentProcess(), 1))
87 fprintf(stderr
, "Failed to set process affinity (%d)\n",
88 (int) GetLastError());
93 #elif defined(HAVE_SCHED_SETAFFINITY)
98 // Unix (Linux) version:
100 static void LockCPUAffinity(void)
108 sched_setaffinity(getpid(), sizeof(set
), &set
);
110 unsigned long mask
= 1;
111 sched_setaffinity(getpid(), sizeof(mask
), &mask
);
117 #warning No known way to set processor affinity on this platform.
118 #warning You may experience crashes due to SDL_mixer.
120 static void LockCPUAffinity(void)
123 "WARNING: No known way to set processor affinity on this platform.\n"
124 " You may experience crashes due to SDL_mixer.\n");
129 int main(int argc
, char **argv
)
136 // Only schedule on a single core, if we have multiple
137 // cores. This is to work around a bug in SDL_mixer.