mirror of
https://github.com/spiffcode/hostile-takeover.git
synced 2026-04-29 15:33:37 -06:00
Create main thread via host
Create the main thread via host rather than being a global variable in base; this way, no base threads are created before the host runs main() because that can cause issues on some platforms.
This commit is contained in:
parent
d34f08c6e5
commit
8f0e81a3f5
@ -3,14 +3,15 @@
|
||||
|
||||
namespace base {
|
||||
|
||||
Thread g_main_thread;
|
||||
pthread_key_t Thread::s_key_;
|
||||
|
||||
Thread::Thread(SocketServer *ss) : start_routine_(NULL), start_pv_(NULL),
|
||||
MessageQueue(ss) {
|
||||
if (&g_main_thread == this) {
|
||||
static bool s_first_thread;
|
||||
if (!s_first_thread) {
|
||||
pthread_key_create(&s_key_, NULL);
|
||||
pthread_setspecific(s_key_, this);
|
||||
s_first_thread = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -117,6 +117,7 @@ class CommandQueueViewer;
|
||||
#include "game/missionlist.h"
|
||||
#include "mpshared/netmessage.h"
|
||||
#include "game/dragrect.h"
|
||||
#include "base/thread.h"
|
||||
//#include "yajl/wrapper/jsontypes.h"
|
||||
|
||||
namespace wi {
|
||||
@ -8800,6 +8801,9 @@ void HostGetUserName(char *pszBuff, int cbMax) secHost;
|
||||
SoundDevice *HostOpenSoundDevice() secSoundDevice;
|
||||
bool HostSoundServiceProc() secSoundDevice;
|
||||
void HostSleep(dword ct) secHost;
|
||||
void HostSetGameThread(base::Thread *thread);
|
||||
base::Thread& HostGetGameThread();
|
||||
base::Thread *HostGetGameThreadPointer();
|
||||
|
||||
const int knKeyboardAskDefault = 0;
|
||||
const int knKeyboardAskURL = 1;
|
||||
|
||||
@ -18,6 +18,7 @@ SdlPackFileReader gpakr;
|
||||
HttpPackManager *gppackm;
|
||||
HttpPackInfoManager *gppim;
|
||||
CompleteManager *gpcptm;
|
||||
base::Thread *gpgt;
|
||||
|
||||
char *gpszUdid;
|
||||
|
||||
@ -511,4 +512,16 @@ bool HostEnumAddonFiles(Enum *penm, char *pszAddonDir, int cbDir,
|
||||
return false;
|
||||
}
|
||||
|
||||
void HostSetGameThread(base::Thread *thread) {
|
||||
gpgt = thread;
|
||||
}
|
||||
|
||||
base::Thread& HostGetGameThread() {
|
||||
return *gpgt;
|
||||
}
|
||||
|
||||
base::Thread *HostGetGameThreadPointer() {
|
||||
return gpgt;
|
||||
}
|
||||
|
||||
} // namespace wi
|
||||
|
||||
@ -22,11 +22,18 @@ static void quit(int rc)
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
|
||||
int SDL_main(int argc, char *argv[])
|
||||
{
|
||||
// Create the main thread
|
||||
base::Thread *main_thread = new base::Thread();
|
||||
|
||||
// Set up the main thread as the SDL event thread.
|
||||
base::Thread::current().set_ss(new wi::SdlEventServer());
|
||||
|
||||
// Let the host have a pointer to the thread
|
||||
wi::HostSetGameThread(main_thread);
|
||||
|
||||
// TODO(darrinm): pass args through
|
||||
wi::GameMain((char *)"");
|
||||
return 0;
|
||||
|
||||
@ -16,6 +16,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Main server thread
|
||||
base::Thread main_thread;
|
||||
|
||||
// These are defaults that can be overridden
|
||||
const dword kcRoomsMax = 200;
|
||||
const dword kcGamesPerRoomMax = 100;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user