示例#1
0
文件: ring_r.c 项目: drknexus/ring
SEXP R_ring_buffer_tail(SEXP extPtr) {
  ring_buffer * buffer = ring_buffer_get(extPtr, 1);
  if (ring_buffer_empty(buffer)) {
    Rf_error("Buffer is empty");
  }
  SEXP ret = PROTECT(allocVector(RAWSXP, buffer->stride));
  memcpy(RAW(ret), ring_buffer_tail(buffer), buffer->stride);
  UNPROTECT(1);
  return ret;
}
示例#2
0
static void
_ringbuffer_fill2(RingBuffer *rb, size_t n, int start_idx, gboolean ack)
{
  TestData *td;
  int i;

  for (i = 0; i < n; i++)
    {
      td = ring_buffer_tail(rb);
      td->idx = start_idx + i;
      td->ack = ack;
      assert_true(ring_buffer_push(rb) == td, "Push should return last tail.");
    }
}
示例#3
0
gpointer
ring_buffer_push(RingBuffer *self)
{
  gpointer r = NULL;

  r = ring_buffer_tail(self);

  if (!r)
    return NULL;

  ++self->count;
  self->tail = (self->tail + 1) % self->capacity;

  return r;
}
示例#4
0
static void
test_tail()
{
  RingBuffer rb;
  TestData *td_tail;

  ring_buffer_alloc(&rb, sizeof(TestData), 103);
  _ringbuffer_fill2(&rb, 103, 0, TRUE);

  ring_buffer_pop(&rb);

  td_tail = ring_buffer_tail(&rb);
  td_tail->idx = 103;

  assert_true(ring_buffer_push(&rb) == td_tail, "Push should return last tail.");

  assert_test_data_idx_range_in(&rb, 1, 103);

  ring_buffer_free(&rb);
}
示例#5
0
static Bookmark *
late_ack_tracker_request_bookmark(AckTracker *s)
{
  LateAckTracker *self = (LateAckTracker *)s;

  _late_tracker_lock(self);
    {
      self->pending_ack_record = ring_buffer_tail(&self->ack_record_storage);
    }
  _late_tracker_unlock(self);

  if (self->pending_ack_record)
    {
      self->pending_ack_record->bookmark.persist_state = s->source->super.cfg->state;

      self->pending_ack_record->super.tracker = (AckTracker *)self;

      return &(self->pending_ack_record->bookmark);
    }

  return NULL;
}