Browse files

split pointer to two uint32_t to avoid a possible problem in 64bit arch

  • Loading branch information...
1 parent 07b67af commit 3bd88818b295144ecf5f75f8bfd047dc6e304291 @cloudwu committed Jul 24, 2012
Showing with 6 additions and 2 deletions.
  1. +6 −2 coroutine.c
View
8 coroutine.c
@@ -5,6 +5,7 @@
#include <assert.h>
#include <stddef.h>
#include <string.h>
+#include <stdint.h>
#define STACK_SIZE (1024*1024)
#define DEFAULT_COROUTINE 16
@@ -103,7 +104,9 @@ coroutine_new(struct schedule *S, coroutine_func func, void *ud) {
}
static void
-mainfunc(struct schedule *S) {
+mainfunc(uint32_t low32, uint32_t hi32) {
+ uintptr_t ptr = (uintptr_t)low32 | ((uintptr_t)hi32 << 32);
+ struct schedule *S = (struct schedule *)ptr;
int id = S->running;
struct coroutine *C = S->co[id];
C->func(S,C->ud);
@@ -129,7 +132,8 @@ coroutine_resume(struct schedule * S, int id) {
C->ctx.uc_link = &S->main;
S->running = id;
C->status = COROUTINE_RUNNING;
- makecontext(&C->ctx, (void (*)(void)) mainfunc, 1, S);
+ uintptr_t ptr = (uintptr_t)S;
+ makecontext(&C->ctx, (void (*)(void)) mainfunc, 2, (uint32_t)ptr, (uint32_t)(ptr>>32));
swapcontext(&S->main, &C->ctx);
break;
case COROUTINE_SUSPEND:

0 comments on commit 3bd8881

Please sign in to comment.