Skip to content

new conc future api #821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 11 additions & 22 deletions src/runtime/encore/encore.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void actor_resume_context(encore_actor_t *actor, ucontext_t *ctx);
static void actor_resume_context(encore_actor_t *actor, ucontext_t *ctx);
#endif

extern void public_run(pony_actor_t *actor);
extern void public_run(pony_actor_t *actor, void * info_node);

extern bool pony_system_actor(pony_actor_t *actor);
static void pony_sendargs(pony_ctx_t *ctx, pony_actor_t* to, uint32_t id,
Expand All @@ -53,17 +53,6 @@ static __pony_thread_local unsigned int available_context = 0;
__pony_thread_local context *root_context;
__pony_thread_local context *this_context;

void actor_unlock(encore_actor_t *actor)
{
if (!pony_system_actor((pony_actor_t*) actor)) {
if (actor->lock) {
pthread_mutex_t *lock = actor->lock;
actor->lock = NULL;
pthread_mutex_unlock(lock);
}
}
}

#ifndef LAZY_IMPL

static __pony_thread_local stack_page *stack_pool = NULL;
Expand Down Expand Up @@ -121,7 +110,7 @@ bool actor_run_to_completion(encore_actor_t *actor)

#ifdef LAZY_IMPL

static context *pop_context(encore_actor_t *actor)
static context *pop_context(encore_actor_t *actor, void * info_node)
{
context *c;
if (available_context == 0) {
Expand All @@ -142,7 +131,7 @@ static context *pop_context(encore_actor_t *actor)
context_pool->uctx.uc_stack.ss_flags = 0;
#endif
}
makecontext(&context_pool->uctx, (void(*)(void))public_run, 1, actor);
makecontext(&context_pool->uctx, (void(*)(void))public_run, 2, actor, info_node);
c = context_pool;
context_pool = c->next;
return c;
Expand Down Expand Up @@ -198,7 +187,7 @@ static void force_thread_local_variable_access(context *old_this_context,
#endif

void actor_save_context(pony_ctx_t **ctx, encore_actor_t *actor,
ucontext_t *uctx)
ucontext_t *uctx, void * info_node)
{
#ifndef LAZY_IMPL

Expand All @@ -221,7 +210,7 @@ void actor_save_context(pony_ctx_t **ctx, encore_actor_t *actor,
context *old_this_context = this_context;
context *old_root_context = root_context;
encore_actor_t *old_actor = actor;
this_context = pop_context(actor);
this_context = pop_context(actor, info_node);
assert_swap(uctx, &this_context->uctx);
#if defined(PLATFORM_IS_MACOSX)
force_thread_local_variable_access(old_this_context, old_root_context);
Expand All @@ -235,14 +224,14 @@ void actor_save_context(pony_ctx_t **ctx, encore_actor_t *actor,
*ctx = pony_ctx(); // Context might have gone stale, update it
}

void actor_block(pony_ctx_t **ctx, encore_actor_t *actor)
void actor_block(pony_ctx_t **ctx, encore_actor_t *actor, void * info_node)
{

#ifndef LAZY_IMPL
actor_save_context(ctx, actor, &actor->uctx);
actor_save_context(ctx, actor, &actor->uctx, info_node);
#else
actor->saved = &this_context->uctx;
actor_save_context(ctx, actor, actor->saved);
actor_save_context(ctx, actor, actor->saved, info_node);
#endif

}
Expand All @@ -255,18 +244,18 @@ void actor_suspend(pony_ctx_t **ctx)
ucontext_t uctx;
pony_sendp(*ctx, (pony_actor_t*) actor, _ENC__MSG_RESUME_SUSPEND, &uctx);

actor_save_context(ctx, actor, &uctx);
actor_save_context(ctx, actor, &uctx, NULL);

actor->suspend_counter--;
assert(actor->suspend_counter >= 0);
}

void actor_await(pony_ctx_t **ctx, ucontext_t *uctx)
void actor_await(pony_ctx_t **ctx, ucontext_t *uctx, void * info_node)
{
encore_actor_t *actor = (encore_actor_t*)(*ctx)->current;
actor->await_counter++;

actor_save_context(ctx, actor, uctx);
actor_save_context(ctx, actor, uctx, info_node);

actor->await_counter--;

Expand Down
19 changes: 16 additions & 3 deletions src/runtime/encore/encore.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ static pony_type_t *ENCORE_PRIMITIVE = (pony_type_t *)1;
typedef struct encore_actor_t encore_actor_t;
typedef struct encore_oneway_msg encore_oneway_msg_t;
typedef struct encore_fut_msg encore_fut_msg_t;
typedef struct encore_vanilla_fut_msg encore_vanilla_fut_msg_t;
typedef struct encore_poly_vanilla_fut_msg encore_poly_vanilla_fut_msg_t;

typedef struct pony_main_msg_t
{
Expand Down Expand Up @@ -87,6 +89,18 @@ struct encore_fut_msg
future_t *_fut;
};

struct encore_vanilla_fut_msg
{
encore_oneway_msg_t pad;
vanilla_future_t *_fut;
};

struct encore_poly_vanilla_fut_msg
{
encore_oneway_msg_t pad;
poly_vanilla_future_t *_fut;
};

typedef struct stack_page {
void *stack;
struct stack_page *next;
Expand Down Expand Up @@ -139,18 +153,17 @@ void *encore_realloc(pony_ctx_t *ctx, void *p, size_t s);
/// The starting point of all Encore programs
int encore_start(int argc, char** argv, pony_type_t *type);

void actor_unlock(encore_actor_t *actor);
bool encore_actor_run_hook(encore_actor_t *actor);
bool encore_actor_handle_message_hook(encore_actor_t *actor, pony_msg_t* msg);
void actor_block(pony_ctx_t **ctx, encore_actor_t *actor);
void actor_block(pony_ctx_t **ctx, encore_actor_t *actor, void * info_node);
void actor_set_resume(encore_actor_t *actor);

#ifndef LAZY_IMPL
void actor_set_run_to_completion(encore_actor_t *actor);
bool actor_run_to_completion(encore_actor_t *actor);
#endif
void actor_suspend();
void actor_await(pony_ctx_t **ctx, ucontext_t *uctx);
void actor_await(pony_ctx_t **ctx, ucontext_t *uctx, void * info_node);

/// calls the pony's respond with the current object's scheduler
void call_respond_with_current_scheduler();
Expand Down
Loading