[pypy-commit] pypy continulet-jit: Finish the part in the C code.
arigo
noreply at buildbot.pypy.org
Sun Oct 16 15:10:01 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: continulet-jit
Changeset: r48078:ff490d93d8b4
Date: 2011-10-16 13:31 +0200
http://bitbucket.org/pypy/pypy/changeset/ff490d93d8b4/
Log: Finish the part in the C code.
diff --git a/pypy/translator/c/src/stacklet/stacklet.c b/pypy/translator/c/src/stacklet/stacklet.c
--- a/pypy/translator/c/src/stacklet/stacklet.c
+++ b/pypy/translator/c/src/stacklet/stacklet.c
@@ -61,6 +61,10 @@
void (*_stacklet_initialstub)(struct stacklet_thread_s *,
stacklet_run_fn, void *) = NULL;
+struct stacklet_id_s {
+ stacklet_handle stacklet;
+};
+
struct stacklet_thread_s {
stacklet_id g_current_id; /* first field */
struct stacklet_s *g_stack_chain_head; /* NULL <=> running main */
@@ -68,10 +72,7 @@
char *g_current_stack_marker;
struct stacklet_s *g_source;
struct stacklet_s *g_target;
-};
-
-struct stacklet_id_s {
- stacklet_handle stacklet;
+ struct stacklet_id_s g_main_id;
};
/***************************************************************/
@@ -136,8 +137,7 @@
stacklet = thrd->g_source;
stacklet->id = thrd->g_current_id;
- if (stacklet->id != NULL)
- stacklet->id->stacklet = stacklet;
+ stacklet->id->stacklet = stacklet;
stacklet->stack_start = old_stack_pointer;
stacklet->stack_stop = thrd->g_current_stack_stop;
stacklet->stack_saved = 0;
@@ -238,8 +238,7 @@
#endif
thrd->g_current_stack_stop = g->stack_stop;
thrd->g_current_id = g->id;
- if (thrd->g_current_id != NULL)
- thrd->g_current_id->stacklet = NULL;
+ thrd->g_current_id->stacklet = NULL;
free(g);
return EMPTY_STACKLET_HANDLE;
}
@@ -300,8 +299,10 @@
}
thrd = malloc(sizeof(struct stacklet_thread_s));
- if (thrd != NULL)
+ if (thrd != NULL) {
memset(thrd, 0, sizeof(struct stacklet_thread_s));
+ thrd->g_current_id = &thrd->g_main_id;
+ }
return thrd;
}
@@ -369,3 +370,10 @@
}
return ptr;
}
+
+stacklet_handle _stacklet_with_id(stacklet_thread_handle thrd, stacklet_id id)
+{
+ if (id == NULL)
+ id = &thrd->g_main_id;
+ return id->stacklet;
+}
diff --git a/pypy/translator/c/src/stacklet/stacklet.h b/pypy/translator/c/src/stacklet/stacklet.h
--- a/pypy/translator/c/src/stacklet/stacklet.h
+++ b/pypy/translator/c/src/stacklet/stacklet.h
@@ -59,14 +59,15 @@
*/
char **_stacklet_translate_pointer(stacklet_handle context, char **ptr);
-/* The "stacklet id" is NULL for main stacklets; for other stacklets it is a
- * value that remain valid and unchanged if the stacklet is suspended and
- * resumed. WARNING: DON'T USE unless you have no other choice, because
- * it is not "composable" at all.
+/* The "stacklet id" is a value that remain valid and unchanged if the
+ * stacklet is suspended and resumed. WARNING: DON'T USE unless you have
+ * no other choice, because it is not "composable" at all.
*/
typedef struct stacklet_id_s *stacklet_id;
#define _stacklet_id_of_stacklet(stacklet) (*(stacklet_id*)(stacklet))
#define _stacklet_id_current(thrd) (*(stacklet_id*)(thrd))
+/* Returns the current stacklet with the given id.
+ If 'id' == NULL, returns the main stacklet in the thread. */
stacklet_handle _stacklet_with_id(stacklet_thread_handle thrd, stacklet_id id);
#endif /* _STACKLET_H_ */
diff --git a/pypy/translator/c/src/stacklet/tests.c b/pypy/translator/c/src/stacklet/tests.c
--- a/pypy/translator/c/src/stacklet/tests.c
+++ b/pypy/translator/c/src/stacklet/tests.c
@@ -628,17 +628,27 @@
/************************************************************/
struct test_id_s {
+ stacklet_id idmain;
stacklet_id id1;
stacklet_id id2;
+ stacklet_handle hmain;
+ stacklet_handle h1;
+ stacklet_handle h2;
} tid;
stacklet_handle stacklet_id_callback_1(stacklet_handle h, void *arg)
{
stacklet_id myid = _stacklet_id_current(thrd);
+ assert(_stacklet_with_id(thrd, myid) == NULL);
+ tid.hmain = h;
+ tid.h1 = NULL;
+
h = stacklet_switch(thrd, h);
-
+ tid.hmain = h;
+ tid.h1 = NULL;
+
tid.id1 = _stacklet_id_current(thrd);
- assert(tid.id1 != NULL);
+ assert(tid.id1 != tid.idmain);
assert(tid.id1 == myid);
assert(status == 0);
status = 1;
@@ -649,11 +659,22 @@
stacklet_handle stacklet_id_callback_2(stacklet_handle h, void *arg)
{
stacklet_id myid = _stacklet_id_current(thrd);
+ assert(_stacklet_with_id(thrd, myid) == NULL);
+ tid.hmain = h;
+ tid.h2 = NULL;
+
h = stacklet_switch(thrd, h);
+ tid.hmain = h;
+ tid.h2 = NULL;
tid.id2 = _stacklet_id_current(thrd);
- assert(tid.id2 != NULL);
+ assert(tid.id2 != tid.idmain);
+ assert(tid.id2 != tid.id1);
assert(tid.id2 == myid);
+ assert(_stacklet_with_id(thrd, tid.idmain) == tid.hmain);
+ assert(_stacklet_with_id(thrd, tid.id1) == tid.h1);
+ assert(_stacklet_with_id(thrd, tid.id2) == tid.h2);
+
assert(status == 1);
status = 2;
@@ -665,19 +686,30 @@
status = 0;
stacklet_handle h1 = stacklet_new(thrd, stacklet_id_callback_1, NULL);
stacklet_handle h2 = stacklet_new(thrd, stacklet_id_callback_2, NULL);
+ tid.hmain = NULL;
+ tid.h1 = h1;
+ tid.h2 = h2;
- assert(_stacklet_id_current(thrd) == NULL);
+ tid.idmain = _stacklet_id_current(thrd);
+ assert(_stacklet_with_id(thrd, tid.idmain) == NULL);
assert(status == 0);
h1 = stacklet_switch(thrd, h1);
+ tid.hmain = NULL;
+ tid.h1 = h1;
assert(status == 1);
h2 = stacklet_switch(thrd, h2);
+ tid.hmain = NULL;
+ tid.h2 = h2;
assert(status == 2);
assert(_stacklet_id_of_stacklet(h1) == tid.id1);
assert(_stacklet_id_of_stacklet(h2) == tid.id2);
- assert(_stacklet_id_current(thrd) == NULL);
+ assert(_stacklet_id_current(thrd) == tid.idmain);
+ assert(_stacklet_with_id(thrd, tid.idmain) == NULL);
+ assert(_stacklet_with_id(thrd, tid.id1) == tid.h1);
+ assert(_stacklet_with_id(thrd, tid.id2) == tid.h2);
h1 = stacklet_switch(thrd, h1);
assert(h1 == EMPTY_STACKLET_HANDLE);
More information about the pypy-commit
mailing list