diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/Fl_sleep.cxx | 68 | ||||
| -rw-r--r-- | src/Makefile | 5 |
3 files changed, 72 insertions, 2 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 778a1d6ea..9da98d6e2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -90,6 +90,7 @@ set(CPPFILES Fl_get_system_colors.cxx Fl_grab.cxx Fl_lock.cxx + Fl_sleep.cxx Fl_own_colormap.cxx Fl_visual.cxx Fl_x.cxx diff --git a/src/Fl_sleep.cxx b/src/Fl_sleep.cxx new file mode 100644 index 000000000..43fbec46c --- /dev/null +++ b/src/Fl_sleep.cxx @@ -0,0 +1,68 @@ +// +// "$Id: Fl_sleep.cxx $" +// +// Multi-threading support code for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2010 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// http://www.fltk.org/COPYING.php +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +// Cross platform sleep API for FLTK, F. Costantini, May 20th, 2014 + +#include <FL/Fl.H> +#include <config.h> + +#include <stdlib.h> + +#ifdef WIN32 +#include <windows.h> +#else +#include <unistd.h> +#endif + +/** Make the current thread sleep for n seconds, support decimals ... */ +void Fl::sleep(double seconds) +{ + Fl::usleep((unsigned long long) (seconds*1000000)); +} + +/** Make the current thread to sleep for n milliseconds */ +void Fl::msleep(unsigned long milliseconds) +{ +#ifdef WIN32 + ::Sleep( (DWORD) milliseconds); +#else + ::usleep((useconds_t) (milliseconds*1000)); +#endif +} + +/** Make the current thread to sleep for n microseconds */ +void Fl::usleep(unsigned long long microseconds) +// unsigned long long more should be more portable than int64_t before c++ 2011 ... +{ +#ifdef WIN32 + HANDLE timer; + LARGE_INTEGER reltime; + + reltime.QuadPart = (LONGLONG) -(10*microseconds); // Convert to 100 nanosecond relative time interval + timer = CreateWaitableTimer(NULL, TRUE, NULL); + SetWaitableTimer(timer, &reltime, 0, NULL, NULL, 0); + WaitForSingleObject(timer, INFINITE); + CloseHandle(timer); +#else + ::usleep((useconds_t) microseconds); +#endif +} + +// +// End of "$Id: $". +// diff --git a/src/Makefile b/src/Makefile index 5df7ea124..2c236f47a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -106,6 +106,7 @@ CPPFILES = \ Fl_get_system_colors.cxx \ Fl_grab.cxx \ Fl_lock.cxx \ + Fl_sleep.cxx \ Fl_own_colormap.cxx \ Fl_visual.cxx \ Fl_x.cxx \ @@ -157,13 +158,13 @@ CPPFILES = \ screen_xywh.cxx \ fl_utf8.cxx \ ps_image.cxx - + OBJCPPFILES = \ Fl_cocoa.mm \ Fl_Quartz_Printer.mm \ Fl_Native_File_Chooser_MAC.mm \ Fl_Sys_Menu_Bar.mm - + FLCPPFILES = \ forms_compatability.cxx \ forms_bitmap.cxx \ |
