123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- #pragma once
- #ifndef GLIB_H
- #define GLIB_H
- #include <stdbool.h>
- #define NULL 0
- #define sti() __asm__ __volatile__("sti\n\t" :: \
- : "memory")
- #define cli() __asm__ __volatile__("cli\n\t" :: \
- : "memory")
- #define nop() __asm__ __volatile__("nop\n\t")
- #define io_mfence() __asm__ __volatile__("mfence\n\t" :: \
- : "memory")
- #define io_sfence() __asm__ __volatile__("sfence\n\t" :: \
- : "memory")
- #define io_lfence() __asm__ __volatile__("lfence\n\t" :: \
- : "memory")
- #define ABS(x) ((x) > 0 ? (x) : -(x))
- struct List
- {
- struct List *prev, *next;
- };
- static inline void list_init(struct List *list)
- {
- list->next = list;
- list->prev = list;
- }
- static inline void list_add(struct List *entry, struct List *node)
- {
-
- node->next = entry->next;
- node->next->prev = node;
- node->prev = entry;
- entry->next = node;
- }
- static inline void list_append(struct List *entry, struct List *node)
- {
-
- struct List *tail = entry->prev;
- list_add(tail, node);
- }
- static inline void list_del(struct List *entry)
- {
-
- entry->prev->next = entry->next;
- entry->next = entry->prev;
- }
- static inline bool list_empty(struct List *entry)
- {
-
- if (entry->prev == entry->next)
- return true;
- else
- return false;
- }
- static inline int strlen(char *s)
- {
- register int __res = 0;
- while (s[__res] != '\0')
- {
- ++__res;
- }
- return __res;
- }
- #endif
|