ObjFW  Diff

Differences From Artifact [967081c426]:

  • File src/threading_pthread.m — part of check-in [52e02c06ca] at 2014-08-01 12:27:29 on branch trunk — Change return type for thread main

    This changes the return type to void, as the return type of a thread's
    main depends on the threading implementation used. For pthreads, it adds
    a wrapper function which returns NULL to avoid problems with bogus
    return values. For WinAPI threads, the function is just casted, as bogus
    return values don't seem to matter there. (user: js, size: 4486) [annotate] [blame] [check-ins using]

To Artifact [3c16bc0403]:


9
10
11
12
13
14
15




16
17
18
19
20
21
22
 * the packaging of this file.
 *
 * 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.
 */





struct thread_ctx {
	void (*function)(id object);
	id object;
};

static void*







>
>
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 * the packaging of this file.
 *
 * 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.
 */

#ifdef HAVE_PTHREAD_NP_H
# include <pthread_np.h>
#endif

struct thread_ctx {
	void (*function)(id object);
	id object;
};

static void*
149
150
151
152
153
154
155





















156
157
158
159
160
161
162
void OF_NO_RETURN
of_thread_exit(void)
{
	pthread_exit(NULL);

	OF_UNREACHABLE
}






















void
of_once(of_once_t *control, void (*func)(void))
{
	pthread_once(control, func);
}








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
void OF_NO_RETURN
of_thread_exit(void)
{
	pthread_exit(NULL);

	OF_UNREACHABLE
}

void
of_thread_set_name(of_thread_t thread, const char *name)
{
#if defined(__HAIKU__)
	rename_thread(get_pthread_thread_id(thread), name);
#elif defined(HAVE_PTHREAD_SET_NAME_NP)
	pthread_set_name_np(pthread_self(), name);
#elif defined(HAVE_PTHREAD_SETNAME_NP)
# if defined(__APPLE__)
	pthread_setname_np(name);
# elif defined(__GLIBC__)
	char buffer[16];

	strncpy(buffer, name, 15);
	buffer[15] = 0;

	pthread_setname_np(pthread_self(), buffer);
# endif
#endif
}

void
of_once(of_once_t *control, void (*func)(void))
{
	pthread_once(control, func);
}