Commit 471f9b1a authored by Maria Matejka's avatar Maria Matejka
Browse files

TMP

parent 538b879a
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -103,32 +103,32 @@ extern _Thread_local u64 worker_id;
 * There is 
 *
 * */
#define CIRCULAR_BUFFER_PTR struct { \
#define CIRCULAR_QUEUE_PTR struct { \
  _Atomic u64 acquire, release; \
  _Atomic uint waiting; \
  struct semaphore *sem; \
}

#define CIRCULAR_BUFFER_N(type_, size_, ptrs_) struct { \
#define CIRCULAR_QUEUE_N(type_, size_, ptrs_) struct { \
  type_ buffer[size_]; \
  CIRCULAR_BUFFER_PTR ptr[ptrs_]; \
  CIRCULAR_QUEUE_PTR ptr[ptrs_]; \
}

#define CIRCULAR_BUFFER(type_, size_) CIRCULAR_BUFFER_N(type_, size_, 2)
#define CIRCULAR_QUEUE(type_, size_) CIRCULAR_QUEUE_N(type_, size_, 2)

#define CIRCULAR_BUFFER_PTR_INIT(ptr_, pool_) do { \
#define CIRCULAR_QUEUE_PTR_INIT(ptr_, pool_) do { \
  (ptr_)->acquire = (ptr_)->release = ATOMIC_VAR_INIT(0); \
  (ptr_)->waiting = ATOMIC_VAR_INIT(0); \
  (ptr_)->sem = semaphore_new(pool_, 0); \
} while (0)

#define CIRCULAR_BUFFER_INIT(buf_, pool_) do { \
#define CIRCULAR_QUEUE_INIT(buf_, pool_) do { \
  memset((buf_)->buffer, 0, sizeof((buf_)->buffer)); \
  for (uint i_=0; i_<sizeof((buf_)->ptr) / sizeof((buf_)->ptr[0]); i_++) \
    CIRCULAR_BUFFER_PTR_INIT(&((buf_)->ptr[i_]), pool_); \
    CIRCULAR_QUEUE_PTR_INIT(&((buf_)->ptr[i_]), pool_); \
} while (0)

#define CIRCULAR_BUFFER_CLEANUP(buf_) do { \
#define CIRCULAR_QUEUE_CLEANUP(buf_) do { \
  u64 val = atomic_load(&((buf_)->ptr[0].acquire)); \
  for (uint i_=0; i_<sizeof((buf_)->ptr) / sizeof((buf_)->ptr[0]); i_++) { \
    ASSERT(val == atomic_load(&((buf_)->ptr[i_].acquire))); \
+2 −2
Original line number Diff line number Diff line
@@ -168,7 +168,7 @@ proto_add_channel(struct proto *p, struct channel_config *cf)
  c->last_tx_filter_change = current_time();
  c->reloadable = 1;

  CIRCULAR_BUFFER_INIT(&c->pending_imports, proto_pool);
  CIRCULAR_QUEUE_INIT(&c->pending_imports, proto_pool);

  CALL(c->channel->init, c, cf);

@@ -186,7 +186,7 @@ proto_remove_channel(struct proto *p, struct channel *c)

  PD(p, "Channel %s removed", c->name);

  CIRCULAR_BUFFER_CLEANUP(&c->pending_imports);
  CIRCULAR_QUEUE_CLEANUP(&c->pending_imports);

  rem_node(&c->n);
  mb_free(c);
+1 −1
Original line number Diff line number Diff line
@@ -538,7 +538,7 @@ struct channel {
  btime last_tx_filter_change;

  /* Circular buffer for pending imports */
  CIRCULAR_BUFFER_N(struct rte_update_data, CHANNEL_QUEUE_SIZE, 3) pending_imports;
  CIRCULAR_QUEUE_N(struct rte_update_data, CHANNEL_QUEUE_SIZE, 3) pending_imports;

  struct rtable *in_table;		/* Internal table for received routes */
  struct event *reload_event;		/* Event responsible for reloading from in_table */