Example #1
0
void
late_ack_tracker_free(AckTracker *s)
{
  LateAckTracker *self = (LateAckTracker *)s;
  guint32 count = ring_buffer_count(&self->ack_record_storage);

  g_static_mutex_free(&self->storage_mutex);

  _drop_range(self, count);

  ring_buffer_free(&self->ack_record_storage);
  g_free(self);
}
Example #2
0
static void
test_init_buffer_state()
{
  RingBuffer rb;

  _ringbuffer_init(&rb);

  assert_false(ring_buffer_is_full(&rb), "buffer should not be full");
  assert_true(ring_buffer_is_empty(&rb), "buffer should be empty");
  assert_true(ring_buffer_count(&rb) == 0, "buffer should be empty");
  assert_true(ring_buffer_capacity(&rb) == capacity, "invalid buffer capacity");

  ring_buffer_free(&rb);
}
Example #3
0
/**
 * detector_exit - Standard module cleanup code
 */
static void detector_exit(void)
{
	int err;

	if (enabled) {
		enabled = 0;
		err = stop_kthread();
		if (err)
			printk(KERN_ERR BANNER "cannot stop kthread\n");
	}

	free_debugfs();
	ring_buffer_free(ring_buffer);	/* free up the ring buffer */

}
Example #4
0
static void
test_drop_elements()
{
  RingBuffer rb;
  const int rb_capacity = 103;
  const int drop = 31;

  ring_buffer_alloc(&rb, sizeof(TestData), rb_capacity);

  _ringbuffer_fill(&rb, rb_capacity, 1, TRUE);

  ring_buffer_drop(&rb, drop);
  assert_true(ring_buffer_count(&rb) == (rb_capacity - drop), "drop failed");

  ring_buffer_free(&rb);
}
Example #5
0
int main(int argc, const char *argv[])
{
	t_ring_buffer *r = NULL;
	int elem1 = 4;
	int elem2 = 6;
	int elem3 = 2;
	int elem4 = 3;
	gpointer oldelem = NULL;
	gpointer popelem = NULL;

	g_message("Test RingBuffer");
	
	r = ring_buffer_new(2);
	g_assert(NULL != r);

	oldelem = ring_buffer_push(r, &elem1);
	g_assert(NULL == oldelem);
	g_assert(1 == ring_buffer_stored_elements(r));

	oldelem = ring_buffer_push(r, &elem2);
	g_assert(NULL == oldelem);
	g_assert(2 == ring_buffer_stored_elements(r));
	
	oldelem = ring_buffer_push(r, &elem3);
	g_assert(NULL != oldelem && *((int *)oldelem) == elem1);
	g_assert(2 == ring_buffer_stored_elements(r));
	
	oldelem = ring_buffer_push(r, &elem4);
	g_assert(NULL != oldelem && *((int *)oldelem) == elem2);

	popelem = ring_buffer_pop(r);
	g_assert(NULL != popelem && *((int *)popelem) == elem4);

	popelem = ring_buffer_pop(r);
	g_assert(NULL != popelem && *((int *)popelem) == elem3);

	popelem = ring_buffer_pop(r);
	g_assert(NULL == popelem);
	g_assert(0 == ring_buffer_stored_elements(r));

	r = ring_buffer_free(r);
	g_assert(NULL == r);

	g_message("Test RingBuffer complete");

	return 0;
}
Example #6
0
static void
test_zero_length_continual_range()
{
  RingBuffer rb;
  TestData *td;

  _ringbuffer_init(&rb);

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

  td = ring_buffer_element_at(&rb, 0);
  td->ack = FALSE;

  assert_continual_range_length_equals(&rb, 0);

  ring_buffer_free(&rb);
}
Example #7
0
static GRilIO *create_io(GIOChannel *channel, GIOFlags flags)
{
	GRilIO *io;

	if (channel == NULL)
		return NULL;

	io = g_try_new0(GRilIO, 1);
	if (io == NULL)
		return io;

	io->ref_count = 1;
	io->debugf = NULL;

	if (flags & G_IO_FLAG_NONBLOCK) {
		io->max_read_attempts = 3;
		io->use_write_watch = TRUE;
	} else {
		io->max_read_attempts = 1;
		io->use_write_watch = FALSE;
	}

	io->buf = ring_buffer_new(8192);

	if (!io->buf)
		goto error;

	if (!g_ril_util_setup_io(channel, flags))
		goto error;

	io->channel = channel;
	io->read_watch = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT,
				G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
				received_data, io,
				read_watcher_destroy_notify);

	return io;

error:
	if (io->buf)
		ring_buffer_free(io->buf);

	g_free(io);

	return NULL;
}
Example #8
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);
}
Example #9
0
static void
test_elements_ordering()
{
  RingBuffer rb;
  TestData *td;
  int start_from = 10;
  int cnt = 0;

  _ringbuffer_init(&rb);

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

  while ( (td = ring_buffer_pop(&rb)) )
    {
      assert_true((cnt + start_from) == td->idx, "wrong order; %d != %d", cnt, td->idx);
      ++cnt;
    }

  ring_buffer_free(&rb);
}
Example #10
0
static void
late_ack_tracker_free(AckTracker *s)
{
  LateAckTracker *self = (LateAckTracker *)s;
  AckTrackerOnAllAcked *handler = &self->on_all_acked;

  if (handler->user_data_free_fn && handler->user_data)
    {
      handler->user_data_free_fn(handler->user_data);
    }

  guint32 count = ring_buffer_count(&self->ack_record_storage);

  g_static_mutex_free(&self->storage_mutex);

  _drop_range(self, count);

  ring_buffer_free(&self->ack_record_storage);
  g_free(self);
}
Example #11
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);
}
Example #12
0
static void read_watcher_destroy_notify(gpointer user_data)
{
	GRilIO *io = user_data;

	ring_buffer_free(io->buf);
	io->buf = NULL;

	io->debugf = NULL;
	io->debug_data = NULL;

	io->read_watch = 0;
	io->read_handler = NULL;
	io->read_data = NULL;

	io->channel = NULL;

	if (io->destroyed)
		g_free(io);
	else if (io->user_disconnect)
		io->user_disconnect(io->user_disconnect_data);
}
Example #13
0
static void
test_pop_all_pushed_element_in_correct_order()
{
  RingBuffer rb;
  int cnt = 0;
  const int start_from = 1;
  TestData *td = NULL;

  _ringbuffer_init(&rb);

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

  while ((td = ring_buffer_pop(&rb)))
    {
      assert_true((cnt+start_from) == td->idx, "wrong order; %d != %d", td->idx, cnt);
      ++cnt;
    }

  assert_true(cnt == capacity, "cannot read all element, %d < %d", cnt, capacity);

  ring_buffer_free(&rb);
}
Example #14
0
static void
test_ring_buffer_is_full()
{
  RingBuffer rb;
  int i;
  TestData *last = NULL;

  _ringbuffer_init(&rb);

  for (i = 1; !ring_buffer_is_full(&rb); i++)
    {
      TestData *td = ring_buffer_push(&rb);
      assert_true(td != NULL, "ring_buffer_push failed");
      td->idx = i;
      last = td;
    }

  assert_true(ring_buffer_count(&rb) == capacity, "buffer count(%d) is not equal to capacity(%d)", ring_buffer_count(&rb), capacity);
  assert_true(last->idx == capacity, "buffer is not full, number of inserted items: %d, capacity: %d", last->idx, capacity);

  ring_buffer_free(&rb);
}
Example #15
0
void g_at_hdlc_unref(GAtHDLC *hdlc)
{
	if (!hdlc)
		return;

	if (g_atomic_int_dec_and_test(&hdlc->ref_count) == FALSE)
		return;

	if (hdlc->record_fd > fileno(stderr)) {
		close(hdlc->record_fd);
		hdlc->record_fd = -1;
	}

	g_at_io_unref(hdlc->io);
	hdlc->io = NULL;

	ring_buffer_free(hdlc->write_buffer);
	g_free(hdlc->decode_buffer);

	if (hdlc->in_read_handler)
		hdlc->destroyed = TRUE;
	else
		g_free(hdlc);
}
static void
Buffer_dealloc(Buffer* self)
{
    ring_buffer_free (self->buffer);
    self->ob_type->tp_free ((PyObject*) self);
}
Example #17
0
void free_cpu_buffers(void)
{
	if (op_ring_buffer)
		ring_buffer_free(op_ring_buffer);
	op_ring_buffer = NULL;
}
Example #18
0
SEXP R_ring_buffer_free(SEXP extPtr, SEXP bytes) {
  return ScalarInteger(ring_buffer_free(ring_buffer_get(extPtr, 1),
                                          logical_scalar(bytes)));
}
Example #19
0
void
_rb_free(void *privdata, const void *rb) {
  (void) privdata;
  ring_buffer_free(rb);
}