Revision 42270035c6550101f7dc742a630c2590dd2d3ae0 authored by Linus Torvalds on 04 March 2007, 21:15:48 UTC, committed by Linus Torvalds on 04 March 2007, 21:15:48 UTC
* master.kernel.org:/home/rmk/linux-2.6-arm: (30 commits)
  [ARM] Acorn: move the i2c bus driver into drivers/i2c
  [ARM] ARM SCSI: Don't try to dma_map_sg too many scatterlist entries
  [ARM] ARM FAS216: don't modify scsi_cmnd request_bufflen
  [ARM] rtc-pcf8583: Final fixes for this RTC on RiscPC
  [ARM] rtc-pcf8583: correct month and year offsets
  [ARM] rtc-pcf8583: don't use BCD_TO_BIN/BIN_TO_BCD
  [ARM] EBSA110: Work around build errors
  [ARM] 4241/1: Define mb() as compiler barrier on a uniprocessor system
  [ARM] 4239/1: S3C24XX: Update kconfig entries for PM
  [ARM] 4238/1: S3C24XX: docs: update suspend and resume
  [ARM] 4237/2: oprofile: Always allow backtraces on ARM
  [ARM] Yet more asm/apm-emulation.h stuff
  ARM: OMAP: Add missing get_irqnr_preamble and arch_ret_to_user for omap2
  ARM: OMAP: Use linux/delay.h not asm/delay.h
  ARM: OMAP: Remove obsolete alsa typedefs
  ARM: OMAP: omap1510->15xx conversions needed for sx1
  ARM: OMAP: Add missing includes to board-nokia770
  ARM: OMAP: Workqueue changes for board-h4.c
  ARM: OMAP: dmtimer.c omap1 register fix
  ARM: OMAP: board-nokia770: correct lcd name
  ...
2 parent s 2c89a8d + 8d91cba
Raw File
plist.c
/*
 * lib/plist.c
 *
 * Descending-priority-sorted double-linked list
 *
 * (C) 2002-2003 Intel Corp
 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>.
 *
 * 2001-2005 (c) MontaVista Software, Inc.
 * Daniel Walker <dwalker@mvista.com>
 *
 * (C) 2005 Thomas Gleixner <tglx@linutronix.de>
 *
 * Simplifications of the original code by
 * Oleg Nesterov <oleg@tv-sign.ru>
 *
 * Licensed under the FSF's GNU Public License v2 or later.
 *
 * Based on simple lists (include/linux/list.h).
 *
 * This file contains the add / del functions which are considered to
 * be too large to inline. See include/linux/plist.h for further
 * information.
 */

#include <linux/plist.h>
#include <linux/spinlock.h>

#ifdef CONFIG_DEBUG_PI_LIST

static void plist_check_prev_next(struct list_head *t, struct list_head *p,
				  struct list_head *n)
{
	if (n->prev != p || p->next != n) {
		printk("top: %p, n: %p, p: %p\n", t, t->next, t->prev);
		printk("prev: %p, n: %p, p: %p\n", p, p->next, p->prev);
		printk("next: %p, n: %p, p: %p\n", n, n->next, n->prev);
		WARN_ON(1);
	}
}

static void plist_check_list(struct list_head *top)
{
	struct list_head *prev = top, *next = top->next;

	plist_check_prev_next(top, prev, next);
	while (next != top) {
		prev = next;
		next = prev->next;
		plist_check_prev_next(top, prev, next);
	}
}

static void plist_check_head(struct plist_head *head)
{
	WARN_ON(!head->lock);
	if (head->lock)
		WARN_ON_SMP(!spin_is_locked(head->lock));
	plist_check_list(&head->prio_list);
	plist_check_list(&head->node_list);
}

#else
# define plist_check_head(h)	do { } while (0)
#endif

/**
 * plist_add - add @node to @head
 *
 * @node:	&struct plist_node pointer
 * @head:	&struct plist_head pointer
 */
void plist_add(struct plist_node *node, struct plist_head *head)
{
	struct plist_node *iter;

	plist_check_head(head);
	WARN_ON(!plist_node_empty(node));

	list_for_each_entry(iter, &head->prio_list, plist.prio_list) {
		if (node->prio < iter->prio)
			goto lt_prio;
		else if (node->prio == iter->prio) {
			iter = list_entry(iter->plist.prio_list.next,
					struct plist_node, plist.prio_list);
			goto eq_prio;
		}
	}

lt_prio:
	list_add_tail(&node->plist.prio_list, &iter->plist.prio_list);
eq_prio:
	list_add_tail(&node->plist.node_list, &iter->plist.node_list);

	plist_check_head(head);
}

/**
 * plist_del - Remove a @node from plist.
 *
 * @node:	&struct plist_node pointer - entry to be removed
 * @head:	&struct plist_head pointer - list head
 */
void plist_del(struct plist_node *node, struct plist_head *head)
{
	plist_check_head(head);

	if (!list_empty(&node->plist.prio_list)) {
		struct plist_node *next = plist_first(&node->plist);

		list_move_tail(&next->plist.prio_list, &node->plist.prio_list);
		list_del_init(&node->plist.prio_list);
	}

	list_del_init(&node->plist.node_list);

	plist_check_head(head);
}
back to top