forked from lei.chen/myxce
80 lines
1.7 KiB
C
80 lines
1.7 KiB
C
#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;
|
|
}
|