summaryrefslogtreecommitdiffstats
path: root/.gitignore
AgeCommit message (Expand)AuthorFilesLines
2016-06-19gitignore gtagsKeith Burns (alagalah)1-0/+4
2016-06-14gitignore change due to DPDK download suffix changeKeith Burns (alagalah)1-0/+1
2016-05-13VPP-57 Add Doxygen to VPPChris Luke1-0/+3
2016-05-12Generate jvpp sources in build-rootMaros Marsalek1-5/+0
2016-05-02HONEYCOMB-10: jVpp - the new java API. C code and jar file generationMarek Gradzki1-0/+6
2016-04-24Updated .gitignore for Python API generated fileKeith Burns (alagalah)1-0/+1
2016-04-12Add unit test infrastructure for LISP protocolFilip Tehlar1-0/+1
2016-03-25Add build-root/*.rpm to .gitignoreEd Warnicke1-0/+1
2016-03-18add ctags and cscope files to .gitignoreDamjan Marion1-0/+4
2016-03-04gitignoreMaros Marsalek1-0/+5
2016-02-01Add a vpp-dpdk-dev package, enable plugins to use dpdk APIs directlyDave Barach1-0/+1
2016-01-31Git ignore additionsKeith Burns (alagalah)1-0/+5
2015-12-23ylwrap is also autotools autogenerated fileDamjan Marion1-0/+1
2015-12-16Update .gitignore to ignore autotools filesEd Warnicke1-1/+25
2015-12-08Initial commit of vpp code.v1.0.0Ed Warnicke1-0/+15
nt-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 * Copyright (c) 2018 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef included_ring_h
#define included_ring_h

#include <vppinfra/error.h>
#include <vppinfra/format.h>
#include <vppinfra/vec.h>
#include <vppinfra/vector.h>

typedef struct
{
  u32 next, n_enq;
} clib_ring_header_t;

always_inline clib_ring_header_t *
clib_ring_header (void *v)
{
  return vec_aligned_header (v, sizeof (clib_ring_header_t), sizeof (void *));
}

always_inline void
clib_ring_new_inline (void **p, u32 elt_bytes, u32 size, u32 align)
{
  void *v;
  clib_ring_header_t *h;

  v = _vec_resize ((void *) 0,
		   /* length increment */ size,
		   /* data bytes */ elt_bytes * size,
		   /* header bytes */ sizeof (h[0]),
		   /* data align */ align);

  h = clib_ring_header (v);
  h->next = 0;
  h->n_enq = 0;
  p[0] = v;
}

#define clib_ring_new_aligned(ring, size, align) \
{ clib_ring_new_inline ((void **)&(ring), sizeof(ring[0]), size, align); }

#define clib_ring_new(ring, size) \
{ clib_ring_new_inline ((void **)&(ring), sizeof(ring[0]), size, 0);}

#define clib_ring_free(f) vec_free_h((f), sizeof(clib_ring_header_t))

always_inline u32
clib_ring_n_enq (void *v)
{
  clib_ring_header_t *h = clib_ring_header (v);
  return h->n_enq;
}

always_inline void *
clib_ring_get_last_inline (void *v, u32 elt_bytes, int enqueue)
{
  clib_ring_header_t *h = clib_ring_header (v);
  u32 slot;

  if (enqueue)
    {
      if (h->n_enq == _vec_len (v))
	return 0;
      slot = h->next;
      h->n_enq++;
      h->next++;
      if (h->next == _vec_len (v))
	h->next = 0;
    }
  else
    {
      if (h->n_enq == 0)
	return 0;
      slot = h->next == 0 ? _vec_len (v) - 1 : h->next - 1;
    }

  return (void *) ((u8 *) v + elt_bytes * slot);
}

#define clib_ring_enq(ring) \
clib_ring_get_last_inline (ring, sizeof(ring[0]), 1)

#define clib_ring_get_last(ring) \
clib_ring_get_last_inline (ring, sizeof(ring[0]), 0)

always_inline void *
clib_ring_get_first_inline (void *v, u32 elt_bytes, int dequeue)
{
  clib_ring_header_t *h = clib_ring_header (v);
  u32 slot;

  if (h->n_enq == 0)
    return 0;

  if (h->n_enq > h->next)
    slot = _vec_len (v) + h->next - h->n_enq;
  else
    slot = h->next - h->n_enq;

  if (dequeue)
    h->n_enq--;

  return (void *) ((u8 *) v + elt_bytes * slot);
}

#define clib_ring_deq(ring) \
clib_ring_get_first_inline (ring, sizeof(ring[0]), 1)

#define clib_ring_get_first(ring) \
clib_ring_get_first_inline (ring, sizeof(ring[0]), 0)

#endif /* included_ring_h */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */