1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
/* -*- mode: C++; tab-width: 4 -*- */
/* ================================================================================== */
/* Copyright (c) 1998-1999 3Com Corporation or its subsidiaries. All rights reserved. */
/* ================================================================================== */
#include "EmulatorCommon.h"
#include "fltk_main.h"
#include "Platform.h" // gPseudoTickcount
#include "EmRPC.h" // SignalWaiters
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include "fltk_MainWindow.h"
#include "Miscellaneous.h" // CommonStartup, CommonShutdown
#include "PreferenceMgr.h"
#include "Startup.h" // Startup::
#ifdef __QNXNTO__
#include <sys/neutrino.h>
#endif
// -----------------------------------------------------------------------------
// execute the given FN within the context of the UI thread. This function
// (fltkExecuteUI) will be called from a non-UI thread. Currently there is
// only support for ONE pending function
static void (*sUIFunc)(void);
static omni_mutex sUIFuncMutex;
static omni_thread* sMainThread;
void fltkExecuteUI (void (*fn) (void))
{
sUIFuncMutex.lock();
sUIFunc = fn;
sUIFuncMutex.unlock();
}
bool currentlyUIThread()
{
return omni_thread::self() == sMainThread;
}
int main(int argc, char** argv)
{
// hold onto the main thread
sMainThread = omni_thread::self();
#ifdef __QNXNTO__
// speed NTO up so the timing will be about right (for an x86 anyway)
struct _clockperiod cpnew;
struct _clockperiod old;
cpnew.nsec = 5000000;
cpnew.fract = 0;
ClockPeriod(CLOCK_REALTIME, &cpnew, &old, 0);
// printf ("%d %d %d\n", old.nsec, old.fract);
#endif
EmulatorPreferences prefs;
prefs.Load ();
::CommonStartup ();
Bool result = Startup::DetermineStartupActions (argc, argv);
if (result)
{
MainWindow* mainWin = new MainWindow;
Fl::visual (FL_DOUBLE|FL_RGB);
mainWin->show (argc, argv);
while ( Fl::wait() )
{
// !!! Still need to idle every once and a while
// when there's no document open in order to
// handle RPC requests.
gPseudoTickcount++;
sUIFuncMutex.lock();
if (sUIFunc != NULL)
{
sUIFunc();
sUIFunc = NULL;
}
sUIFuncMutex.unlock();
}
}
RPC::SignalWaiters (hostSignalQuit);
::CommonShutdown ();
prefs.Save ();
return 0;
}
|