Sha256: 418b3a2423882cccfcb3d13167f4e8bb00a18bc3c31cab35bd1799c91b2aa915

Contents?: true

Size: 1.83 KB

Versions: 15

Compression:

Stored size: 1.83 KB

Contents

#include <stdlib.h>
#include "ruby.h"
#include "polyphony.h"
#include "backend_io_uring_context.h"

const char *op_type_to_str(enum op_type type) {
  switch (type) {
  case OP_READ: return "READ";
  case OP_WRITEV: return "WRITEV";
  case OP_WRITE: return "WRITE";
  case OP_RECV: return "RECV";
  case OP_SEND: return "SEND";
  case OP_TIMEOUT: return "TIMEOUT";
  case OP_POLL: return "POLL";
  case OP_ACCEPT: return "ACCEPT";
  case OP_CONNECT: return "CONNECT";
  default: return "";
  };
}

void context_store_initialize(op_context_store_t *store) {
  store->last_id = 0;
  store->available = NULL;
  store->taken = NULL;
}

inline op_context_t *context_store_acquire(op_context_store_t *store, enum op_type type) {
  op_context_t *ctx = store->available;
  if (ctx) {
    if (ctx->next) ctx->next->prev = NULL;
    store->available = ctx->next;
  }
  else {
    ctx = malloc(sizeof(op_context_t));
  }
  ctx->id = (++store->last_id);
  
  ctx->prev = NULL;
  ctx->next = store->taken;
  if (store->taken) store->taken->prev = ctx;
  store->taken = ctx;

  ctx->type = type;
  ctx->fiber = rb_fiber_current();
  ctx->resume_value = Qnil;
  ctx->completed = 0;
  ctx->result = 0;

  return ctx;
}

inline void context_store_release(op_context_store_t *store, op_context_t *ctx) {
  if (ctx->next) ctx->next->prev = ctx->prev;
  if (ctx->prev) ctx->prev->next = ctx->next;
  if (store->taken == ctx) store->taken = ctx->next;

  ctx->prev = NULL;
  ctx->next = store->available;
  if (ctx->next) ctx->next->prev = ctx;
  store->available = ctx;
}

void context_store_free(op_context_store_t *store) {
  while (store->available) {
    op_context_t *next = store->available->next;
    free(store->available);
    store->available = next;
  }
  while (store->taken) {
    op_context_t *next = store->taken->next;
    free(store->taken);
    store->taken = next;
  }
}

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
polyphony-0.52.0 ext/polyphony/backend_io_uring_context.c
polyphony-0.51.0 ext/polyphony/backend_io_uring_context.c
polyphony-0.50.1 ext/polyphony/backend_io_uring_context.c
polyphony-0.50.0 ext/polyphony/backend_io_uring_context.c
polyphony-0.49.2 ext/polyphony/backend_io_uring_context.c
polyphony-0.49.1 ext/polyphony/backend_io_uring_context.c
polyphony-0.49.0 ext/polyphony/backend_io_uring_context.c
polyphony-0.48.0 ext/polyphony/backend_io_uring_context.c
polyphony-0.47.5.1 ext/polyphony/backend_io_uring_context.c
polyphony-0.47.5 ext/polyphony/backend_io_uring_context.c
polyphony-0.47.4 ext/polyphony/backend_io_uring_context.c
polyphony-0.47.3 ext/polyphony/backend_io_uring_context.c
polyphony-0.47.2 ext/polyphony/backend_io_uring_context.c
polyphony-0.47.1 ext/polyphony/backend_io_uring_context.c
polyphony-0.47.0 ext/polyphony/backend_io_uring_context.c