summaryrefslogtreecommitdiff
path: root/include/wolf/threads/threads.h
blob: 73c5236bc661aefe9f8d7c39f054062cad289073 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
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
/*
    Copyright (C) 2008 Andreas Baumann <abaumann@yahoo.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef WOLF_THREADS_H
#define WOLF_THREADS_H

/**
 * @addtogroup wolf_threading Threading support
 * @{
 */

/**
 * @file threads.h
 * @brief Portable thread functions
 * @author Andreas Baumann <abaumann@yahoo.com>
 */

#ifdef __cplusplus
extern "C" {
#endif

#include "port/sys.h"

#include "errors.h"

#ifdef HAVE_PTHREADS

#include <pthread.h>			/* for thread functions */

#define WOLF_THREAD_RETURN_DECL void *
#define WOLF_THREAD_RETURN return NULL;

typedef pthread_t wolf_thread_t;

typedef void *( *wolf_thread_func_t )( void * );

wolf_error_t wolf_thread_create( wolf_thread_t *thread, wolf_thread_func_t func );
wolf_error_t wolf_thread_join( wolf_thread_t *thread );

#endif /* HAVE_PTHREADS */

#ifdef _WIN32

#define WIN32_MEAN_AND_LEAN
#include <windows.h>

#define WOLF_THREAD_RETURN_DECL unsigned
#define WOLF_THREAD_RETURN return 0;

typedef uintptr_t wolf_thread_t;

typedef void ( *wolf_thread_func_t )( void * );

wolf_error_t wolf_thread_create( wolf_thread_t *thread, wolf_thread_func_t func );
wolf_error_t wolf_thread_join( wolf_thread_t *thread );

#endif /* _WIN32 */

#ifdef __cplusplus
}
#endif

/** @} */ /* @addtogroup wolf_threading */

#endif /* ifndef WOLF_THREADS_H */