use nix build & meson & zlog

This commit is contained in:
Rongsong Shen 2025-11-03 18:19:59 +08:00
parent 0123623742
commit 346768a144
60 changed files with 13739 additions and 0 deletions

81
src/lib/threshold.c Normal file
View file

@ -0,0 +1,81 @@
#include <errno.h>
#include <stdlib.h>
#include "utils.h"
#include "xce/errnox.h"
#include "xce/types.h"
static void kill_thresholds(xce_res_threshold_t** thresholds,
int count)
{
int i;
if (thresholds == NULL) {
return;
}
if (count > 0) {
for (i = 0; i < count; i++) {
xce_res_threshold_t* it = thresholds[i];
if (it == NULL) {
continue;
}
FREEUP(it->name);
FREEUP(it);
}
}
FREEUP(thresholds);
}
void free_resource_thresholds(xce_res_threshold_t** thresholds,
int count)
{
kill_thresholds(thresholds, count);
}
xce_res_threshold_t** dup_resource_thresholds(xce_res_threshold_t** src,
int count)
{
xce_res_threshold_t** thresholds = NULL;
int i;
if ((src == NULL) || (count <= 0)) {
errno = EINVAL;
return NULL;
}
thresholds = (xce_res_threshold_t**)calloc(count, sizeof(xce_res_threshold_t*));
if (thresholds == NULL) {
errno = ENOMEM;
return NULL;
}
for (i = 0; i < count; i++) {
xce_res_threshold_t* it = (xce_res_threshold_t*)calloc(1, sizeof(*it));
if (it == NULL) {
kill_thresholds(thresholds, i);
errno = ENOMEM;
return NULL;
}
thresholds[i] = it;
it->name = strdup(src[i]->name);
if (it->name == NULL) {
kill_thresholds(thresholds, i + 1);
errno = ENOMEM;
return NULL;
}
it->sched = src[i]->sched;
it->stop = src[i]->stop;
}
return thresholds;
}