diff options
author | Michael Lutz <michi@icosahedron.de> | 2019-03-17 11:05:53 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2019-04-06 11:27:39 +0200 |
commit | ae748166d06e756a0a6abab582dc341494a9b2da (patch) | |
tree | d4c75246740f2e2ddd6978a6b14b17ac84bc27cf | |
parent | 94c5269fa772304112b7c40d2c84794056f87717 (diff) | |
download | openttd-ae748166d06e756a0a6abab582dc341494a9b2da.tar.xz |
Codechange: Use platform independent C++11 function for sleeping on a thread.
-rw-r--r-- | src/gfx.cpp | 1 | ||||
-rw-r--r-- | src/gfx_func.h | 1 | ||||
-rw-r--r-- | src/music/extmidi.cpp | 1 | ||||
-rw-r--r-- | src/network/network_client.cpp | 1 | ||||
-rw-r--r-- | src/os/os2/os2.cpp | 9 | ||||
-rw-r--r-- | src/os/unix/unix.cpp | 8 | ||||
-rw-r--r-- | src/os/windows/win32.cpp | 6 | ||||
-rw-r--r-- | src/thread.h | 9 | ||||
-rw-r--r-- | src/video/allegro_v.cpp | 1 | ||||
-rw-r--r-- | src/video/cocoa/event.mm | 1 | ||||
-rw-r--r-- | src/video/cocoa/fullscreen.mm | 3 | ||||
-rw-r--r-- | src/video/dedicated_v.cpp | 1 |
12 files changed, 17 insertions, 25 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp index b7e31a384..f1b91c16e 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -21,6 +21,7 @@ #include "network/network_func.h" #include "window_func.h" #include "newgrf_debug.h" +#include "thread.h" #include "table/palettes.h" #include "table/string_colours.h" diff --git a/src/gfx_func.h b/src/gfx_func.h index 9f7cb9153..2abbcd2a8 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -75,7 +75,6 @@ void HandleKeypress(uint keycode, WChar key); void HandleTextInput(const char *str, bool marked = false, const char *caret = NULL, const char *insert_location = NULL, const char *replacement_end = NULL); void HandleCtrlChanged(); void HandleMouseEvents(); -void CSleep(int milliseconds); void UpdateWindows(); void DrawMouseCursor(); diff --git a/src/music/extmidi.cpp b/src/music/extmidi.cpp index 9d07761b7..f7fc454df 100644 --- a/src/music/extmidi.cpp +++ b/src/music/extmidi.cpp @@ -18,6 +18,7 @@ #include "../gfx_func.h" #include "extmidi.h" #include "../base_media_base.h" +#include "../thread.h" #include "midifile.hpp" #include <fcntl.h> #include <sys/types.h> diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 7b658e8b5..8c68b98f8 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -29,6 +29,7 @@ #include "network_base.h" #include "network_client.h" #include "../core/backup_type.hpp" +#include "../thread.h" #include "table/strings.h" diff --git a/src/os/os2/os2.cpp b/src/os/os2/os2.cpp index 9d01a99b8..b62e83e5e 100644 --- a/src/os/os2/os2.cpp +++ b/src/os/os2/os2.cpp @@ -205,15 +205,6 @@ bool GetClipboardContents(char *buffer, const char *last) } -void CSleep(int milliseconds) -{ -#ifndef __INNOTEK_LIBC__ - delay(milliseconds); -#else - usleep(milliseconds * 1000); -#endif -} - const char *FS2OTTD(const char *name) {return name;} const char *OTTD2FS(const char *name) {return name;} diff --git a/src/os/unix/unix.cpp b/src/os/unix/unix.cpp index 024dc8627..e20a6c1b5 100644 --- a/src/os/unix/unix.cpp +++ b/src/os/unix/unix.cpp @@ -273,14 +273,6 @@ bool GetClipboardContents(char *buffer, const char *last) #endif -/* multi os compatible sleep function */ - -void CSleep(int milliseconds) -{ - usleep(milliseconds * 1000); -} - - #ifndef __APPLE__ uint GetCPUCoreCount() { diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index 2a72ca1c5..9847de567 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -544,12 +544,6 @@ bool GetClipboardContents(char *buffer, const char *last) } -void CSleep(int milliseconds) -{ - Sleep(milliseconds); -} - - /** * Convert to OpenTTD's encoding from that of the local environment. * When the project is built in UNICODE, the system codepage is irrelevant and diff --git a/src/thread.h b/src/thread.h index 086e2f51e..cd2608221 100644 --- a/src/thread.h +++ b/src/thread.h @@ -21,6 +21,15 @@ class OTTDThreadExitSignal { }; /** + * Sleep on the current thread for a defined time. + * @param milliseconds Time to sleep for in milliseconds. + */ +inline void CSleep(int milliseconds) +{ + std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds)); +} + +/** * Get number of processor cores in the system, including HyperThreading or similar. * @return Total number of processor cores. */ diff --git a/src/video/allegro_v.cpp b/src/video/allegro_v.cpp index 53a42393e..c21f88d67 100644 --- a/src/video/allegro_v.cpp +++ b/src/video/allegro_v.cpp @@ -25,6 +25,7 @@ #include "../core/random_func.hpp" #include "../core/math_func.hpp" #include "../framerate_type.h" +#include "../thread.h" #include "allegro_v.h" #include <allegro.h> diff --git a/src/video/cocoa/event.mm b/src/video/cocoa/event.mm index de812a70d..a8108b561 100644 --- a/src/video/cocoa/event.mm +++ b/src/video/cocoa/event.mm @@ -37,6 +37,7 @@ #include "../../core/math_func.hpp" #include "../../texteff.hpp" #include "../../window_func.h" +#include "../../thread.h" #import <sys/time.h> /* gettimeofday */ diff --git a/src/video/cocoa/fullscreen.mm b/src/video/cocoa/fullscreen.mm index 860866b33..3ce22133d 100644 --- a/src/video/cocoa/fullscreen.mm +++ b/src/video/cocoa/fullscreen.mm @@ -30,6 +30,7 @@ #include "../../core/sort_func.hpp" #include "cocoa_v.h" #include "../../gfx_func.h" +#include "../../thread.h" #include "../../os/macosx/macos.h" /** @@ -174,7 +175,7 @@ class FullscreenSubdriver : public CocoaSubdriver { double adjustment = (target - position) / linesPerSecond; - CSleep((uint32)(adjustment * 1000)); + CSleep((uint32)adjustment * 1000); } diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp index e0096c893..5af900080 100644 --- a/src/video/dedicated_v.cpp +++ b/src/video/dedicated_v.cpp @@ -22,6 +22,7 @@ #include "../company_func.h" #include "../core/random_func.hpp" #include "../saveload/saveload.h" +#include "../thread.h" #include "dedicated_v.h" #ifdef __OS2__ |