Beispiel #1
0
guint32
ring_buffer_get_continual_range_length(RingBuffer *self, RingBufferIsContinuousPredicate pred)
{
  guint32 r = 0, i;

  g_assert(self->buffer != NULL);

  for (i = 0; i < ring_buffer_count(self); i++)
    {
      if (!pred(ring_buffer_element_at(self, i)))
        {
          break;
        }
      ++r;
    }

  return r;
}
Beispiel #2
0
static inline void
_drop_range(LateAckTracker *self, guint32 n)
{
  int i;
  LateAckRecord *ack_rec;

  for (i = 0; i < n; i++)
    {
      ack_rec = ring_buffer_element_at(&self->ack_record_storage, i);
      ack_rec->acked = FALSE;

      late_ack_record_destroy(ack_rec);

      ack_rec->bookmark.save = NULL;
      ack_rec->bookmark.destroy = NULL;
    }
  ring_buffer_drop(&self->ack_record_storage, n);
}
Beispiel #3
0
static void
test_element_at()
{
  RingBuffer rb;
  size_t i;
  TestData *td;

  _ringbuffer_init(&rb);

  _ringbuffer_fill(&rb, capacity, 0, TRUE);

  for ( i = 0; i < ring_buffer_count(&rb); i++ )
    {
      td = ring_buffer_element_at(&rb, i);
      assert_true(td != NULL, "invalid element, i=%d", i);
      assert_true(td->idx == i, "invalid order, actual=%d, expected=%d", td->idx, i);
    }

  ring_buffer_free(&rb);
}
Beispiel #4
0
static void
late_ack_tracker_manage_msg_ack(AckTracker *s, LogMessage *msg, AckType ack_type)
{
  LateAckTracker *self = (LateAckTracker *)s;
  LateAckRecord *ack_rec = (LateAckRecord *)msg->ack_record;
  LateAckRecord *last_in_range = NULL;
  guint32 ack_range_length = 0;

  ack_rec->acked = TRUE;

  if (ack_type == AT_SUSPENDED)
    log_source_flow_control_suspend(self->super.source);

  late_ack_tracker_lock(s);
  {
    ack_range_length = _get_continuous_range_length(self);
    if (ack_range_length > 0)
      {
        last_in_range = ring_buffer_element_at(&self->ack_record_storage, ack_range_length - 1);
        if (ack_type != AT_ABORTED)
          {
            Bookmark *bookmark = &(last_in_range->bookmark);
            bookmark->save(bookmark);
          }
        _drop_range(self, ack_range_length);

        if (ack_type == AT_SUSPENDED)
          log_source_flow_control_adjust_when_suspended(self->super.source, ack_range_length);
        else
          log_source_flow_control_adjust(self->super.source, ack_range_length);

        if (ring_buffer_is_empty(&self->ack_record_storage))
          late_ack_tracker_on_all_acked_call(s);
      }
  }
  late_ack_tracker_unlock(s);

  log_msg_unref(msg);
  log_pipe_unref((LogPipe *)self->super.source);
}