Skip to content

Commit 439d92a

Browse files
committed
Add experimental SUBR to call nanosleep() for experiments in reducing CPU load
This adds a SUBR, sb_YIELD, value (octal) 0322 which takes a single number 0..999999999 which is the number of nanoseconds to pass to nanosleep(). The return value is T if the call to nanosleep() was executed or NIL if it was not (argument out-of-range, or other error in getting the number from the argument). To use this experimental SUBR in a sysout you should: (SETQ \INITSUBRS (CONS '(YIELD #o322) \INITSUBRS)) then you can define functions that use that SUBR: (DEFINEQ (BACKGROUND-YIELD (SUBRCALL YIELD 833333))) (COMPILE 'BACKGROUND-YIELD) (SETQ BACKGROUNDFNS (CONS 'BACKGROUND-YIELD BACKGROUNDFNS))
1 parent c6a74b2 commit 439d92a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

inc/subrs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,6 @@
191191
#define user_subr_DUMMY 012
192192
#define user_subr_SAMPLE_USER_SUBR 00
193193

194+
/* Experimental yield */
195+
#define sb_YIELD 0322
194196
#endif

src/subr.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
/***********************************************************/
3030

3131
#include <stdio.h>
32+
#include <time.h>
3233
#include "lispemul.h"
3334
#include "address.h"
3435
#include "adr68k.h"
@@ -779,6 +780,20 @@ void OP_subrcall(int subr_no, int argnum) {
779780
break;
780781
}
781782
#endif /* LPSOLVE */
783+
case sb_YIELD: {
784+
struct timespec rqts = {0, 833333};
785+
unsigned sleepnanos;
786+
POP_SUBR_ARGS;
787+
N_GETNUMBER(args[0], sleepnanos, ret_nil);
788+
if (sleepnanos > 999999999) {
789+
TopOfStack = NIL;
790+
break;
791+
}
792+
rqts.tv_nsec = sleepnanos;
793+
nanosleep(&rqts, NULL);
794+
TopOfStack = ATOM_T;
795+
break;
796+
}
782797
default: {
783798
char errtext[200];
784799
sprintf(errtext, "OP_subrcall: Invalid alpha byte 0%o", ((*(PC + 1)) & 0xff));

0 commit comments

Comments
 (0)