summaryrefslogtreecommitdiff
path: root/user/idle.c
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-03-25 17:36:52 -0400
committerFreya Murphy <freya@freyacat.org>2025-03-25 17:38:22 -0400
commit6af21e6a4f2251e71353562d5df7f376fdffc270 (patch)
treede20c7afc9878422c81e34f30c6b010075e9e69a /user/idle.c
downloadcomus-6af21e6a4f2251e71353562d5df7f376fdffc270.tar.gz
comus-6af21e6a4f2251e71353562d5df7f376fdffc270.tar.bz2
comus-6af21e6a4f2251e71353562d5df7f376fdffc270.zip
initial checkout from wrc
Diffstat (limited to 'user/idle.c')
-rw-r--r--user/idle.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/user/idle.c b/user/idle.c
new file mode 100644
index 0000000..dbce885
--- /dev/null
+++ b/user/idle.c
@@ -0,0 +1,51 @@
+#include <common.h>
+
+/**
+** Idle process: write, getpid, gettime, exit
+**
+** Reports itself, then loops forever delaying and printing a character.
+** MUST NOT SLEEP, as it must always be available in the ready queue
+** when there is no other process to dispatch.
+**
+** Invoked as: idle
+*/
+
+USERMAIN( main ) {
+ // this is the character we will repeatedly print
+ char ch = '.';
+
+ // ignore the command-line arguments
+ (void) argc;
+ (void) argv;
+
+ // get some current information
+ uint_t pid = getpid();
+ uint32_t now = gettime();
+ enum priority_e prio = getprio();
+
+ char buf[128];
+ sprint( buf, "Idle [%d], started @ %u\n", pid, prio, now );
+ cwrites( buf );
+
+ // report our presence on the console
+ cwrites( "Idle started\n" );
+
+ write( CHAN_SIO, &ch, 1 );
+
+ // idle() should never block - it must always be available
+ // for dispatching when we need to pick a new current process
+
+ for(;;) {
+ DELAY(LONG);
+ write( CHAN_SIO, &ch, 1 );
+ }
+
+ // we should never reach this point!
+ now = gettime();
+ sprint( buf, "Idle [%d] EXITING @ %u!?!?!\n", pid, now );
+ cwrites( buf );
+
+ exit( 1 );
+
+ return( 42 );
+}