haiku/headers/posix
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
..
arch posix: Add initial ARM64 headers. 2018-08-02 19:59:30 -04:00
arpa libbind: integrate "netresolv" patches from NetBSD. 2015-06-14 15:47:03 +02:00
compat/sys
net if_dl: Increase size of sdl_data from 20 to 46 bytes. 2018-06-20 21:26:21 -04:00
netinet
netinet6 Fix IN6_IS_ADDR_V4MAPPED & IN6_IS_ADDR_V4COMPAT false positives 2018-11-27 02:43:53 +00:00
sys libroot: add [gs]etpriority implementation 2019-01-19 18:31:58 +00:00
alloca.h
assert.h assert.h: reintroduce headers guard for function declarations. 2015-08-29 23:14:03 +02:00
bsd_mem.h
complex.h complex.h: add a C++ guard. 2016-10-05 09:18:42 +02:00
ctype.h
dirent.h
div_t.h
dlfcn.h libroot.so: make first parameter of dladdr() const. 2017-09-15 23:09:24 +02:00
endian.h Revert "endian.h: add BSD extensions when _BSD_SOURCE is defined." 2017-09-11 07:06:52 +12:00
errno.h
fcntl.h POSIX: F_DUPFD_CLOEXEC support (POSIX.1-2008). 2017-08-24 17:54:50 +02:00
fenv.h arch: Cleanup of __ARM__ checks 2018-07-31 19:12:20 -05:00
fnmatch.h
fts.h
ftw.h
getopt.h
glob.h
grp.h
inttypes.h Remove __STDC_FORMAT/CONSTANT_MACROS 2017-06-04 17:29:29 +02:00
iovec.h
langinfo.h
libgen.h
libio.h
limits.h libroot: add [gs]etpriority implementation 2019-01-19 18:31:58 +00:00
locale.h
malloc_debug.h malloc_debug: Implement allocation dump on exit in guarded heap. 2015-04-10 17:04:28 +02:00
malloc.h malloc: implement malloc_usable_size(). 2015-06-13 14:29:11 +02:00
math.h
memory.h
monetary.h
netdb.h Remove pthread.h include from netdb.h 2016-08-27 09:04:22 +02:00
nl_types.h
null.h
poll.h
pthread.h posix/pthread.h: mark pthread_exit as noreturn 2018-10-17 19:23:17 +00:00
pwd.h
regex.h
resolv.h libbind: integrate "netresolv" patches from NetBSD. 2015-06-14 15:47:03 +02:00
sched.h
search.h
semaphore.h Reimplement unnamed POSIX semaphores using user_mutex 2015-05-24 14:03:40 +01:00
setjmp.h setjmp.h: add noreturn keyword on longjmp variants. 2018-07-21 12:27:27 +02:00
shadow.h
signal.h Revert "Add sys/ucontext.h" 2014-08-09 20:18:05 +02:00
size_t.h
spawn.h libroot: add posix_spawn(). 2017-09-12 19:42:57 +02:00
stdint.h Remove __STDC_FORMAT/CONSTANT_MACROS 2017-06-04 17:29:29 +02:00
stdio_ext.h
stdio_post.h
stdio_pre.h
stdio.h stdio.h: declare fcloseall() GNU extension 2015-05-08 23:46:15 +02:00
stdlib.h Fix #7008: Add a64l and l64a from glibc, and add some missing definitions in wchar.h and stdlib.h 2014-12-14 18:06:09 +01:00
string.h string.h: include strings.h for compatibility. 2014-10-30 00:20:13 +01:00
strings.h
syslog.h syslog.h: Add LOG_NFACILITIES, LOG_FACMASK, LOG_FAC. 2017-12-26 17:09:26 -05:00
tar.h
termios.h Allow custom baud rates for FTDI serial ports 2016-02-27 19:08:53 +01:00
time.h Switch to a 64-bit time_t everywhere except 32-bit x86. 2017-06-06 17:38:17 -04:00
uchar.h uchar: Introduce C11 uchar.h 2018-01-14 14:42:34 +00:00
unistd.h unistd.h: define _POSIX_BARRIERS 2017-07-14 09:38:41 +02:00
utime.h
wchar_t.h
wchar.h Fix #7008: Add a64l and l64a from glibc, and add some missing definitions in wchar.h and stdlib.h 2014-12-14 18:06:09 +01:00
wctype.h