Revision: 2444
          http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2444&view=rev
Author:   rorthomas
Date:     2012-02-04 13:59:21 +0000 (Sat, 04 Feb 2012)
Log Message:
-----------
new sleep function

Modified Paths:
--------------
    trunk/source/main/framework/AppStateManager.cpp
    trunk/source/main/network/IRCWrapper.cpp
    trunk/source/main/network/network.cpp
    trunk/source/main/physics/BeamFactory.cpp
    trunk/source/main/utils/utils.cpp
    trunk/source/main/utils/utils.h

Modified: trunk/source/main/framework/AppStateManager.cpp
===================================================================
--- trunk/source/main/framework/AppStateManager.cpp     2012-02-04 13:58:18 UTC 
(rev 2443)
+++ trunk/source/main/framework/AppStateManager.cpp     2012-02-04 13:59:21 UTC 
(rev 2444)
@@ -8,6 +8,7 @@
 #include <OgreLogManager.h>
 
 #include "Settings.h"
+#include "utils.h"
 
 using namespace Ogre;
 
@@ -120,12 +121,8 @@
                // no more actual rendering?
                if(m_bNoRendering)
                {
-#ifdef WIN32
-                       Sleep(100);
-#else
-                       sleep(100);
+                       sleepMilliSeconds(100);
                        continue;
-#endif // WIN32
                }
 
                update(timeSinceLastFrame);
@@ -133,11 +130,7 @@
                if (maxFPS && timeSinceLastFrame < minTimePerFrame)
                {
                        // Sleep twice as long as we were too fast.
-#ifdef WIN32
-                       Sleep((minTimePerFrame - timeSinceLastFrame) << 1);
-#else
-                       sleep((minTimePerFrame - timeSinceLastFrame) << 1);
-#endif // WIN32
+                       sleepMilliSeconds((minTimePerFrame - 
timeSinceLastFrame) << 1);
                }
 
 

Modified: trunk/source/main/network/IRCWrapper.cpp
===================================================================
--- trunk/source/main/network/IRCWrapper.cpp    2012-02-04 13:58:18 UTC (rev 
2443)
+++ trunk/source/main/network/IRCWrapper.cpp    2012-02-04 13:59:21 UTC (rev 
2444)
@@ -37,6 +37,7 @@
 #include "Settings.h"
 #include "errorutils.h"
 #include "ImprovedConfigFile.h"
+#include "utils.h"
 #include "RoRVersion.h"
 
 using namespace std; // primary for string
@@ -589,21 +590,16 @@
        if(eventNum == 433)
        {
                // 433 = uername already used, try to take another one
-#ifdef WIN32
-               Sleep(500);
-#else
-               sleep(500);
-#endif // WIN32                irc_ctx_t * ctx = (irc_ctx_t *) irc_get_ctx 
(session);
+               sleepMilliSeconds(500);
+
+
+               //irc_ctx_t * ctx = (irc_ctx_t *) irc_get_ctx (session);
                //ctx->retryCounter++;
                ctx->nick += "_";
 
                // now change the nick
                irc_cmd_nick(session, ctx->nick.c_str());
-#ifdef WIN32
-               Sleep(500);
-#else
-               sleep(500);
-#endif // WIN32
+               sleepMilliSeconds(500);
 
                // and rejoin the channels
                irc_cmd_join (session, ctx->channel.c_str(), 0);
@@ -728,11 +724,7 @@
        {
                // sleep longer the more often we try to connect - security 
measure
                // gives the old connection the chance to time-out
-#ifdef WIN32
-               Sleep(2000*ctx->retryCounter);
-#else
-               sleep(2000*ctx->retryCounter);
-#endif // WIN32
+               sleepMilliSeconds(2000*ctx->retryCounter);
        }
 
        irc_set_ctx (ctx->irc_session, ctx);

Modified: trunk/source/main/network/network.cpp
===================================================================
--- trunk/source/main/network/network.cpp       2012-02-04 13:58:18 UTC (rev 
2443)
+++ trunk/source/main/network/network.cpp       2012-02-04 13:59:21 UTC (rev 
2444)
@@ -508,11 +508,7 @@
        // otherwise you can get runtime conditions
        while(!BeamFactory::getSingletonPtr())
        {
-#ifndef WIN32
-                       sleep(1);
-#else
-                       Sleep(1000);
-#endif
+               sleepMilliSeconds(1000);
        };
 
 

Modified: trunk/source/main/physics/BeamFactory.cpp
===================================================================
--- trunk/source/main/physics/BeamFactory.cpp   2012-02-04 13:58:18 UTC (rev 
2443)
+++ trunk/source/main/physics/BeamFactory.cpp   2012-02-04 13:59:21 UTC (rev 
2444)
@@ -80,9 +80,14 @@
                tdr = new TwoDReplay();
 
 
-       // TEST for Beamworker, add two instances
-       //new BeamWorker();
-       //new BeamWorker();
+       // TEST for Beamworker, add example instances
+       /*
+               for(int i=0; i < 60; i++)
+               {
+                       new BeamWorker();
+               //new BeamWorker();
+               }
+       */
 }
 
 BeamFactory::~BeamFactory()
@@ -828,4 +833,4 @@
        ffhydro=affhydro/steps;
        if (free_hydro) ffhydro=ffhydro/free_hydro;
 }
-#endif // 0
\ No newline at end of file
+#endif // 0

Modified: trunk/source/main/utils/utils.cpp
===================================================================
--- trunk/source/main/utils/utils.cpp   2012-02-04 13:58:18 UTC (rev 2443)
+++ trunk/source/main/utils/utils.cpp   2012-02-04 13:59:21 UTC (rev 2444)
@@ -328,3 +328,30 @@
        if(left)
                str.erase(0, str.find_first_not_of(delims)); // trim left
 }
+
+pthread_key_t ThreadID::key;
+pthread_once_t ThreadID::key_once = PTHREAD_ONCE_INIT;
+unsigned int ThreadID::tuid = 1;
+
+unsigned int ThreadID::getID()
+{
+        ThreadID *ptr = NULL;
+        pthread_once(&key_once, ThreadID::make_key);
+        ptr = (ThreadID*)pthread_getspecific(key);
+
+        if( !ptr ) {
+                ptr = new ThreadID();
+                pthread_setspecific(key, (void*)ptr);
+        }
+
+        return ptr->thread_id;
+}
+
+ThreadID::ThreadID() : thread_id( tuid )
+{
+       tuid++;
+}
+void ThreadID::make_key()
+{
+       pthread_key_create(&key, NULL);
+}

Modified: trunk/source/main/utils/utils.h
===================================================================
--- trunk/source/main/utils/utils.h     2012-02-04 13:58:18 UTC (rev 2443)
+++ trunk/source/main/utils/utils.h     2012-02-04 13:59:21 UTC (rev 2444)
@@ -101,4 +101,31 @@
        }
 }
 
+inline void sleepMilliSeconds(unsigned int ms)
+{
+#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
+       // accepts milliseconds
+       Sleep(ms);
+#else
+       // accepts microseconds
+       usleep(ms * 1000);
+#endif
+}
+
+class ThreadID
+{
+
+public:
+        static unsigned int getID();
+
+private:
+        ThreadID();
+        static void make_key();
+
+        unsigned int thread_id;
+        static pthread_key_t key;
+        static pthread_once_t key_once;
+        static unsigned int tuid;
+};
+
 #endif //UTILS_H_

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Rigsofrods-devel mailing list
Rigsofrods-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel

Reply via email to