mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-10 03:44:16 +00:00
Implement base::this_thread::yield & sleep_for().
This commit is contained in:
parent
c2874a063c
commit
fffc32548a
@ -1,6 +1,18 @@
|
|||||||
# ASEPRITE
|
# ASEPRITE
|
||||||
# Copyright (C) 2001-2012 David Capello
|
# Copyright (C) 2001-2012 David Capello
|
||||||
|
|
||||||
|
CHECK_C_SOURCE_COMPILES("
|
||||||
|
#include <unistd.h>
|
||||||
|
int main() {
|
||||||
|
sched_yield();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
" HAVE_SCHED_YIELD)
|
||||||
|
|
||||||
|
if(HAVE_SCHED_YIELD)
|
||||||
|
add_definitions(-DHAVE_SCHED_YIELD)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_library(base-lib
|
add_library(base-lib
|
||||||
convert_to.cpp
|
convert_to.cpp
|
||||||
errno_string.cpp
|
errno_string.cpp
|
||||||
|
@ -15,6 +15,12 @@
|
|||||||
#include <pthread.h> // Use pthread library in Unix-like systems
|
#include <pthread.h> // Use pthread library in Unix-like systems
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAVE_SCHED_YIELD) && defined(_POSIX_PRIORITY_SCHEDULING)
|
||||||
|
#include <unistd.h>
|
||||||
|
#elif !defined(WIN32)
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@ -116,17 +122,32 @@ void base::thread::details::thread_proxy(void* data)
|
|||||||
void base::this_thread::yield()
|
void base::this_thread::yield()
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
::Sleep(0);
|
::Sleep(0);
|
||||||
|
|
||||||
|
#elif defined(HAVE_SCHED_YIELD) && defined(_POSIX_PRIORITY_SCHEDULING)
|
||||||
|
|
||||||
|
sched_yield();
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// TODO
|
|
||||||
|
struct timeval timeout;
|
||||||
|
timeout.tv_sec = 0;
|
||||||
|
timeout.tv_usec = 0;
|
||||||
|
select(0, NULL, NULL, NULL, &timeout);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void base::this_thread::sleep_for(int milliseconds)
|
void base::this_thread::sleep_for(double seconds)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
::Sleep(milliseconds);
|
|
||||||
|
::Sleep(seconds * 1000.0);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// TODO
|
|
||||||
|
usleep(seconds * 1000000.0);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ namespace base { // Based on C++0x threads lib
|
|||||||
namespace this_thread
|
namespace this_thread
|
||||||
{
|
{
|
||||||
void yield();
|
void yield();
|
||||||
void sleep_for(int milliseconds);
|
void sleep_for(double seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This class joins the thread in its destructor.
|
// This class joins the thread in its destructor.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user