Skip to content

Instantly share code, notes, and snippets.

@liuliu
Created August 16, 2018 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liuliu/dda279757bbccaf00c996deae00fecc7 to your computer and use it in GitHub Desktop.
Save liuliu/dda279757bbccaf00c996deae00fecc7 to your computer and use it in GitHub Desktop.
union ptr_splitter {
void *ptr;
uint32_t part[2];
};
static const int default_stack_size = 65536;
typedef struct schd_s schd_t;
typedef struct task_s task_t;
typedef void (*task_fn_t)(task_t *task);
struct task_s {
struct task_s* prev;
struct task_s* next;
schd_t* schd;
int done;
struct task_s* waitfor;
// For swapcontext / makecontext / getcontext.
ucontext_t context;
char *stack;
task_fn_t fn;
};
struct schd_s {
task_t* head;
task_t* tail;
struct {
int suspend;
} count;
pthread_cond_t cv;
pthread_mutex_t mutex;
ucontext_t caller, callee;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment