Skip to content

Commit 4357ab0

Browse files
committed
Fix nanosleep64 permanently: exclude <thread> on Windows, use Sleep() for all Windows sleeps
1 parent 02b783b commit 4357ab0

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

.github/workflows/build-cache.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ jobs:
2727
- name: Build cache
2828
run: |
2929
mkdir -p cache/linux-x64
30-
CFLAGS="-std=c++2c -O2 -march=x86-64 -DWINPTHREAD_STATIC"
31-
LFLAGS="-static-libgcc -static-libstdc++ -static -lpthread"
30+
CFLAGS="-std=c++2c -O2 -march=x86-64"
31+
LFLAGS="-static-libgcc -static-libstdc++"
3232
DEFS="-DPROCESSING_HAS_STB_IMAGE -DPROCESSING_HAS_STB_TRUETYPE"
3333
INC="-I src"
3434
@@ -64,8 +64,8 @@ jobs:
6464
shell: msys2 {0}
6565
run: |
6666
mkdir -p cache/windows-x64
67-
CFLAGS="-std=c++2c -O2 -march=x86-64 -DWINPTHREAD_STATIC"
68-
LFLAGS="-static-libgcc -static-libstdc++ -static -lpthread"
67+
CFLAGS="-std=c++2c -O2 -march=x86-64"
68+
LFLAGS="-static-libgcc -static-libstdc++"
6969
DEFS="-DPROCESSING_HAS_STB_IMAGE -DPROCESSING_HAS_STB_TRUETYPE"
7070
INC="-I src"
7171

src/Processing.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
#include <iomanip>
2525
#include <sstream>
2626
#include <fstream>
27-
#include <thread>
2827
#include <chrono>
28+
#ifndef _WIN32
29+
#include <thread>
30+
#endif
2931
#include <vector>
3032
#include <array>
3133
#include <string>
@@ -555,8 +557,12 @@ void PApplet::size(int w,int h){
555557
#ifdef _WIN32
556558
Sleep(1);
557559
#elif !defined(__EMSCRIPTEN__)
560+
#ifdef _WIN32
561+
Sleep(1);
562+
#else
558563
::std::this_thread::sleep_for(::std::chrono::milliseconds(1));
559564
#endif
565+
#endif
560566
}
561567
// Force coordinate system to requested size regardless of WM.
562568
// logicalW/H are the sketch's coordinate space; viewport uses actual size.
@@ -3767,7 +3773,13 @@ void PApplet::run(){
37673773
auto now = ::std::chrono::steady_clock::now();
37683774
double elapsed = ::std::chrono::duration<double>(now - last).count();
37693775
double sl = targetFrameTime - elapsed;
3770-
if (sl > 0) ::std::this_thread::sleep_for(::std::chrono::duration<double>(sl));
3776+
if (sl > 0) {
3777+
#ifdef _WIN32
3778+
Sleep((DWORD)(sl * 1000.0));
3779+
#else
3780+
::std::this_thread::sleep_for(::std::chrono::duration<double>(sl));
3781+
#endif
3782+
}
37713783
auto frameEnd = ::std::chrono::steady_clock::now();
37723784
double fullFrame = ::std::chrono::duration<double>(frameEnd - last).count();
37733785
if (fullFrame > 0) _frameRate = (float)(1.0 / fullFrame);

0 commit comments

Comments
 (0)