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
64
65
66
|
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
64
65
66
67
68
69
70
71
72
73
74
|
-
+
+
+
-
+
-
+
-
-
-
-
-
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
-
+
+
+
|
#import "macros.h"
#ifdef OF_HAIKU
# include <kernel/OS.h>
#endif
static int minPrio, maxPrio, normalPrio;
static int minPrio = 0, maxPrio = 0, normalPrio = 0;
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.
*/
OF_CONSTRUCTOR()
{
pthread_attr_t pattr;
if (pthread_attr_init(&pattr) == 0) {
#ifdef HAVE_PTHREAD_ATTR_GETSCHEDPOLICY
int policy;
int policy;
#endif
struct sched_param param;
struct sched_param param;
OF_ENSURE(pthread_attr_init(&pattr) == 0);
#ifdef HAVE_PTHREAD_ATTR_GETSCHEDPOLICY
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);
#endif
if (pthread_attr_getschedpolicy(&pattr, &policy) == 0) {
minPrio = sched_get_priority_min(policy);
maxPrio = sched_get_priority_max(policy);
OF_ENSURE(pthread_attr_getschedparam(&pattr, ¶m) == 0);
normalPrio = param.sched_priority;
if (minPrio == -1 || maxPrio == -1)
minPrio = maxPrio = 0;
}
if (pthread_attr_getschedparam(&pattr, ¶m) != 0)
normalPrio = param.sched_priority;
else
minPrio = maxPrio = 0;
pthread_attr_destroy(&pattr);
pthread_attr_destroy(&pattr);
#endif
}
}
static void *
function_wrapper(void *data)
{
struct thread_ctx *ctx = data;
|