bool ret = false;
f = fopen(MOUNTS_PATH, "r");
- if (NULL == f) {
+ if (f == NULL) {
_E("cpu-sched: could not open " MOUNTS_PATH);
return ret;
}
if (sscanf(buf, "%*s %127s %*s %127s %*d %*d", mountpoint, opts) != 2)
continue;
- if (!strcmp(mountpoint, CPUSET_CGROUP) && NULL != strstr(opts, "cpuset")) {
+ if (!strcmp(mountpoint, CPUSET_CGROUP) && strstr(opts, "cpuset") != NULL) {
ret = true;
break;
}
struct coreset *c;
_D("cpu-sched: init cgroup subsystem");
- if (false == cpu_sched_is_cpuset_mounted()) {
+ if (cpu_sched_is_cpuset_mounted() == false) {
r = cgroup_make_subdir(DEFAULT_CGROUP, "cpuset", NULL);
if (r < 0) {
_E("failed to make cpuset cgroup");
_D("cpu-sched: new core %d for set %s", core_id, set->name);
c = (struct core *)calloc(1, sizeof *c);
- if (NULL == c) {
+ if (c == NULL) {
_E("cpu-sched: could not allocate memory for core struct");
return RESOURCED_ERROR_FAIL;
}
}
/* free memory allocated in coreset structure */
-static void cpu_sched_free_cpuset(struct coreset *set)
+static void cpu_sched_free_cpuset(struct coreset **c)
{
- if (NULL != set->cores)
+ struct coreset *set = *c;
+
+ if (set->cores != NULL)
g_slist_free_full(set->cores, free);
set->cores = NULL;
free(set->name);
set->name = NULL;
+
+ free(set);
+ *c = NULL;
}
/* free memory allocated in coreset structure and the structure */
assert(set);
- cpu_sched_free_cpuset(set);
- free(set);
+ cpu_sched_free_cpuset(&set);
}
/* parse config for specific coreset line */
ptr = strtok_r(value, ",", &saveptr);
while (ptr) {
- if (NULL == strstr(ptr, "-")) { /* single value */
+ if (strstr(ptr, "-") == NULL) { /* single value */
r = sscanf(ptr, "%d", &min);
if (r == 1 && min >= 0) {
- if (RESOURCED_ERROR_NONE != cpu_sched_new_core(set, min))
+ if (cpu_sched_new_core(set, min) != RESOURCED_ERROR_NONE)
goto parse_cpuset_fail;
} else {
_E("cpu-sched: error parsing cpuset (%s)", ptr);
r = sscanf(ptr, "%d-%d", &min, &max);
if (r == 2 && min >= 0 && max >= 0 && max > min) {
for (int i = min; i <= max; i++) {
- if (RESOURCED_ERROR_NONE != cpu_sched_new_core(set, i))
+ if (cpu_sched_new_core(set, i) != RESOURCED_ERROR_NONE)
goto parse_cpuset_fail;
}
} else {
}
return RESOURCED_ERROR_NONE;
parse_cpuset_fail:
- cpu_sched_free_cpuset(set);
+ cpu_sched_free_cpuset(&set);
return RESOURCED_ERROR_FAIL;
}
assert(data);
- int ret = RESOURCED_ERROR_OUT_OF_MEMORY;
bool is_fg = !strcmp(result->name, CPU_SCHED_FG_NAME);
char *name = strdup(result->name);
+ if (name == NULL)
+ return RESOURCED_ERROR_OUT_OF_MEMORY;
+
struct coreset *c = (struct coreset *)calloc(1, sizeof *c);
- if (NULL == c || NULL == name)
- goto err_out;
+ if (c == NULL) {
+ free(name);
+ return RESOURCED_ERROR_OUT_OF_MEMORY;
+ }
c->name = name;
if (cpu_sched_parse_cpuset(c, result->value) < 0) {
_E("cpu-sched parse %s coreset: could not parse", result->name);
- ret = RESOURCED_ERROR_FAIL;
- goto err_out;
+ return RESOURCED_ERROR_FAIL;
}
if (is_fg)
data->apps = g_slist_append(data->apps, c);
return RESOURCED_ERROR_NONE;
-
-err_out:
- free(c);
- free(name);
- return ret;
}
static int cpu_sched_parse_config(struct cpu_sched *data)
r = 0;
gslist_for_each_item(i, set->cores) {
c = (struct core *)i->data;
- if (NULL == c || false == c->on)
+ if (c == NULL || c->on == false)
continue;
r += snprintf(coreset + r, sizeof coreset - r, "%d,", c->id);
assert(set);
assert(core_id >= 0);
- if (NULL == set->cores)
+ if (set->cores == NULL)
return 0;
gslist_for_each_item(i, set->cores) {
c = (struct core *)i->data;
- if (NULL == c || c->id != core_id)
+ if (c == NULL || c->id != core_id)
continue;
_D("cpu-sched: core %d on for coreset %s", core_id, set->name);
break;
}
- if (false == refresh)
+ if (refresh == false)
return 0;
return cpu_sched_write_coreset(set);
assert(set);
assert(core_id >= 0);
- if (NULL == set->cores)
+ if (set->cores == NULL)
return 0;
gslist_for_each_item(i, set->cores) {
c = (struct core *)i->data;
- if (NULL == c || c->id != core_id)
+ if (c == NULL || c->id != core_id)
continue;
_D("cpu-sched: core %d off for coreset %s", core_id, set->name);
break;
}
- if (false == refresh)
+ if (refresh == false)
return 0;
return cpu_sched_write_coreset(set);
if (!c)
return false;
- if (false == c->disclaimer_shown) {
+ if (c->disclaimer_shown == false) {
_D("cpu-sched: appid %s is statically configured - not subject to cpuset change", appid);
c->disclaimer_shown = true;
}
assert(ps);
assert(ps->pai);
- if (false == cs.is_initalized || true == cpu_sched_is_static_app(ps->pai->appid))
+ if (cs.is_initalized == false || cpu_sched_is_static_app(ps->pai->appid) == true)
return RESOURCED_ERROR_NONE;
_D("cpu-sched: app %s moved to foreground; pid=%d", ps->pai->appid, ps->pid);
assert(ps);
assert(ps->pai);
- if (false == cs.is_initalized || true == cpu_sched_is_static_app(ps->pai->appid))
+ if (cs.is_initalized == false || cpu_sched_is_static_app(ps->pai->appid) == true)
return RESOURCED_ERROR_NONE;
_D("cpu-sched: app %s moved to background; pid=%d", ps->pai->appid, ps->pid);
_D("cpu-sched: app launch: %s", ps->pai->appid);
c = cpu_sched_find_coreset(ps->pai->appid);
- if (NULL == c)
+ if (c == NULL)
return 0;
return cpu_sched_add_pid_to_cpuset(c, ps->pid);
static void cpu_sched_free_cpusets()
{
g_slist_free_full(g_steal_pointer(&cs.apps), cpu_sched_free_cpuset_full);
- if (cs.fg) {
- cpu_sched_free_cpuset(cs.fg);
- free(cs.fg);
- cs.fg = NULL;
- }
+ if (cs.fg)
+ cpu_sched_free_cpuset(&cs.fg);
}
static void cpu_sched_check_apps()
continue;
c = cpu_sched_find_coreset(pai->appid);
- if (NULL != c) {
+ if (c != NULL) {
cpu_sched_add_pid_to_cpuset(c, pai->main_pid);
continue;
}