ObjFW  Check-in [885d84a1a7]

Overview
Comment:socket.m: Minor cleanup

This should make the init behavior the same for --enable-threads and
--disable-threads.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 885d84a1a77aaafec4806b62f3f9a3b64a6f2a2564255c79f47e785ea3bbdeb7
User & Date: js on 2018-03-18 01:01:42
Other Links: manifest | tags
Context
2018-03-18
01:05
Fix missing import and typo check-in: c32b3419c2 user: js tags: trunk
01:01
socket.m: Minor cleanup check-in: 885d84a1a7 user: js tags: trunk
00:52
Implement +[operatingSystemVersion] for macOS/iOS check-in: 01104c5e85 user: js tags: trunk
Changes

Modified src/runtime/threading.m from [485a93cc19] to [f965e6303e].

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







-











+












#include <stdlib.h>

#import "ObjFW_RT.h"
#import "private.h"
#import "threading.h"

static of_rmutex_t global_mutex;
static of_once_t once_control = OF_ONCE_INIT;

static void
init(void)
{
	if (!of_rmutex_new(&global_mutex))
		OBJC_ERROR("Failed to create global mutex!");
}

void
objc_global_mutex_lock(void)
{
	static of_once_t once_control = OF_ONCE_INIT;
	of_once(&once_control, init);

	if (!of_rmutex_lock(&global_mutex))
		OBJC_ERROR("Failed to lock global mutex!");
}

void
objc_global_mutex_unlock(void)
{
	if (!of_rmutex_unlock(&global_mutex))
		OBJC_ERROR("Failed to unlock global mutex!");
}

Modified src/socket.m from [07290bee4c] to [d3a737b015].

35
36
37
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
35
36
37
38
39
40
41

42
43

44
45
46
47
48
49
50
51







-


-
+








#ifdef OF_NINTENDO_3DS
# include <3ds/types.h>
# include <3ds/services/soc.h>
#endif

#ifdef OF_HAVE_THREADS
static of_once_t onceControl = OF_ONCE_INIT;
static of_mutex_t mutex;
#endif
static bool initialized = false;
static bool initSuccessful = false;

static void
init(void)
{
#if defined(OF_WINDOWS)
	WSADATA wsa;

73
74
75
76
77
78
79
80

81
82
83
84
85
86

87
88

89

90


91
92
93

94
95
96
97
98
99
100
72
73
74
75
76
77
78

79
80
81
82
83
84
85
86
87
88
89

90
91
92
93
94
95

96
97
98
99
100
101
102
103







-
+






+


+
-
+

+
+


-
+








# ifdef OF_WII
	if (!of_spinlock_new(&spinlock))
		return;
# endif
#endif

	initialized = true;
	initSuccessful = true;
}

bool
of_socket_init()
{
#ifdef OF_HAVE_THREADS
	static of_once_t onceControl = OF_ONCE_INIT;
	of_once(&onceControl, init);
#else
	static bool initialized = false;
	if (!initialized)
	if (!initialized) {
		init();
		initialized = true;
	}
#endif

	return initialized;
	return initSuccessful;
}

int
of_socket_errno()
{
#ifndef OF_WINDOWS
	return errno;