Closed lukego closed 9 years ago
On reflection it would be really nice to be able to treat a CPU set like an array e.g. count its elements, iterate over its elements, access its first element, etc. Perhaps a better solution would be to convert the cpu_set_t
into an array? (Even for sched_getaffinity()
to do that automatically for its return value?)
The thing to do would be to return an array from get unless the user actually passes a cpu_set_t - in which case return that. That's the fairly standard arrangement elsewhere. The set syscall should accept either. Then most people can just use arrays but if you want to interoperate with something else that uses the type you can.
Good idea. Closing for now. I opened this a little prematurely because I haven't fleshed out my use case yet.
This makes the '#' operator return the number of elements in a cpu_set_t object. Originally the return value was always 128 based on the size of the structure rather than the number of elements set.
This change is immediately useful for some code of mine that depends on having affinity to one CPU core and wants to run:
Summary of original behavior:
and new behavior: