Merge branch 'remove_extlib' into scheduler-framework
This commit is contained in:
commit
c4f2fec0d5
7 changed files with 144 additions and 91 deletions
|
|
@ -82,6 +82,7 @@ libxce_src = [ gen_srcs[0],
|
|||
'window.c',
|
||||
'xceapi.c',
|
||||
'xcectx.c',
|
||||
'xcelist.c',
|
||||
'xlist.c',
|
||||
'xstring.c',
|
||||
'zarray.c',
|
||||
|
|
|
|||
82
src/lib/xcelist.c
Normal file
82
src/lib/xcelist.c
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "xcelist.h"
|
||||
|
||||
/*
|
||||
* Intrusive circular doubly-linked list.
|
||||
*
|
||||
* The list head (`xcelist_t`) doubles as a sentinel: when the list is empty,
|
||||
* both `forw` and `back` point back at the head. This keeps insertion and
|
||||
* removal branch-free while allowing `list->forw` to be read directly as the
|
||||
* first entry (as done by the autoscaler demand queue).
|
||||
*/
|
||||
|
||||
xcelist_t* list_create(const char* name)
|
||||
{
|
||||
xcelist_t* list = (xcelist_t*)calloc(1, sizeof(xcelist_t));
|
||||
if (!list) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* empty list: head points at itself */
|
||||
list->forw = (xcelist_entry_t*)list;
|
||||
list->back = (xcelist_entry_t*)list;
|
||||
list->numEnts = 0;
|
||||
|
||||
if (name) {
|
||||
list->name = strdup(name);
|
||||
if (!list->name) {
|
||||
free(list);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void list_destroy(xcelist_t* list)
|
||||
{
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
free(list->name);
|
||||
free(list);
|
||||
}
|
||||
|
||||
void list_insert_entry_back(xcelist_t* list, xcelist_entry_t* entry)
|
||||
{
|
||||
xcelist_entry_t* head;
|
||||
xcelist_entry_t* last;
|
||||
|
||||
if (!list || !entry) {
|
||||
return;
|
||||
}
|
||||
|
||||
head = (xcelist_entry_t*)list;
|
||||
last = head->back;
|
||||
|
||||
entry->forw = head;
|
||||
entry->back = last;
|
||||
last->forw = entry;
|
||||
head->back = entry;
|
||||
|
||||
list->numEnts++;
|
||||
}
|
||||
|
||||
void list_entry_remove(xcelist_t* list, xcelist_entry_t* entry)
|
||||
{
|
||||
if (!list || !entry || entry == (xcelist_entry_t*)list) {
|
||||
return;
|
||||
}
|
||||
|
||||
entry->back->forw = entry->forw;
|
||||
entry->forw->back = entry->back;
|
||||
|
||||
entry->forw = NULL;
|
||||
entry->back = NULL;
|
||||
|
||||
if (list->numEnts > 0) {
|
||||
list->numEnts--;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue