Exemplo n.º 1
0
static void ponyint_sched_shutdown()
{
  uint32_t start;

  start = 0;

  for(uint32_t i = start; i < scheduler_count; i++)
    ponyint_thread_join(scheduler[i].tid);

  DTRACE0(RT_END);
  ponyint_cycle_terminate(&scheduler[0].ctx);

  for(uint32_t i = 0; i < scheduler_count; i++)
  {
    while(ponyint_messageq_pop(&scheduler[i].mq) != NULL);
    ponyint_messageq_destroy(&scheduler[i].mq);
    ponyint_mpmcq_destroy(&scheduler[i].q);
  }

  ponyint_pool_free_size(scheduler_count * sizeof(scheduler_t), scheduler);
  scheduler = NULL;
  scheduler_count = 0;

  ponyint_mpmcq_destroy(&inject);
}
Exemplo n.º 2
0
static void read_msg(scheduler_t* sched)
{
  pony_msgi_t* m;

  while((m = (pony_msgi_t*)ponyint_messageq_pop(&sched->mq)) != NULL)
  {
    switch(m->msg.id)
    {
      case SCHED_BLOCK:
      {
        sched->block_count++;

        if(atomic_load_explicit(&detect_quiescence, memory_order_relaxed) &&
          (sched->block_count == scheduler_count))
        {
          // If we think all threads are blocked, send CNF(token) to everyone.
          for(uint32_t i = 0; i < scheduler_count; i++)
            send_msg(i, SCHED_CNF, sched->ack_token);
        }
        break;
      }

      case SCHED_UNBLOCK:
      {
        // Cancel all acks and increment the ack token, so that any pending
        // acks in the queue will be dropped when they are received.
        sched->block_count--;
        sched->ack_token++;
        sched->ack_count = 0;
        break;
      }

      case SCHED_CNF:
      {
        // Echo the token back as ACK(token).
        send_msg(0, SCHED_ACK, m->i);
        break;
      }

      case SCHED_ACK:
      {
        // If it's the current token, increment the ack count.
        if(m->i == sched->ack_token)
          sched->ack_count++;
        break;
      }

      case SCHED_TERMINATE:
      {
        sched->terminate = true;
        break;
      }

      default: {}
    }
  }
}
Exemplo n.º 3
0
static void handle_queue(asio_backend_t* b)
{
  asio_msg_t* msg;

  while((msg = (asio_msg_t*)ponyint_messageq_pop(&b->q)) != NULL)
  {
    asio_event_t* ev = msg->event;

    switch(msg->flags)
    {
      case ASIO_DISPOSABLE:
        pony_asio_event_send(ev, ASIO_DISPOSABLE, 0);
        break;

      default: {}
    }
  }
}
Exemplo n.º 4
0
static void ponyint_sched_shutdown()
{
  uint32_t start;

  start = 0;

  for(uint32_t i = start; i < scheduler_count; i++)
    pony_thread_join(scheduler[i].tid);

  ponyint_cycle_terminate(&scheduler[0].ctx);

#ifdef USE_TELEMETRY
  printf("\"telemetry\": [\n");
#endif

  for(uint32_t i = 0; i < scheduler_count; i++)
  {
    while(ponyint_messageq_pop(&scheduler[i].mq) != NULL);
    ponyint_messageq_destroy(&scheduler[i].mq);
    ponyint_mpmcq_destroy(&scheduler[i].q);

#ifdef USE_TELEMETRY
    pony_ctx_t* ctx = &scheduler[i].ctx;

    printf(
      "  {\n"
      "    \"count_gc_passes\": " __zu ",\n"
      "    \"count_alloc\": " __zu ",\n"
      "    \"count_alloc_size\": " __zu ",\n"
      "    \"count_alloc_actors\": " __zu ",\n"
      "    \"count_msg_app\": " __zu ",\n"
      "    \"count_msg_block\": " __zu ",\n"
      "    \"count_msg_unblock\": " __zu ",\n"
      "    \"count_msg_acquire\": " __zu ",\n"
      "    \"count_msg_release\": " __zu ",\n"
      "    \"count_msg_conf\": " __zu ",\n"
      "    \"count_msg_ack\": " __zu ",\n"
      "    \"time_in_gc\": " __zu ",\n"
      "    \"time_in_send_scan\": " __zu ",\n"
      "    \"time_in_recv_scan\": " __zu "\n"
      "  }",
      ctx->count_gc_passes,
      ctx->count_alloc,
      ctx->count_alloc_size,
      ctx->count_alloc_actors,
      ctx->count_msg_app,
      ctx->count_msg_block,
      ctx->count_msg_unblock,
      ctx->count_msg_acquire,
      ctx->count_msg_release,
      ctx->count_msg_conf,
      ctx->count_msg_ack,
      ctx->time_in_gc,
      ctx->time_in_send_scan,
      ctx->time_in_recv_scan
      );

    if(i < (scheduler_count - 1))
      printf(",\n");
#endif
  }

#ifdef USE_TELEMETRY
  printf("\n]\n");
#endif

  ponyint_pool_free_size(scheduler_count * sizeof(scheduler_t), scheduler);
  scheduler = NULL;
  scheduler_count = 0;

  ponyint_mpmcq_destroy(&inject);
}