Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 26, 2016, 8:32:16 PM (8 years ago)
Author:
muemart
Message:

Minor C++11 improvements:

  • Drop ImplicitConversion.h in favor of std::is_convertible.
  • Move constructor & assignment for MultiType and SubString. I'm not sure if the MultiType should convert types when moving. Currently it doesn't, because otherwise it would have no benefit over copying.
  • Use standard library functions for sleeping.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/util/Sleep.cc

    r8858 r11098  
    3030@file
    3131@brief
    32     Implementation of three sleep functions. Avoids including windows.h
     32    Implementation of three sleep functions.
    3333*/
    3434
    3535#include "Sleep.h"
    36 #include "Output.h"
    3736
    38 #ifdef ORXONOX_PLATFORM_WINDOWS
    39 #ifndef WIN32_LEAN_AND_MEAN
    40 #  define WIN32_LEAN_AND_MEAN
    41 #endif
    42 #include <windows.h>
    43 #undef min
    44 #undef max
     37#include <chrono>
     38#include <thread>
    4539
    4640namespace orxonox
     
    4842    void usleep(unsigned long microseconds)
    4943    {
    50         //if (microseconds < 1000)
    51         //    orxout(internal_warning) << "Windows cannot sleep less than 1ms, ignoring" << endl;
    52         Sleep(microseconds / 1000);
     44        std::this_thread::sleep_for(std::chrono::microseconds(microseconds));
    5345    }
    5446
    5547    void msleep(unsigned long milliseconds)
    5648    {
    57         Sleep(milliseconds);
     49        std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds));
    5850    }
    5951
    6052    void sleep(unsigned long seconds)
    6153    {
    62         Sleep(seconds * 1000);
     54        std::this_thread::sleep_for(std::chrono::seconds(seconds));
    6355    }
    6456}
    65 
    66 #else /* Linux/Apple */
    67 #include <unistd.h>
    68 
    69 namespace orxonox
    70 {
    71     void usleep(unsigned long usec)
    72     {
    73         ::usleep(usec);
    74     }
    75     void msleep(unsigned long msec)
    76     {
    77         ::usleep(msec * 1000);
    78     }
    79     void sleep(unsigned long sec)
    80     {
    81         ::usleep(sec * 1000000);
    82     }
    83 }
    84 
    85 #endif
Note: See TracChangeset for help on using the changeset viewer.