]> git.tdb.fi Git - libs/core.git/blobdiff - source/application.cpp
Native threads for Win32
[libs/core.git] / source / application.cpp
index 22c8d2688310685fb2aaeb4e30857256bcc7c062..a9aa88ea55bdee578d81238d614120a962be2173 100644 (file)
@@ -19,7 +19,9 @@ Poller::Slot &Application::add_pollable(Pollable *obj, short events)
        
        Poller::Slot &slot=poller_->add_pollable(obj, events);
        // Interrupt a possible poll in progress
-       pthread_kill(main_tid, SIGALRM);        
+#ifndef WIN32  //XXX
+       pthread_kill(main_tid, SIGALRM);
+#endif
        return slot;
 }
 
@@ -62,7 +64,9 @@ int Application::run(int argc, char **argv)
                return 126;
        }
 
+#ifndef WIN32 //XXX
        signal(SIGALRM, &sigalrm_);
+#endif
        
        try
        {
@@ -91,6 +95,17 @@ void Application::usage(const char *, bool)
        cerr<<"The programmer was lazy and didn't write a usage() function for this application.\n";
 }
 
+Application::Application():
+       exit_code(0),
+       tick_mode_(IDLE),
+       poller_(0),
+       ev_mgr_(0)
+#ifndef WIN32
+       //XXX Figure out how to get the current thread on win32
+       ,main_tid(pthread_self())
+#endif
+{ }
+
 /**
 Default main loop.  Calls tick() periodically if do_ticks is true, otherwise
 just sleeps.  A custom main loop should monitor the done member variable and
@@ -106,7 +121,11 @@ int Application::main()
                        if(poller_)
                                poller_->poll(0);
                        tick();
+#ifdef WIN32
+                       Sleep(0);
+#else
                        sched_yield();
+#endif
                }
                else
                {
@@ -140,7 +159,9 @@ void Application::catch_signal(int s)
 void Application::set_tick_mode(TickMode t)
 {
        tick_mode_=t;
+#ifndef WIN32 //XXX
        pthread_kill(main_tid, SIGALRM);        
+#endif
 }
 
 /**
@@ -150,7 +171,9 @@ void Application::exit(int c)
 {
        done=true;
        exit_code=c;
+#ifndef WIN32 //XXX
        pthread_kill(main_tid, SIGALRM);        
+#endif
 }
 
 void Application::sighandler_(int s)