haiku/headers/posix/sys
Timothy Gu 8ae2e95643 libroot: add [gs]etpriority implementation
Implemented against POSIX-1.2013.

The implementation POSIX requirement thats setpriority() shall affect the
priority of all system scope threads only extends to POSIX threads. This
is implemented by modifying the default attributes for newly spawned
pthreads.

It is not possible to modify the default pthread attributes for different
processes with the current implementation, as default pthread attributes
are implemented in user-space. As a result, PRIO_PROCESS for which and 0
for who is the only supported combination for setpriority().

While it is possible to move the default attributes to the kernel, it
is chosen not to so as to keep the pthread implementation user-space only.

POSIX requires that lowering the nice value (increasing priority) can be
done only by processes with appropriate privileges. However, as Haiku
currently doesn't harbor any restrictions in setting the thread priority,
this is not implemented.

It is possible to have small precision errors when converting from Unix-
style thread priority to Be-style. For example, the following program
outputs "17" instead of the expected "18":

	#include <stdio.h>
	#include <sys/resource.h>

	int
	main()
	{
		setpriority(PRIO_PROCESS, 0, 18);
		printf("%d\n", getpriority(PRIO_PROCESS, 0));
		return 0;
	}

The underlying reason is because when you setpriority() both 18 and 19
are converted to the Be-style "2". This problem should not happen with
priority levels lower than or equal to 20, when the Be notation is more
precise than the Unix-style.

Done as a part of GCI 2014. Fixes #2817.

Signed-off-by: Timothy Gu <timothygu99@gmail.com>
Co-authored-by: Leorize <leorize+oss@disroot.org>
Change-Id: Ie14f105b00fe8563d16b3562748e1c2e56c873a6
Reviewed-on: https://review.haiku-os.org/c/78
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2019-01-19 18:31:58 +00:00
..
cdefs.h x86_64: fenv.c needs __weak_reference() 2015-03-27 20:16:57 +01:00
file.h Updated copyright in headers. No functional change. 2012-07-19 18:14:06 +00:00
ioctl.h Updated copyright in headers. No functional change. 2012-07-19 18:14:06 +00:00
ipc.h Updated copyright in headers. No functional change. 2012-07-19 18:14:06 +00:00
mman.h Updated copyright in headers. No functional change. 2012-07-19 18:14:06 +00:00
msg.h Updated copyright in headers. No functional change. 2012-07-19 18:14:06 +00:00
param.h Updated copyright in headers. No functional change. 2012-07-19 18:14:06 +00:00
poll.h Updated copyright in headers. No functional change. 2012-07-19 18:14:06 +00:00
resource.h libroot: add [gs]etpriority implementation 2019-01-19 18:31:58 +00:00
select.h <langinfo.h>/<select.h>: don't use C++ comments 2013-06-12 14:55:16 +02:00
sem.h Updated copyright in headers. No functional change. 2012-07-19 18:14:06 +00:00
socket.h Implement MSG_NOSIGNAL 2015-06-10 17:39:53 +02:00
sockio.h Updated copyright in headers. No functional change. 2012-07-19 18:14:06 +00:00
stat.h mknod[at](): moves from unistd.h to sys/stat.h 2014-08-04 19:03:08 +02:00
statvfs.h Updated copyright in headers. No functional change. 2012-07-19 18:14:06 +00:00
time.h libbsd: Move lutimes to bsd compat 2017-11-17 14:27:26 -06:00
timeb.h Updated copyright in headers. No functional change. 2012-07-19 18:14:06 +00:00
times.h Updated copyright in headers. No functional change. 2012-07-19 18:14:06 +00:00
types.h pthread_rwlock: use a mutex for process-private locks. 2017-07-27 18:33:53 +02:00
uio.h Updated copyright in headers. No functional change. 2012-07-19 18:14:06 +00:00
un.h Updated copyright in headers. No functional change. 2012-07-19 18:14:06 +00:00
utsname.h Updated copyright in headers. No functional change. 2012-07-19 18:14:06 +00:00
wait.h Merged signals-merge branch into trunk with the following changes: 2011-06-12 00:00:23 +00:00