Merge branch 'remove_extlib' into scheduler-framework

This commit is contained in:
Rongsong Shen 2026-09-04 06:49:06 +00:00
commit c4f2fec0d5
No known key found for this signature in database
GPG key ID: 5BCDAAE0123E9FE2
7 changed files with 144 additions and 91 deletions

View file

@ -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
View 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--;
}
}