Skip to content

Commit

Permalink
Handle EINTR error in sleep_ms/sleep_us.
Browse files Browse the repository at this point in the history
  • Loading branch information
CuppoJava committed Apr 16, 2024
1 parent 96e8e43 commit 40c092f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion compiler/params.stanza
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public defn compiler-flags () :
to-tuple(COMPILE-FLAGS)

;========= Stanza Configuration ========
public val STANZA-VERSION = [0 18 61]
public val STANZA-VERSION = [0 18 62]
public var STANZA-INSTALL-DIR:String = ""
public var OUTPUT-PLATFORM:Symbol = `platform
public var STANZA-PKG-DIRS:List<String> = List()
Expand Down
31 changes: 23 additions & 8 deletions runtime/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,18 +454,33 @@ StringList* list_dir (const stz_byte* filename){
//===================== Sleeping =============================
//============================================================

//Helper: Handle EINTR by calling nanosleep() repeatedly
//until desired time has elapsed.
stz_int continuous_sleep (struct timespec time){
while(true){
struct timespec rem;
stz_int result = nanosleep(&time, &rem);
if(result >= 0) return result;
if(errno != EINTR) return result;
time = rem;
}
exit_with_error();
}

//Sleep for the given number of microseconds.
stz_int sleep_us (stz_long us){
struct timespec t1, t2;
t1.tv_sec = us / 1000000L;
t1.tv_nsec = (us % 1000000L) * 1000L;
return (stz_int)nanosleep(&t1, &t2);
struct timespec t;
t.tv_sec = us / 1000000L;
t.tv_nsec = (us % 1000000L) * 1000L;
return continuous_sleep(t);
}

//Sleep for the given number of milliseconds.
stz_int sleep_ms (stz_long ms){
struct timespec t1, t2;
t1.tv_sec = ms / 1000L;
t1.tv_nsec = (ms % 1000L) * 1000000L;
return (stz_int)nanosleep(&t1, &t2);
struct timespec t;
t.tv_sec = ms / 1000L;
t.tv_nsec = (ms % 1000L) * 1000000L;
return continuous_sleep(t);
}

//============================================================
Expand Down

0 comments on commit 40c092f

Please sign in to comment.