ObjFW  Diff

Differences From Artifact [a634dc92fc]:

To Artifact [73d2b0526d]:


10
11
12
13
14
15
16







17

18

19
20

21












22
23
24

25





26
27
28
29
30
31
32
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */








#import "threading.h"



bool
of_thread_new(of_thread_t *thread, id (*function)(id), id data)

{












	*thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)function,
	    (__bridge void*)data, 0, NULL);


	return (thread != NULL);





}

bool
of_thread_join(of_thread_t thread)
{
	if (WaitForSingleObject(thread, INFINITE))
		return false;







>
>
>
>
>
>
>
|
>
|
>

|
>

>
>
>
>
>
>
>
>
>
>
>
>
|
|

>
|
>
>
>
>
>







10
11
12
13
14
15
16
17
18
19
20
21
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
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

bool
of_thread_attr_init(of_thread_attr_t *attr)
{
	attr->priority =
	    (float)(THREAD_PRIORITY_NORMAL - THREAD_PRIORITY_LOWEST) /
	    (THREAD_PRIORITY_HIGHEST - THREAD_PRIORITY_LOWEST);
	attr->stackSize = 0;

	return true;
}

bool
of_thread_new(of_thread_t *thread, id (*function)(id), id data,
    const of_thread_attr_t *attr)
{
	size_t stackSize = 0;
	int priority = 0;

	if (attr != NULL) {
		if (attr->priority < 0 || attr->priority > 1)
			return false;

		priority = THREAD_PRIORITY_LOWEST + attr->priority *
		    (THREAD_PRIORITY_HIGHEST - THREAD_PRIORITY_LOWEST);
		stackSize = attr->stackSize;
	}

	*thread = CreateThread(NULL, stackSize,
	    (LPTHREAD_START_ROUTINE)function, (__bridge void*)data, 0, NULL);

	if (thread == NULL)
		return false;

	if (priority > 0)
		return SetThreadPriority(*thread, priority);
	else
		return true;
}

bool
of_thread_join(of_thread_t thread)
{
	if (WaitForSingleObject(thread, INFINITE))
		return false;