foxygit / doom Log in
commit 6e2c404f64f39e059848bc66b707dfe979f044ff
Merge: 20cb0007 535c64b3
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Thu Mar 12 22:20:07 2009 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Thu Mar 12 22:20:07 2009 +0000

    Update from trunk.

    Subversion-branch: /branches/raven-branch
    Subversion-revision: 1467

 src/i_main.c                   |   93 ++-
 src/w_file_win32.c             |    6 +
 textscreen/Doxyfile            | 1366 ++++++++++++++++++++++++++++++++++++++++
 textscreen/Makefile.am         |    3 +
 textscreen/txt_button.h        |   41 +-
 textscreen/txt_checkbox.h      |   41 ++
 textscreen/txt_desktop.h       |   37 +-
 textscreen/txt_dropdown.h      |   30 +
 textscreen/txt_inputbox.h      |   38 ++
 textscreen/txt_label.h         |   43 ++
 textscreen/txt_radiobutton.h   |   43 ++
 textscreen/txt_scrollpane.c    |    8 +-
 textscreen/txt_scrollpane.h    |   24 +
 textscreen/txt_separator.h     |   23 +
 textscreen/txt_spinctrl.h      |   36 ++
 textscreen/txt_strut.h         |   26 +-
 textscreen/txt_table.h         |  124 +++-
 textscreen/txt_widget.h        |   55 +-
 textscreen/txt_window.h        |  101 ++-
 textscreen/txt_window_action.h |   50 +-
 20 files changed, 2134 insertions(+), 54 deletions(-)

diff --cc src/i_main.c
index d7cdcef6,7c5b16e7..a0b0bfd5
--- a/src/i_main.c
+++ b/src/i_main.c
@@@ -24,7 -24,7 +24,6 @@@
  //
  //-----------------------------------------------------------------------------

--
  #include "config.h"

  #include "SDL.h"
@@@ -41,55 -41,81 +40,87 @@@
  #include <sched.h>
  #endif

 -#include "doomdef.h"
 +#include "doomtype.h"
  #include "i_system.h"
  #include "m_argv.h"
 -#include "d_main.h"
 +
 +//
 +// D_DoomMain()
 +// Not a globally visible function, just included for source reference,
 +// calls all startup code, parses command line options.
 +//
 +
 +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