diff runtime/context.c @ 140:c14698c512f1

Untested addition of Pause/Resume
author Mike Pavone <pavone@retrodev.com>
date Sat, 20 Nov 2010 20:03:25 +0000
parents a68e6828d896
children f2cb85c53ced
line wrap: on
line diff
--- a/runtime/context.c	Fri Nov 19 04:04:14 2010 -0500
+++ b/runtime/context.c	Sat Nov 20 20:03:25 2010 +0000
@@ -1,9 +1,49 @@
 #include "context.h"
 #include "object.h"
+#include "thread.h"
 #include <stdlib.h>
 #include <stddef.h>
 #include <stdio.h>
 
+context * contextqueue[32];
+int32_t cq_readloc=0;
+int32_t cq_writeloc=0;
+rh_mutex(cq_lock)
+
+void cqueue_init()
+{
+	rh_mutex_init(cq_lock);
+}
+
+context * get_cqueue()
+{
+	context * ret;
+	rh_lock(cq_lock);
+		if (cq_readloc == cq_writeloc)
+		{
+			rh_unlock(cq_lock);
+			return NULL;
+		}
+		ret = contextqueue[cq_readloc++];
+		if (cq_readloc == 32)
+			cq_readloc = 0;
+	rh_unlock(cq_lock);
+	return ret;
+}
+
+int32_t put_cqueue(context * ct)
+{
+	rh_lock(cq_lock);
+		if ((cq_writeloc+1)&31 == cq_readloc)
+		{
+			rh_unlock(cq_lock);
+			return 0;
+		}
+		contextqueue[cq_writeloc++] = ct;
+	rh_unlock(cq_lock);
+	return 1;
+}
+
 stackchunk * new_stack()
 {
 	stackchunk * st = malloc(sizeof(stackchunk));
@@ -18,7 +58,9 @@
 	context * c = malloc(sizeof(context));
 	c->stack_begin = new_stack();
 	c->current_stack = c->stack_begin;
-	c->transaction = NULL;
+	c->resume_cdata = c->runafter = c->transaction = NULL;	
+	c->resumeable = 0;
+	c->start_func = -1;
 	return c;
 }