ObjFW  Diff

Differences From Artifact [7e3609752c]:

To Artifact [299f066682]:


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
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







-
+

-
+



-
+








-
+








-
+







#import "tlskey.h"

#include <dos/dostags.h>
#include <proto/dos.h>
#include <proto/exec.h>

#ifndef OF_MORPHOS
extern void of_tlskey_thread_exited(void);
extern void OFTLSKeyThreadExited(void);
#endif
static of_tlskey_t threadKey;
static OFTLSKey threadKey;

OF_CONSTRUCTOR()
{
	OF_ENSURE(of_tlskey_new(&threadKey) == 0);
	OF_ENSURE(OFTLSKeyNew(&threadKey) == 0);
}

static void
functionWrapper(void)
{
	bool detached = false;
	of_thread_t thread =
	    (of_thread_t)((struct Process *)FindTask(NULL))->pr_ExitData;
	OF_ENSURE(of_tlskey_set(threadKey, thread) == 0);
	OF_ENSURE(OFTLSKeySet(threadKey, thread) == 0);

	thread->function(thread->object);

	ObtainSemaphore(&thread->semaphore);
	@try {
		thread->done = true;

#ifndef OF_MORPHOS
		of_tlskey_thread_exited();
		OFTLSKeyThreadExited();
#endif

		if (thread->detached)
			detached = true;
		else if (thread->joinTask != NULL)
			Signal(thread->joinTask, (1ul << thread->joinSigBit));
	} @finally {
154
155
156
157
158
159
160
161

162
163
164
165
166
167
168
154
155
156
157
158
159
160

161
162
163
164
165
166
167
168







-
+








	return 0;
}

of_thread_t
of_thread_current(void)
{
	return of_tlskey_get(threadKey);
	return OFTLSKeyGet(threadKey);
}

int
of_thread_join(of_thread_t thread)
{
	ObtainSemaphore(&thread->semaphore);