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