ObjFW  Check-in [c2bde5d283]

Overview
Comment:Add of_once() for AmigaOS
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c2bde5d2834b09ee7e1639925c94ecbd97d9c03269c7968543f6bc9e6087febf
User & Date: js on 2019-08-01 21:20:03
Other Links: manifest | tags
Context
2019-08-01
21:31
Add thread-local storage for AmigaOS check-in: abaf310373 user: js tags: trunk
21:20
Add of_once() for AmigaOS check-in: c2bde5d283 user: js tags: trunk
21:17
Add mutexes for AmigaOS check-in: 2f01be3808 user: js tags: trunk
Changes

Modified src/once.h from [5ea0cd3af5] to [61d24c33d5].

22
23
24
25
26
27
28
29

30
31
32
33
34
35
36
37
38
39
40
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
39
40







-
+











#if defined(OF_HAVE_PTHREADS)
# include <pthread.h>
typedef pthread_once_t of_once_t;
# define OF_ONCE_INIT PTHREAD_ONCE_INIT
#elif defined(OF_HAVE_ATOMIC_OPS)
typedef volatile int of_once_t;
# define OF_ONCE_INIT 0
#elif !defined(OF_HAVE_THREADS)
#elif defined(OF_AMIGAOS) || !defined(OF_HAVE_THREADS)
typedef int of_once_t;
# define OF_ONCE_INIT 0
#endif

#ifdef __cplusplus
extern "C" {
#endif
extern void of_once(of_once_t *control, void (*func)(void));
#ifdef __cplusplus
}
#endif

Modified src/once.m from [9475bcca1a] to [4811cc42bf].

14
15
16
17
18
19
20




21
22
23
24
25
26
27
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31







+
+
+
+







 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#include "config.h"

#import "once.h"

#ifdef OF_AMIGAOS
# include <proto/exec.h>
#endif

#if defined(OF_HAVE_THREADS) && defined(OF_HAVE_ATOMIC_OPS)
# import "atomic.h"
# import "mutex.h"
#endif

void
40
41
42
43
44
45
46










47
48
49
50
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64







+
+
+
+
+
+
+
+
+
+





		of_memory_barrier();

		of_atomic_int_inc(control);
	} else
		while (*control == 1)
			of_thread_yield();
#elif defined(OF_AMIGAOS)
	Forbid();
	@try {
		if (*control == 0) {
			*control = 1;
			func();
		}
	} @finally {
		Permit();
	}
#else
# error No of_once available
#endif
}