Blame include/list.h

Packit 6c4009
/* Copyright (C) 2002-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _LIST_H
Packit 6c4009
#define _LIST_H	1
Packit 6c4009
Packit 6c4009
/* Internal: doubly linked lists.  */
Packit 6c4009
Packit 6c4009
/* The definitions of this file are adopted from those which can be
Packit 6c4009
   found in the Linux kernel headers to enable people familiar with
Packit 6c4009
   the latter find their way in these sources as well.  */
Packit 6c4009
Packit 6c4009
#include <list_t.h>
Packit 6c4009
#include <atomic.h>
Packit 6c4009
Packit 6c4009
/* Define a variable with the head and tail of the list.  */
Packit 6c4009
#define LIST_HEAD(name) \
Packit 6c4009
  list_t name = { &(name), &(name) }
Packit 6c4009
Packit 6c4009
/* Initialize a new list head.  */
Packit 6c4009
#define INIT_LIST_HEAD(ptr) \
Packit 6c4009
  (ptr)->next = (ptr)->prev = (ptr)
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Add new element at the head of the list.  */
Packit 6c4009
static inline void
Packit 6c4009
list_add (list_t *newp, list_t *head)
Packit 6c4009
{
Packit 6c4009
  newp->next = head->next;
Packit 6c4009
  newp->prev = head;
Packit 6c4009
  head->next->prev = newp;
Packit 6c4009
  atomic_write_barrier ();
Packit 6c4009
  head->next = newp;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Remove element from list.  */
Packit 6c4009
static inline void
Packit 6c4009
list_del (list_t *elem)
Packit 6c4009
{
Packit 6c4009
  elem->next->prev = elem->prev;
Packit 6c4009
  elem->prev->next = elem->next;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Join two lists.  */
Packit 6c4009
static inline void
Packit 6c4009
list_splice (list_t *add, list_t *head)
Packit 6c4009
{
Packit 6c4009
  /* Do nothing if the list which gets added is empty.  */
Packit 6c4009
  if (add != add->next)
Packit 6c4009
    {
Packit 6c4009
      add->next->prev = head;
Packit 6c4009
      add->prev->next = head->next;
Packit 6c4009
      head->next->prev = add->prev;
Packit 6c4009
      head->next = add->next;
Packit 6c4009
    }
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Get typed element from list at a given position.  */
Packit 6c4009
#define list_entry(ptr, type, member) \
Packit 6c4009
  ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member)))
Packit 6c4009
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Iterate forward over the elements of the list.  */
Packit 6c4009
#define list_for_each(pos, head) \
Packit 6c4009
  for (pos = (head)->next; pos != (head); pos = pos->next)
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Iterate forward over the elements of the list.  */
Packit 6c4009
#define list_for_each_prev(pos, head) \
Packit 6c4009
  for (pos = (head)->prev; pos != (head); pos = pos->prev)
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Iterate backwards over the elements list.  The list elements can be
Packit 6c4009
   removed from the list while doing this.  */
Packit 6c4009
#define list_for_each_prev_safe(pos, p, head) \
Packit 6c4009
  for (pos = (head)->prev, p = pos->prev; \
Packit 6c4009
       pos != (head); \
Packit 6c4009
       pos = p, p = pos->prev)
Packit 6c4009
Packit 6c4009
#endif	/* list.h */