fixed include directives to avoid having to pass to much include paths in usage scripts
This commit is contained in:
parent
d2c4acf6e2
commit
2fe683b79d
File diff suppressed because it is too large
Load Diff
|
@ -1,74 +1,74 @@
|
||||||
/************************************************************//**
|
/************************************************************//**
|
||||||
*
|
*
|
||||||
* @file: platform_memory.h
|
* @file: platform_memory.h
|
||||||
* @author: Martin Fouilleul
|
* @author: Martin Fouilleul
|
||||||
* @date: 10/09/2021
|
* @date: 10/09/2021
|
||||||
* @revision:
|
* @revision:
|
||||||
*
|
*
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
#ifndef __PLATFORM_MEMORY_H_
|
#ifndef __PLATFORM_MEMORY_H_
|
||||||
#define __PLATFORM_MEMORY_H_
|
#define __PLATFORM_MEMORY_H_
|
||||||
|
|
||||||
#include"typedefs.h"
|
#include"util/typedefs.h"
|
||||||
#include"platform.h"
|
#include"platform.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
//NOTE(martin): base allocator
|
//NOTE(martin): base allocator
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
typedef struct mem_base_allocator mem_base_allocator;
|
typedef struct mem_base_allocator mem_base_allocator;
|
||||||
|
|
||||||
typedef void*(*mem_reserve_function)(mem_base_allocator* context, u64 size);
|
typedef void*(*mem_reserve_function)(mem_base_allocator* context, u64 size);
|
||||||
typedef void(*mem_modify_function)(mem_base_allocator* context, void* ptr, u64 size);
|
typedef void(*mem_modify_function)(mem_base_allocator* context, void* ptr, u64 size);
|
||||||
|
|
||||||
typedef struct mem_base_allocator
|
typedef struct mem_base_allocator
|
||||||
{
|
{
|
||||||
mem_reserve_function reserve;
|
mem_reserve_function reserve;
|
||||||
mem_modify_function commit;
|
mem_modify_function commit;
|
||||||
mem_modify_function decommit;
|
mem_modify_function decommit;
|
||||||
mem_modify_function release;
|
mem_modify_function release;
|
||||||
|
|
||||||
} mem_base_allocator;
|
} mem_base_allocator;
|
||||||
|
|
||||||
MP_API mem_base_allocator* mem_base_allocator_default();
|
MP_API mem_base_allocator* mem_base_allocator_default();
|
||||||
|
|
||||||
#define mem_base_reserve(base, size) base->reserve(base, size)
|
#define mem_base_reserve(base, size) base->reserve(base, size)
|
||||||
#define mem_base_commit(base, ptr, size) base->commit(base, ptr, size)
|
#define mem_base_commit(base, ptr, size) base->commit(base, ptr, size)
|
||||||
#define mem_base_decommit(base, ptr, size) base->decommit(base, ptr, size)
|
#define mem_base_decommit(base, ptr, size) base->decommit(base, ptr, size)
|
||||||
#define mem_base_release(base, ptr, size) base->release(base, ptr, size)
|
#define mem_base_release(base, ptr, size) base->release(base, ptr, size)
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
//NOTE(martin): malloc/free
|
//NOTE(martin): malloc/free
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
#if PLATFORM_ORCA
|
#if PLATFORM_ORCA
|
||||||
void* malloc(size_t size);
|
void* malloc(size_t size);
|
||||||
void* realloc(void* ptr, size_t size);
|
void* realloc(void* ptr, size_t size);
|
||||||
void free(void* ptr);
|
void free(void* ptr);
|
||||||
#else
|
#else
|
||||||
#include<stdlib.h>
|
#include<stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define malloc_type(type) ((type*)malloc(sizeof(type)))
|
#define malloc_type(type) ((type*)malloc(sizeof(type)))
|
||||||
#define malloc_array(type, count) ((type*)malloc(sizeof(type)*count))
|
#define malloc_array(type, count) ((type*)malloc(sizeof(type)*count))
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
//NOTE(martin): memset / memcpy
|
//NOTE(martin): memset / memcpy
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
#if PLATFORM_ORCA
|
#if PLATFORM_ORCA
|
||||||
void* memset(void *b, int c, size_t len);
|
void* memset(void *b, int c, size_t len);
|
||||||
void* memcpy(void *restrict dst, const void *restrict src, size_t n);
|
void* memcpy(void *restrict dst, const void *restrict src, size_t n);
|
||||||
void* memmove(void *dst, const void *src, size_t len);
|
void* memmove(void *dst, const void *src, size_t len);
|
||||||
int memcmp(const void *s1, const void *s2, size_t n);
|
int memcmp(const void *s1, const void *s2, size_t n);
|
||||||
#else
|
#else
|
||||||
#include<string.h>
|
#include<string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif //__PLATFORM_MEMORY_H_
|
#endif //__PLATFORM_MEMORY_H_
|
||||||
|
|
776
src/util/lists.h
776
src/util/lists.h
|
@ -1,388 +1,388 @@
|
||||||
/************************************************************//**
|
/************************************************************//**
|
||||||
*
|
*
|
||||||
* @file: lists.h
|
* @file: lists.h
|
||||||
* @author: Martin Fouilleul
|
* @author: Martin Fouilleul
|
||||||
* @date: 22/11/2017
|
* @date: 22/11/2017
|
||||||
* @brief: Implements generic intrusive linked list and dynamic array
|
* @brief: Implements generic intrusive linked list and dynamic array
|
||||||
*
|
*
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
#ifndef __CONTAINERS_H_
|
#ifndef __CONTAINERS_H_
|
||||||
#define __CONTAINERS_H_
|
#define __CONTAINERS_H_
|
||||||
|
|
||||||
#include"macro_helpers.h"
|
#include"util/macro_helpers.h"
|
||||||
#include"platform_assert.h"
|
#include"platform/platform_assert.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define OFFSET_OF_CONTAINER(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
#define OFFSET_OF_CONTAINER(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#define CONTAINER_OF(ptr, type, member) ({ \
|
#define CONTAINER_OF(ptr, type, member) ({ \
|
||||||
const decltype( ((type *)0)->member ) *__mptr = (ptr); \
|
const decltype( ((type *)0)->member ) *__mptr = (ptr); \
|
||||||
(type *)( (char *)__mptr - OFFSET_OF_CONTAINER(type,member) );})
|
(type *)( (char *)__mptr - OFFSET_OF_CONTAINER(type,member) );})
|
||||||
#else
|
#else
|
||||||
#define CONTAINER_OF(ptr, type, member) (type *)((char*)(ptr) - OFFSET_OF_CONTAINER(type,member))
|
#define CONTAINER_OF(ptr, type, member) (type *)((char*)(ptr) - OFFSET_OF_CONTAINER(type,member))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// Intrusive linked lists
|
// Intrusive linked lists
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
#define list_entry(ptr, type, member) \
|
#define list_entry(ptr, type, member) \
|
||||||
CONTAINER_OF(ptr, type, member)
|
CONTAINER_OF(ptr, type, member)
|
||||||
|
|
||||||
#define list_next(elt) (elt)->next
|
#define list_next(elt) (elt)->next
|
||||||
#define list_prev(elt) (elt)->prev
|
#define list_prev(elt) (elt)->prev
|
||||||
|
|
||||||
#define list_next_entry(list, elt, type, member) \
|
#define list_next_entry(list, elt, type, member) \
|
||||||
((elt->member.next != list_end(list)) ? list_entry(elt->member.next, type, member) : 0)
|
((elt->member.next != list_end(list)) ? list_entry(elt->member.next, type, member) : 0)
|
||||||
|
|
||||||
#define list_prev_entry(list, elt, type, member) \
|
#define list_prev_entry(list, elt, type, member) \
|
||||||
((elt->member.prev != list_end(list)) ? list_entry(elt->member.prev, type, member) : 0)
|
((elt->member.prev != list_end(list)) ? list_entry(elt->member.prev, type, member) : 0)
|
||||||
|
|
||||||
#define list_checked_entry(list, type, member) \
|
#define list_checked_entry(list, type, member) \
|
||||||
(((list) != 0) ? list_entry(list, type, member) : 0)
|
(((list) != 0) ? list_entry(list, type, member) : 0)
|
||||||
|
|
||||||
#define list_first_entry(list, type, member) \
|
#define list_first_entry(list, type, member) \
|
||||||
(list_checked_entry(list_begin(list), type, member))
|
(list_checked_entry(list_begin(list), type, member))
|
||||||
|
|
||||||
#define list_last_entry(list, type, member) \
|
#define list_last_entry(list, type, member) \
|
||||||
(list_checked_entry(list_last(list), type, member))
|
(list_checked_entry(list_last(list), type, member))
|
||||||
|
|
||||||
#define for_list(list, elt, type, member) \
|
#define for_list(list, elt, type, member) \
|
||||||
for(type* elt = list_checked_entry(list_begin(list), type, member); \
|
for(type* elt = list_checked_entry(list_begin(list), type, member); \
|
||||||
elt != 0; \
|
elt != 0; \
|
||||||
elt = list_checked_entry(elt->member.next, type, member)) \
|
elt = list_checked_entry(elt->member.next, type, member)) \
|
||||||
|
|
||||||
#define for_list_reverse(list, elt, type, member) \
|
#define for_list_reverse(list, elt, type, member) \
|
||||||
for(type* elt = list_checked_entry(list_last(list), type, member); \
|
for(type* elt = list_checked_entry(list_last(list), type, member); \
|
||||||
elt != 0; \
|
elt != 0; \
|
||||||
elt = list_checked_entry(elt->member.prev, type, member)) \
|
elt = list_checked_entry(elt->member.prev, type, member)) \
|
||||||
|
|
||||||
#define for_list_safe(list, elt, type, member) \
|
#define for_list_safe(list, elt, type, member) \
|
||||||
for(type* elt = list_checked_entry(list_begin(list), type, member), \
|
for(type* elt = list_checked_entry(list_begin(list), type, member), \
|
||||||
*__tmp = elt ? list_checked_entry(elt->member.next, type, member) : 0 ; \
|
*__tmp = elt ? list_checked_entry(elt->member.next, type, member) : 0 ; \
|
||||||
elt != 0; \
|
elt != 0; \
|
||||||
elt = __tmp, \
|
elt = __tmp, \
|
||||||
__tmp = elt ? list_checked_entry(elt->member.next, type, member) : 0) \
|
__tmp = elt ? list_checked_entry(elt->member.next, type, member) : 0) \
|
||||||
|
|
||||||
#define list_pop_entry(list, type, member) (list_empty(list) ? 0 : list_entry(list_pop(list), type, member))
|
#define list_pop_entry(list, type, member) (list_empty(list) ? 0 : list_entry(list_pop(list), type, member))
|
||||||
|
|
||||||
typedef struct list_elt list_elt;
|
typedef struct list_elt list_elt;
|
||||||
struct list_elt
|
struct list_elt
|
||||||
{
|
{
|
||||||
list_elt* next;
|
list_elt* next;
|
||||||
list_elt* prev;
|
list_elt* prev;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct list_info
|
typedef struct list_info
|
||||||
{
|
{
|
||||||
list_elt* first;
|
list_elt* first;
|
||||||
list_elt* last;
|
list_elt* last;
|
||||||
} list_info;
|
} list_info;
|
||||||
|
|
||||||
static inline void list_init(list_info* list)
|
static inline void list_init(list_info* list)
|
||||||
{
|
{
|
||||||
list->first = list->last = 0;
|
list->first = list->last = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline list_elt* list_begin(list_info* list)
|
static inline list_elt* list_begin(list_info* list)
|
||||||
{
|
{
|
||||||
return(list->first);
|
return(list->first);
|
||||||
}
|
}
|
||||||
static inline list_elt* list_end(list_info* list)
|
static inline list_elt* list_end(list_info* list)
|
||||||
{
|
{
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline list_elt* list_last(list_info* list)
|
static inline list_elt* list_last(list_info* list)
|
||||||
{
|
{
|
||||||
return(list->last);
|
return(list->last);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void list_insert(list_info* list, list_elt* afterElt, list_elt* elt)
|
static inline void list_insert(list_info* list, list_elt* afterElt, list_elt* elt)
|
||||||
{
|
{
|
||||||
elt->prev = afterElt;
|
elt->prev = afterElt;
|
||||||
elt->next = afterElt->next;
|
elt->next = afterElt->next;
|
||||||
if(afterElt->next)
|
if(afterElt->next)
|
||||||
{
|
{
|
||||||
afterElt->next->prev = elt;
|
afterElt->next->prev = elt;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
list->last = elt;
|
list->last = elt;
|
||||||
}
|
}
|
||||||
afterElt->next = elt;
|
afterElt->next = elt;
|
||||||
|
|
||||||
DEBUG_ASSERT(elt->next != elt, "list_insert(): can't insert an element into itself");
|
DEBUG_ASSERT(elt->next != elt, "list_insert(): can't insert an element into itself");
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void list_insert_before(list_info* list, list_elt* beforeElt, list_elt* elt)
|
static inline void list_insert_before(list_info* list, list_elt* beforeElt, list_elt* elt)
|
||||||
{
|
{
|
||||||
elt->next = beforeElt;
|
elt->next = beforeElt;
|
||||||
elt->prev = beforeElt->prev;
|
elt->prev = beforeElt->prev;
|
||||||
|
|
||||||
if(beforeElt->prev)
|
if(beforeElt->prev)
|
||||||
{
|
{
|
||||||
beforeElt->prev->next = elt;
|
beforeElt->prev->next = elt;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
list->first = elt;
|
list->first = elt;
|
||||||
}
|
}
|
||||||
beforeElt->prev = elt;
|
beforeElt->prev = elt;
|
||||||
|
|
||||||
DEBUG_ASSERT(elt->next != elt, "list_insert_before(): can't insert an element into itself");
|
DEBUG_ASSERT(elt->next != elt, "list_insert_before(): can't insert an element into itself");
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void list_remove(list_info* list, list_elt* elt)
|
static inline void list_remove(list_info* list, list_elt* elt)
|
||||||
{
|
{
|
||||||
if(elt->prev)
|
if(elt->prev)
|
||||||
{
|
{
|
||||||
elt->prev->next = elt->next;
|
elt->prev->next = elt->next;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DEBUG_ASSERT(list->first == elt);
|
DEBUG_ASSERT(list->first == elt);
|
||||||
list->first = elt->next;
|
list->first = elt->next;
|
||||||
}
|
}
|
||||||
if(elt->next)
|
if(elt->next)
|
||||||
{
|
{
|
||||||
elt->next->prev = elt->prev;
|
elt->next->prev = elt->prev;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DEBUG_ASSERT(list->last == elt);
|
DEBUG_ASSERT(list->last == elt);
|
||||||
list->last = elt->prev;
|
list->last = elt->prev;
|
||||||
}
|
}
|
||||||
elt->prev = elt->next = 0;
|
elt->prev = elt->next = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void list_push(list_info* list, list_elt* elt)
|
static inline void list_push(list_info* list, list_elt* elt)
|
||||||
{
|
{
|
||||||
elt->next = list->first;
|
elt->next = list->first;
|
||||||
elt->prev = 0;
|
elt->prev = 0;
|
||||||
if(list->first)
|
if(list->first)
|
||||||
{
|
{
|
||||||
list->first->prev = elt;
|
list->first->prev = elt;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
list->last = elt;
|
list->last = elt;
|
||||||
}
|
}
|
||||||
list->first = elt;
|
list->first = elt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline list_elt* list_pop(list_info* list)
|
static inline list_elt* list_pop(list_info* list)
|
||||||
{
|
{
|
||||||
list_elt* elt = list_begin(list);
|
list_elt* elt = list_begin(list);
|
||||||
if(elt != list_end(list))
|
if(elt != list_end(list))
|
||||||
{
|
{
|
||||||
list_remove(list, elt);
|
list_remove(list, elt);
|
||||||
return(elt);
|
return(elt);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void list_push_back(list_info* list, list_elt* elt)
|
static inline void list_push_back(list_info* list, list_elt* elt)
|
||||||
{
|
{
|
||||||
elt->prev = list->last;
|
elt->prev = list->last;
|
||||||
elt->next = 0;
|
elt->next = 0;
|
||||||
if(list->last)
|
if(list->last)
|
||||||
{
|
{
|
||||||
list->last->next = elt;
|
list->last->next = elt;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
list->first = elt;
|
list->first = elt;
|
||||||
}
|
}
|
||||||
list->last = elt;
|
list->last = elt;
|
||||||
}
|
}
|
||||||
#define list_append(a, b) list_push_back(a, b)
|
#define list_append(a, b) list_push_back(a, b)
|
||||||
|
|
||||||
|
|
||||||
static inline list_elt* list_pop_back(list_info* list)
|
static inline list_elt* list_pop_back(list_info* list)
|
||||||
{
|
{
|
||||||
list_elt* elt = list_last(list);
|
list_elt* elt = list_last(list);
|
||||||
if(elt != list_end(list))
|
if(elt != list_end(list))
|
||||||
{
|
{
|
||||||
list_remove(list, elt);
|
list_remove(list, elt);
|
||||||
return(elt);
|
return(elt);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool list_empty(list_info* list)
|
static inline bool list_empty(list_info* list)
|
||||||
{
|
{
|
||||||
return(list->first == 0 || list->last == 0);
|
return(list->first == 0 || list->last == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// Circular Intrusive linked lists
|
// Circular Intrusive linked lists
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
#define clist_entry(ptr, type, member) list_entry(ptr, type, member)
|
#define clist_entry(ptr, type, member) list_entry(ptr, type, member)
|
||||||
#define clist_next(elt) list_next(elt)
|
#define clist_next(elt) list_next(elt)
|
||||||
#define clist_prev(elt) list_prev(elt)
|
#define clist_prev(elt) list_prev(elt)
|
||||||
|
|
||||||
#define clist_next_entry(head, elt, type, member) \
|
#define clist_next_entry(head, elt, type, member) \
|
||||||
((elt->member.next != clist_end(head)) ? clist_entry(elt->member.next, type, member) : 0)
|
((elt->member.next != clist_end(head)) ? clist_entry(elt->member.next, type, member) : 0)
|
||||||
|
|
||||||
#define clist_prev_entry(head, elt, type, member) \
|
#define clist_prev_entry(head, elt, type, member) \
|
||||||
((elt->member.prev != clist_end(head)) ? clist_entry(elt->member.prev, type, member) : 0)
|
((elt->member.prev != clist_end(head)) ? clist_entry(elt->member.prev, type, member) : 0)
|
||||||
|
|
||||||
#define clist_checked_entry(head, info, type, member) \
|
#define clist_checked_entry(head, info, type, member) \
|
||||||
((info != clist_end(head)) ? clist_entry(info, type, member) : 0)
|
((info != clist_end(head)) ? clist_entry(info, type, member) : 0)
|
||||||
|
|
||||||
#define clist_first_entry(head, type, member) \
|
#define clist_first_entry(head, type, member) \
|
||||||
(clist_checked_entry(head, clist_begin(head), type, member))
|
(clist_checked_entry(head, clist_begin(head), type, member))
|
||||||
|
|
||||||
#define clist_last_entry(head, type, member) \
|
#define clist_last_entry(head, type, member) \
|
||||||
(clist_checked_entry(head, clist_last(head), type, member))
|
(clist_checked_entry(head, clist_last(head), type, member))
|
||||||
|
|
||||||
#define for_clist(list, elt, type, member) \
|
#define for_clist(list, elt, type, member) \
|
||||||
for(type* elt = clist_entry(clist_begin(list), type, member); \
|
for(type* elt = clist_entry(clist_begin(list), type, member); \
|
||||||
&elt->member != clist_end(list); \
|
&elt->member != clist_end(list); \
|
||||||
elt = clist_entry(elt->member.next, type, member)) \
|
elt = clist_entry(elt->member.next, type, member)) \
|
||||||
|
|
||||||
|
|
||||||
#define for_clist_reverse(list, elt, type, member) \
|
#define for_clist_reverse(list, elt, type, member) \
|
||||||
for(type* elt = clist_entry(clist_last(list), type, member); \
|
for(type* elt = clist_entry(clist_last(list), type, member); \
|
||||||
&elt->member != clist_end(list); \
|
&elt->member != clist_end(list); \
|
||||||
elt = clist_entry(elt->member.prev, type, member)) \
|
elt = clist_entry(elt->member.prev, type, member)) \
|
||||||
|
|
||||||
|
|
||||||
#define for_clist_safe(list, elt, type, member) \
|
#define for_clist_safe(list, elt, type, member) \
|
||||||
for(type* elt = clist_entry(clist_begin(list), type, member), \
|
for(type* elt = clist_entry(clist_begin(list), type, member), \
|
||||||
*__tmp = clist_entry(elt->member.next, type, member); \
|
*__tmp = clist_entry(elt->member.next, type, member); \
|
||||||
&elt->member != clist_end(list); \
|
&elt->member != clist_end(list); \
|
||||||
elt = clist_entry(&__tmp->member, type, member), \
|
elt = clist_entry(&__tmp->member, type, member), \
|
||||||
__tmp = clist_entry(elt->member.next, type, member)) \
|
__tmp = clist_entry(elt->member.next, type, member)) \
|
||||||
|
|
||||||
|
|
||||||
#define clist_push(a, b) clist_insert(a, b)
|
#define clist_push(a, b) clist_insert(a, b)
|
||||||
#define clist_insert_before(a, b) clist_append(a, b)
|
#define clist_insert_before(a, b) clist_append(a, b)
|
||||||
|
|
||||||
#define clist_pop_entry(list, type, member) (clist_empty(list) ? 0 : clist_entry(clist_pop(list), type, member))
|
#define clist_pop_entry(list, type, member) (clist_empty(list) ? 0 : clist_entry(clist_pop(list), type, member))
|
||||||
|
|
||||||
static inline void clist_init(list_elt* info)
|
static inline void clist_init(list_elt* info)
|
||||||
{
|
{
|
||||||
info->next = info->prev = info;
|
info->next = info->prev = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline list_elt* clist_begin(list_elt* head)
|
static inline list_elt* clist_begin(list_elt* head)
|
||||||
{
|
{
|
||||||
return(head->next ? head->next : head );
|
return(head->next ? head->next : head );
|
||||||
}
|
}
|
||||||
static inline list_elt* clist_end(list_elt* head)
|
static inline list_elt* clist_end(list_elt* head)
|
||||||
{
|
{
|
||||||
return(head);
|
return(head);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline list_elt* clist_last(list_elt* head)
|
static inline list_elt* clist_last(list_elt* head)
|
||||||
{
|
{
|
||||||
return(head->prev ? head->prev : head);
|
return(head->prev ? head->prev : head);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void clist_insert(list_elt* head, list_elt* elt)
|
static inline void clist_insert(list_elt* head, list_elt* elt)
|
||||||
{
|
{
|
||||||
elt->prev = head;
|
elt->prev = head;
|
||||||
elt->next = head->next;
|
elt->next = head->next;
|
||||||
if(head->next)
|
if(head->next)
|
||||||
{
|
{
|
||||||
head->next->prev = elt;
|
head->next->prev = elt;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
head->prev = elt;
|
head->prev = elt;
|
||||||
}
|
}
|
||||||
head->next = elt;
|
head->next = elt;
|
||||||
|
|
||||||
ASSERT(elt->next != elt, "clist_insert(): can't insert an element into itself");
|
ASSERT(elt->next != elt, "clist_insert(): can't insert an element into itself");
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void clist_append(list_elt* head, list_elt* elt)
|
static inline void clist_append(list_elt* head, list_elt* elt)
|
||||||
{
|
{
|
||||||
clist_insert(head->prev, elt);
|
clist_insert(head->prev, elt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void clist_cat(list_elt* head, list_elt* list)
|
static inline void clist_cat(list_elt* head, list_elt* list)
|
||||||
{
|
{
|
||||||
if(head->prev)
|
if(head->prev)
|
||||||
{
|
{
|
||||||
head->prev->next = list->next;
|
head->prev->next = list->next;
|
||||||
}
|
}
|
||||||
if(head->prev && head->prev->next)
|
if(head->prev && head->prev->next)
|
||||||
{
|
{
|
||||||
head->prev->next->prev = head->prev;
|
head->prev->next->prev = head->prev;
|
||||||
}
|
}
|
||||||
head->prev = list->prev;
|
head->prev = list->prev;
|
||||||
if(head->prev)
|
if(head->prev)
|
||||||
{
|
{
|
||||||
head->prev->next = head;
|
head->prev->next = head;
|
||||||
}
|
}
|
||||||
clist_init(list);
|
clist_init(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void clist_remove(list_elt* elt)
|
static inline void clist_remove(list_elt* elt)
|
||||||
{
|
{
|
||||||
if(elt->prev)
|
if(elt->prev)
|
||||||
{
|
{
|
||||||
elt->prev->next = elt->next;
|
elt->prev->next = elt->next;
|
||||||
}
|
}
|
||||||
if(elt->next)
|
if(elt->next)
|
||||||
{
|
{
|
||||||
elt->next->prev = elt->prev;
|
elt->next->prev = elt->prev;
|
||||||
}
|
}
|
||||||
elt->prev = elt->next = 0;
|
elt->prev = elt->next = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline list_elt* clist_pop(list_elt* head)
|
static inline list_elt* clist_pop(list_elt* head)
|
||||||
{
|
{
|
||||||
list_elt* it = clist_begin(head);
|
list_elt* it = clist_begin(head);
|
||||||
if(it != clist_end(head))
|
if(it != clist_end(head))
|
||||||
{
|
{
|
||||||
clist_remove(it);
|
clist_remove(it);
|
||||||
return(it);
|
return(it);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline list_elt* clist_pop_back(list_elt* head)
|
static inline list_elt* clist_pop_back(list_elt* head)
|
||||||
{
|
{
|
||||||
list_elt* it = clist_last(head);
|
list_elt* it = clist_last(head);
|
||||||
if(it != clist_end(head))
|
if(it != clist_end(head))
|
||||||
{
|
{
|
||||||
clist_remove(it);
|
clist_remove(it);
|
||||||
return(it);
|
return(it);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool clist_empty(list_elt* head)
|
static inline bool clist_empty(list_elt* head)
|
||||||
{
|
{
|
||||||
return(head->next == 0 || head->next == head);
|
return(head->next == 0 || head->next == head);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif //__CONTAINERS_H_
|
#endif //__CONTAINERS_H_
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
* @revision:
|
* @revision:
|
||||||
*
|
*
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
#include"platform.h"
|
#include"platform/platform.h"
|
||||||
#include"memory.h"
|
#include"memory.h"
|
||||||
#include"platform_memory.h"
|
#include"platform/platform_memory.h"
|
||||||
#include"macro_helpers.h"
|
#include"macro_helpers.h"
|
||||||
|
|
||||||
#if PLATFORM_ORCA
|
#if PLATFORM_ORCA
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* @revision:
|
* @revision:
|
||||||
*
|
*
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
#include"platform_assert.h"
|
#include"platform/platform_assert.h"
|
||||||
#include"strings.h"
|
#include"strings.h"
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
#include"typedefs.h"
|
#include"typedefs.h"
|
||||||
#include"lists.h"
|
#include"lists.h"
|
||||||
#include"memory.h"
|
#include"memory.h"
|
||||||
#include"platform_strings.h"
|
#include"platform/platform_strings.h"
|
||||||
#include"platform_varg.h"
|
#include"platform/platform_varg.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
Loading…
Reference in New Issue