Differences From Artifact [706256fda3]:
- File
src/threading_pthread.m
— part of check-in
[f58ea581f0]
at
2016-03-28 11:26:47
on branch trunk
— Move Haiku-specific include to the right file
This was forgotten when splitting threading.m into multiple files. (user: js, size: 5222) [annotate] [blame] [check-ins using]
To Artifact [22a0bb4722]:
- File
src/threading_pthread.m
— part of check-in
[b4023e6bc0]
at
2016-03-28 16:50:16
on branch trunk
— Change the definition of thread priorities
The old definition was quite unpredictable and too platform-specific.
The new one defines -1.0 as lowest priority that still schedules, 0.0 as
the normal priority (meaning the same as the main thread) and +1.0 as
the highest priority that still allows getting preempted. (user: js, size: 5322) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #import "macros.h" #ifdef OF_HAIKU # include <kernel/OS.h> #endif struct thread_ctx { void (*function)(id object); id object; }; static void* function_wrapper(void *data) { struct thread_ctx *ctx = data; pthread_cleanup_push(free, data); | > > > > > > > > > > > > > > > > > > > > > > > > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #import "macros.h" #ifdef OF_HAIKU # include <kernel/OS.h> #endif static int minPrio, maxPrio, normalPrio; struct thread_ctx { void (*function)(id object); id object; }; /* * This is done here to make sure this is done as early as possible in the main * thread. */ static void __attribute__((constructor)) init(void) { pthread_attr_t pattr; int policy; struct sched_param param; OF_ENSURE(pthread_attr_init(&pattr) == 0); OF_ENSURE(pthread_attr_getschedpolicy(&pattr, &policy) == 0); OF_ENSURE((minPrio = sched_get_priority_min(policy)) != -1); OF_ENSURE((maxPrio = sched_get_priority_max(policy)) != -1); OF_ENSURE(pthread_attr_getschedparam(&pattr, ¶m) == 0); normalPrio = param.sched_priority; pthread_attr_destroy(&pattr); } static void* function_wrapper(void *data) { struct thread_ctx *ctx = data; pthread_cleanup_push(free, data); |
︙ | ︙ | |||
49 50 51 52 53 54 55 | { pthread_attr_t pattr; if (pthread_attr_init(&pattr) != 0) return false; @try { | < < < < < < < < < < < < < < < < < | | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | { pthread_attr_t pattr; if (pthread_attr_init(&pattr) != 0) return false; @try { attr->priority = 0; if (pthread_attr_getstacksize(&pattr, &attr->stackSize) != 0) return false; } @finally { pthread_attr_destroy(&pattr); } |
︙ | ︙ | |||
91 92 93 94 95 96 97 | if (pthread_attr_init(&pattr) != 0) return false; @try { struct thread_ctx *ctx; if (attr != NULL) { | < | < < < < < < < < < > > > > > > > > | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | if (pthread_attr_init(&pattr) != 0) return false; @try { struct thread_ctx *ctx; if (attr != NULL) { struct sched_param param; if (attr->priority < -1 || attr->priority > 1) return false; #ifdef HAVE_PTHREAD_ATTR_SETINHERITSCHED if (pthread_attr_setinheritsched(&pattr, PTHREAD_EXPLICIT_SCHED) != 0) return false; #endif if (attr->priority < 0) { param.sched_priority = minPrio + (1.0 + attr->priority) * (normalPrio - minPrio); } else param.sched_priority = normalPrio + attr->priority * (maxPrio - normalPrio); if (pthread_attr_setschedparam(&pattr, ¶m) != 0) return false; if (attr->stackSize > 0) { if (pthread_attr_setstacksize(&pattr, attr->stackSize) != 0) return false; |
︙ | ︙ |