mirror of
https://github.com/NikitaIvanovV/ctpv.git
synced 2024-11-24 13:53:07 +01:00
Minor, add comments
This commit is contained in:
parent
2ac76f7b10
commit
805f6aa8f4
20
src/ulist.c
20
src/ulist.c
@ -10,9 +10,6 @@
|
|||||||
#define DEFAULT_CAP 256
|
#define DEFAULT_CAP 256
|
||||||
#define NO_LOCK -1
|
#define NO_LOCK -1
|
||||||
|
|
||||||
#define ULIST_NODE_SIZE(cap, size) \
|
|
||||||
(sizeof(struct UListNode) - sizeof(void *) + (cap * size))
|
|
||||||
|
|
||||||
#define ULIST_BUF(node) ((void *)&(node).buf)
|
#define ULIST_BUF(node) ((void *)&(node).buf)
|
||||||
#define ULIST_BUF_AT(list, node, i) (ULIST_BUF(node) + i * (list).size)
|
#define ULIST_BUF_AT(list, node, i) (ULIST_BUF(node) + i * (list).size)
|
||||||
|
|
||||||
@ -28,11 +25,6 @@ struct UListNode {
|
|||||||
void *buf;
|
void *buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline int is_locked(UList *l)
|
|
||||||
{
|
|
||||||
return l->lock_i != NO_LOCK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct UListNode *ulist_node_new(UList *l, size_t cap)
|
static struct UListNode *ulist_node_new(UList *l, size_t cap)
|
||||||
{
|
{
|
||||||
struct UListNode *n;
|
struct UListNode *n;
|
||||||
@ -40,7 +32,8 @@ static struct UListNode *ulist_node_new(UList *l, size_t cap)
|
|||||||
if (cap == 0)
|
if (cap == 0)
|
||||||
cap = DEFAULT_CAP;
|
cap = DEFAULT_CAP;
|
||||||
|
|
||||||
if (!(n = malloc(ULIST_NODE_SIZE(cap, l->size)))) {
|
/* Store buffer and node data in the same chunk */
|
||||||
|
if (!(n = malloc(sizeof(*n) - sizeof(n->buf) + (cap * l->size)))) {
|
||||||
FUNCFAILED("malloc", strerror(errno));
|
FUNCFAILED("malloc", strerror(errno));
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
@ -81,6 +74,11 @@ void ulist_free(UList *l)
|
|||||||
free(l);
|
free(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int is_locked(UList *l)
|
||||||
|
{
|
||||||
|
return l->lock_i != NO_LOCK;
|
||||||
|
}
|
||||||
|
|
||||||
void ulist_append_arr(UList *l, void *arr, size_t len)
|
void ulist_append_arr(UList *l, void *arr, size_t len)
|
||||||
{
|
{
|
||||||
struct UListNode *new, *node = l->tail;
|
struct UListNode *new, *node = l->tail;
|
||||||
@ -113,6 +111,10 @@ void ulist_append(UList *l, void *val)
|
|||||||
ulist_append_arr(l, val, 1);
|
ulist_append_arr(l, val, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ensure that all the elements appended will be placed in memory
|
||||||
|
* will be placed one after another. Useful for storing strings.
|
||||||
|
*/
|
||||||
void ulist_lock(UList *l)
|
void ulist_lock(UList *l)
|
||||||
{
|
{
|
||||||
l->lock_i = l->tail->len;
|
l->lock_i = l->tail->len;
|
||||||
|
Loading…
Reference in New Issue
Block a user