Skip to content

Instantly share code, notes, and snippets.

@Ancurio
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save Ancurio/ae83d3bacc7991e5ca5b to your computer and use it in GitHub Desktop.

Select an option

Save Ancurio/ae83d3bacc7991e5ca5b to your computer and use it in GitHub Desktop.

Revisions

  1. Ancurio revised this gist Jun 11, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions nanosleep.patch
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    diff --git a/src/graphics.cpp b/src/graphics.cpp
    index 01e80c7..2f719f5 100644
    index 01e80c7..300bebb 100644
    --- a/src/graphics.cpp
    +++ b/src/graphics.cpp
    @@ -34,6 +34,7 @@
    @@ -27,13 +27,13 @@ index 01e80c7..2f719f5 100644
    while (nanosleep(&req, &req) == -1)
    - ;
    + {
    + bool interrupted = (errno == EINTR);
    + int err = errno;
    + errno = 0;
    +
    + if (interrupted)
    + if (err == EINTR)
    + continue;
    +
    + Debug() << "nanosleep failed for ticks =" << ticks;
    + Debug() << "nanosleep failed. errno:" << err << "ticks:" << ticks;
    + break;
    + }
    #else
  2. Ancurio revised this gist Jun 11, 2014. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions nanosleep.patch
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    diff --git a/src/graphics.cpp b/src/graphics.cpp
    index 01e80c7..674e12f 100644
    index 01e80c7..2f719f5 100644
    --- a/src/graphics.cpp
    +++ b/src/graphics.cpp
    @@ -34,6 +34,7 @@
    @@ -18,10 +18,11 @@ index 01e80c7..674e12f 100644
    #include <algorithm>

    struct PingPong
    @@ -342,8 +344,18 @@ private:
    @@ -342,8 +344,19 @@ private:
    struct timespec req;
    req.tv_sec = 0;
    req.tv_nsec = ticks / tickFreqNS;
    + errno = 0;
    +
    while (nanosleep(&req, &req) == -1)
    - ;
  3. Ancurio revised this gist Jun 11, 2014. 1 changed file with 8 additions and 9 deletions.
    17 changes: 8 additions & 9 deletions nanosleep.patch
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    diff --git a/src/graphics.cpp b/src/graphics.cpp
    index 01e80c7..43542be 100644
    index 01e80c7..674e12f 100644
    --- a/src/graphics.cpp
    +++ b/src/graphics.cpp
    @@ -34,6 +34,7 @@
    @@ -18,23 +18,22 @@ index 01e80c7..43542be 100644
    #include <algorithm>

    struct PingPong
    @@ -342,8 +344,19 @@ private:
    @@ -342,8 +344,18 @@ private:
    struct timespec req;
    req.tv_sec = 0;
    req.tv_nsec = ticks / tickFreqNS;
    +
    while (nanosleep(&req, &req) == -1)
    - ;
    + {
    + if (errno != EINTR)
    + {
    + Debug() << "nanosleep failed for ticks =" << ticks;
    + errno = 0;
    + bool interrupted = (errno == EINTR);
    + errno = 0;
    +
    + break;
    + }
    + if (interrupted)
    + continue;
    +
    + errno = 0;
    + Debug() << "nanosleep failed for ticks =" << ticks;
    + break;
    + }
    #else
    SDL_Delay(ticks / tickFreqMS);
  4. Ancurio created this gist Jun 10, 2014.
    41 changes: 41 additions & 0 deletions nanosleep.patch
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    diff --git a/src/graphics.cpp b/src/graphics.cpp
    index 01e80c7..43542be 100644
    --- a/src/graphics.cpp
    +++ b/src/graphics.cpp
    @@ -34,6 +34,7 @@
    #include "etc-internal.h"
    #include "binding.h"
    #include "perftimer.h"
    +#include "debugwriter.h"

    #include <SDL_video.h>
    #include <SDL_timer.h>
    @@ -41,6 +42,7 @@

    #include <time.h>
    #include <sys/time.h>
    +#include <errno.h>
    #include <algorithm>

    struct PingPong
    @@ -342,8 +344,19 @@ private:
    struct timespec req;
    req.tv_sec = 0;
    req.tv_nsec = ticks / tickFreqNS;
    +
    while (nanosleep(&req, &req) == -1)
    - ;
    + {
    + if (errno != EINTR)
    + {
    + Debug() << "nanosleep failed for ticks =" << ticks;
    + errno = 0;
    +
    + break;
    + }
    +
    + errno = 0;
    + }
    #else
    SDL_Delay(ticks / tickFreqMS);
    #endif