Skip to content

Commit

Permalink
Fail pony_start if ASIO backend wasn't successfully initialized
Browse files Browse the repository at this point in the history
Prior to this commit, the ASIO backend could fail initialization
but the runtime would continue to start up anyway resulting in
segfaults or assertion failures.

This commit changes things so that if the backend initialization
fails, the runtime exits immediately with an error.

This commit also fixes the asio restart logic from PR #2373 to
properly re-initialize the backend first.
  • Loading branch information
dipinhora authored and SeanTAllen committed Nov 28, 2017
1 parent b2a7f3f commit 1468374
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/libponyrt/asio/asio.c
Expand Up @@ -46,6 +46,10 @@ void ponyint_asio_init(uint32_t cpu)

bool ponyint_asio_start()
{
// if the backend wasn't successfully initialized
if(running_base.backend == NULL)
return false;

if(!ponyint_thread_create(&running_base.tid, ponyint_asio_backend_dispatch,
asio_cpu, running_base.backend))
return false;
Expand Down
9 changes: 4 additions & 5 deletions src/libponyrt/sched/scheduler.c
Expand Up @@ -29,6 +29,7 @@ typedef enum
} sched_msg_t;

// Scheduler global data.
static uint32_t asio_cpu;
static uint32_t scheduler_count;
static scheduler_t* scheduler;
static PONY_ATOMIC(bool) detect_quiescence;
Expand Down Expand Up @@ -113,10 +114,8 @@ static bool read_msg(scheduler_t* sched)
if (sched->asio_stopped)
{
// restart the ASIO thread
bool asio_started = ponyint_asio_start();
pony_assert(asio_started);
(void) asio_started;
sched->asio_stopped = false;
ponyint_asio_init(asio_cpu);
sched->asio_stopped = !ponyint_asio_start();
}

// make sure asio hasn't already been stopped or else runtime is in
Expand Down Expand Up @@ -470,7 +469,7 @@ pony_ctx_t* ponyint_sched_init(uint32_t threads, bool noyield, bool nopin,
scheduler_count * sizeof(scheduler_t));
memset(scheduler, 0, scheduler_count * sizeof(scheduler_t));

uint32_t asio_cpu = ponyint_cpu_assign(scheduler_count, scheduler, nopin,
asio_cpu = ponyint_cpu_assign(scheduler_count, scheduler, nopin,
pinasio);

for(uint32_t i = 0; i < scheduler_count; i++)
Expand Down

0 comments on commit 1468374

Please sign in to comment.