2012-04-14 11:52:56 +08:00
|
|
|
/*
|
|
|
|
* File : rtservice.h
|
|
|
|
* This file is part of RT-Thread RTOS
|
|
|
|
* COPYRIGHT (C) 2006 - 2012, RT-Thread Development Team
|
|
|
|
*
|
2013-06-24 17:06:09 +08:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2012-04-14 11:52:56 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2006-03-16 Bernard the first version
|
|
|
|
* 2006-09-07 Bernard move the kservice APIs to rtthread.h
|
|
|
|
* 2007-06-27 Bernard fix the rt_list_remove bug
|
|
|
|
* 2012-03-22 Bernard rename kservice.h to rtservice.h
|
|
|
|
*/
|
|
|
|
|
2012-10-13 11:26:25 +08:00
|
|
|
#ifndef __RT_SERVICE_H__
|
|
|
|
#define __RT_SERVICE_H__
|
|
|
|
|
2012-04-14 11:52:56 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup KernelService
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*@{*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief initialize a list object
|
|
|
|
*/
|
|
|
|
#define RT_LIST_OBJECT_INIT(object) { &(object), &(object) }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief initialize a list
|
|
|
|
*
|
|
|
|
* @param l list to be initialized
|
|
|
|
*/
|
|
|
|
rt_inline void rt_list_init(rt_list_t *l)
|
|
|
|
{
|
2012-09-05 13:42:12 +08:00
|
|
|
l->next = l->prev = l;
|
2012-04-14 11:52:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief insert a node after a list
|
|
|
|
*
|
|
|
|
* @param l list to insert it
|
|
|
|
* @param n new node to be inserted
|
|
|
|
*/
|
|
|
|
rt_inline void rt_list_insert_after(rt_list_t *l, rt_list_t *n)
|
|
|
|
{
|
2012-09-05 13:42:12 +08:00
|
|
|
l->next->prev = n;
|
|
|
|
n->next = l->next;
|
2012-04-14 11:52:56 +08:00
|
|
|
|
2012-09-05 13:42:12 +08:00
|
|
|
l->next = n;
|
|
|
|
n->prev = l;
|
2012-04-14 11:52:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief insert a node before a list
|
|
|
|
*
|
|
|
|
* @param n new node to be inserted
|
|
|
|
* @param l list to insert it
|
|
|
|
*/
|
|
|
|
rt_inline void rt_list_insert_before(rt_list_t *l, rt_list_t *n)
|
|
|
|
{
|
2012-09-05 13:42:12 +08:00
|
|
|
l->prev->next = n;
|
|
|
|
n->prev = l->prev;
|
2012-04-14 11:52:56 +08:00
|
|
|
|
2012-09-05 13:42:12 +08:00
|
|
|
l->prev = n;
|
|
|
|
n->next = l;
|
2012-04-14 11:52:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief remove node from list.
|
|
|
|
* @param n the node to remove from the list.
|
|
|
|
*/
|
|
|
|
rt_inline void rt_list_remove(rt_list_t *n)
|
|
|
|
{
|
2012-09-05 13:42:12 +08:00
|
|
|
n->next->prev = n->prev;
|
|
|
|
n->prev->next = n->next;
|
2012-04-14 11:52:56 +08:00
|
|
|
|
2012-09-05 13:42:12 +08:00
|
|
|
n->next = n->prev = n;
|
2012-04-14 11:52:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief tests whether a list is empty
|
|
|
|
* @param l the list to test.
|
|
|
|
*/
|
|
|
|
rt_inline int rt_list_isempty(const rt_list_t *l)
|
|
|
|
{
|
2012-09-05 13:42:12 +08:00
|
|
|
return l->next == l;
|
2012-04-14 11:52:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief get the struct for this entry
|
|
|
|
* @param node the entry point
|
|
|
|
* @param type the type of structure
|
|
|
|
* @param member the name of list in structure
|
|
|
|
*/
|
|
|
|
#define rt_list_entry(node, type, member) \
|
|
|
|
((type *)((char *)(node) - (unsigned long)(&((type *)0)->member)))
|
|
|
|
|
|
|
|
/*@}*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2012-10-13 11:26:25 +08:00
|
|
|
|
|
|
|
#endif
|