ObjFW  Diff

Differences From Artifact [0f3980a25d]:

To Artifact [4742ef8bb4]:


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
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
104
105
106
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

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
104
105
106

107
108

109
110
111
112
113
114
115
116
117
118

119
120

121
122
123
124
125
126
127
128

129
130
131
132
133







+
+




















+
+
+
+
+
+

+
+
+
+
+
+
+







-
+
+
+
+
+
+
+






+
+
+
+
+
+

-
+

-
+









-
+

-
+









-
+

-
+







-
+





#if !defined(OF_HAVE_THREADS) || \
    (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS))
# error No thread-local storage available!
#endif

#import "macros.h"

/** @file */

#if defined(OF_HAVE_PTHREADS)
# include <pthread.h>
typedef pthread_key_t OFTLSKey;
#elif defined(OF_WINDOWS)
# include <windows.h>
typedef DWORD OFTLSKey;
#elif defined(OF_MORPHOS)
# include <proto/exec.h>
typedef ULONG OFTLSKey;
#elif defined(OF_AMIGAOS)
typedef struct _OFTLSKey {
	struct objc_hashtable *table;
	struct _OFTLSKey *next, *previous;
} *OFTLSKey;
#endif

#ifdef __cplusplus
extern "C" {
#endif
/**
 * @brief Creates a new Thread Local Storage key.
 *
 * @param key A pointer to the key to create
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFTLSKeyNew(OFTLSKey *key);

/**
 * @brief Destroys the specified Thread Local Storage key.
 *
 * @param key A pointer to the key to destroy
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFTLSKeyFree(OFTLSKey key);
#ifdef __cplusplus
}
#endif

/* TLS keys are inlined for performance. */

#if defined(OF_HAVE_PTHREADS)
#if defined(OF_HAVE_PTHREADS) || defined(DOXYGEN)
/**
 * @brief Returns the current value for the specified Thread Local Storage key.
 *
 * @param key A pointer to the key whose value to return
 * @return The current value for the specified Thread Local Storage key
 */
static OF_INLINE void *
OFTLSKeyGet(OFTLSKey key)
{
	return pthread_getspecific(key);
}

/**
 * @brief Sets the current value for the specified Thread Local Storage key.
 *
 * @param key A pointer to the key whose value to set
 * @param value The new value for the key
 */
static OF_INLINE int
OFTLSKeySet(OFTLSKey key, void *ptr)
OFTLSKeySet(OFTLSKey key, void *value)
{
	return pthread_setspecific(key, ptr);
	return pthread_setspecific(key, value);
}
#elif defined(OF_WINDOWS)
static OF_INLINE void *
OFTLSKeyGet(OFTLSKey key)
{
	return TlsGetValue(key);
}

static OF_INLINE int
OFTLSKeySet(OFTLSKey key, void *ptr)
OFTLSKeySet(OFTLSKey key, void *value)
{
	return (TlsSetValue(key, ptr) ? 0 : EINVAL);
	return (TlsSetValue(key, value) ? 0 : EINVAL);
}
#elif defined(OF_MORPHOS)
static OF_INLINE void *
OFTLSKeyGet(OFTLSKey key)
{
	return (void *)TLSGetValue(key);
}

static OF_INLINE int
OFTLSKeySet(OFTLSKey key, void *ptr)
OFTLSKeySet(OFTLSKey key, void *value)
{
	return (TLSSetValue(key, (APTR)ptr) ? 0 : EINVAL);
	return (TLSSetValue(key, (APTR)value) ? 0 : EINVAL);
}
#elif defined(OF_AMIGAOS)
/* Those are too big too inline. */
# ifdef __cplusplus
extern "C" {
# endif
extern void *OFTLSKeyGet(OFTLSKey key);
extern int OFTLSKeySet(OFTLSKey key, void *ptr);
extern int OFTLSKeySet(OFTLSKey key, void *value);
# ifdef __cplusplus
}
# endif
#endif