[Vala] [PATCH] Posix vapi, added scheduler (sched.h) functions



I've included in the vala posix vapi all the scheduler functions
provided by sched.h.

A simple usage, could be for example this code (which shows the number
of CPUs that you have):

/* Compile with valac --pkg posix test-posix-sched.vala -v -X -D"_GNU_SOURCE" */

using Posix;

int get_cpu_count() {
        int count = 0;

        var cpus = new Posix.CpuSet();
        var size = cpus.alloc_size();
        cpus.zero_sized(size);
        cpus.getaffinity(size);
        count = cpus.count_sized(size);

        return (count <= 0) ? 1 : count;
}

int main(string[] args) {
        print(@"Your PC has $(get_cpu_count()) CPUs\n");

        return 0;
}

(Maybe this get_cpu_count() function could be added to the vapi itself,
for getting the number of CPUs for multi-threading apps using, for
example a ThreadPool or just to limit Thread creation...)

Bye.

Attachment: vala-Posix-added-sched_-functions-support.patch
Description: Text Data



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]