-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangjipeng
committed
Jan 24, 2025
1 parent
655ac1d
commit d4b6e74
Showing
11 changed files
with
715 additions
and
591 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright (c) 2024, Zhang Ji Peng | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef _PSX_LIST_H_ | ||
#define _PSX_LIST_H_ | ||
|
||
#if defined(__GNUC__) | ||
#define INLINE inline | ||
#elif defined(_MSC_VER) | ||
#define INLINE __inline | ||
#else | ||
#define INLINE | ||
#endif | ||
|
||
struct list_hdr { | ||
struct list_hdr* next; | ||
struct list_hdr* prev; | ||
}; | ||
|
||
/* all function return 0 is success or true, -1 is fail or false. */ | ||
|
||
static INLINE void list_init(struct list_hdr* head) | ||
{ | ||
head->next = head; | ||
head->prev = head; | ||
} | ||
|
||
static INLINE int list_empty(const struct list_hdr* head) | ||
{ | ||
return head->next == head ? 0 : -1; | ||
} | ||
|
||
#define list_add(head, value) \ | ||
list_add_entry((struct list_hdr*)(head), (struct list_hdr*)(value)) | ||
|
||
static INLINE void list_add_entry(struct list_hdr* head, struct list_hdr* value) | ||
{ | ||
register struct list_hdr* next = head->next; | ||
|
||
next->prev = value; | ||
value->next = next; | ||
value->prev = head; | ||
head->next = value; | ||
} | ||
|
||
#define list_add_tail(head, value) \ | ||
list_add_tail_entry((struct list_hdr*)(head), (struct list_hdr*)(value)) | ||
|
||
static INLINE void list_add_tail_entry(struct list_hdr* head, struct list_hdr* value) | ||
{ | ||
register struct list_hdr* prev = head->prev; | ||
|
||
head->prev = value; | ||
value->next = head; | ||
value->prev = prev; | ||
prev->next = value; | ||
} | ||
|
||
#define list_remove(entry) \ | ||
list_remove_entry((struct list_hdr*)(entry)) | ||
|
||
static INLINE void list_remove_entry(struct list_hdr* entry) | ||
{ | ||
entry->next->prev = entry->prev; | ||
entry->prev->next = entry->next; | ||
entry->next = entry->prev = NULL; | ||
} | ||
|
||
#define list_for_each(head, iterator) \ | ||
for ((iterator) = (head)->next; (iterator) != (head); (iterator) = (iterator)->next) | ||
|
||
#define list_for_each_start_with(head, start, iterator) \ | ||
for ((iterator) = ((struct list_hdr*)(start))->next; (iterator) != (head); (iterator) = (iterator)->next) | ||
|
||
#endif /*_PSX_LIST_H_*/ |
Oops, something went wrong.