ObjFW  Diff

Differences From Artifact [3654325ef3]:

To Artifact [3b3df80df6]:


23
24
25
26
27
28
29


30
31
32
33
34
35
36

#if !defined(OF_HAVE_THREADS) || \
    (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS))
# error No threads available!
#endif

#import "OFObject.h"



#if defined(OF_HAVE_PTHREADS)
# include <pthread.h>
typedef pthread_t OFPlainThread;
#elif defined(OF_WINDOWS)
# include <windows.h>
typedef HANDLE OFPlainThread;







>
>







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

#if !defined(OF_HAVE_THREADS) || \
    (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS))
# error No threads available!
#endif

#import "OFObject.h"

/** @file */

#if defined(OF_HAVE_PTHREADS)
# include <pthread.h>
typedef pthread_t OFPlainThread;
#elif defined(OF_WINDOWS)
# include <windows.h>
typedef HANDLE OFPlainThread;
49
50
51
52
53
54
55
56





57
58
59
60
61
62






63
64
65
66
67
68
69
#endif

typedef struct {
	float priority;
	size_t stackSize;
} OFPlainThreadAttributes;

#if defined(OF_HAVE_PTHREADS)





static OF_INLINE OFPlainThread
OFCurrentPlainThread(void)
{
	return pthread_self();
}







static OF_INLINE bool
OFPlainThreadIsCurrent(OFPlainThread thread)
{
	return pthread_equal(thread, pthread_self());
}
#elif defined(OF_WINDOWS)
static OF_INLINE OFPlainThread







|
>
>
>
>
>






>
>
>
>
>
>







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

typedef struct {
	float priority;
	size_t stackSize;
} OFPlainThreadAttributes;

#if defined(OF_HAVE_PTHREADS) || defined(DOXYGEN)
/**
 * @brief Returns the current plain thread.
 *
 * @return The current plain thread
 */
static OF_INLINE OFPlainThread
OFCurrentPlainThread(void)
{
	return pthread_self();
}

/**
 * @brief Returns whether the specified plain thread is the current thread.
 *
 * @param thread The thread to check
 * @return Whether the specified plain thread is the current thread
 */
static OF_INLINE bool
OFPlainThreadIsCurrent(OFPlainThread thread)
{
	return pthread_equal(thread, pthread_self());
}
#elif defined(OF_WINDOWS)
static OF_INLINE OFPlainThread
81
82
83
84
85
86
87






88














89
90






91







92







93
94
95
96
extern OFPlainThread OFCurrentPlainThread(void);
extern bool OFPlainThreadIsCurrent(OFPlainThread);
#endif

#ifdef __cplusplus
extern "C" {
#endif






extern int OFPlainThreadAttributesInit(OFPlainThreadAttributes *attr);














extern int OFPlainThreadNew(OFPlainThread *thread, const char *name,
    void (*function)(id), id object, const OFPlainThreadAttributes *attr);






extern void OFSetThreadName(const char *name);







extern int OFPlainThreadJoin(OFPlainThread thread);







extern int OFPlainThreadDetach(OFPlainThread thread);
#ifdef __cplusplus
}
#endif







>
>
>
>
>
>

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


>
>
>
>
>
>

>
>
>
>
>
>
>

>
>
>
>
>
>
>




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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
extern OFPlainThread OFCurrentPlainThread(void);
extern bool OFPlainThreadIsCurrent(OFPlainThread);
#endif

#ifdef __cplusplus
extern "C" {
#endif
/**
 * @brief Initializes the specified thread attributes.
 *
 * @param attr A pointer to the thread attributes to initialize
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainThreadAttributesInit(OFPlainThreadAttributes *attr);

/**
 * @brief Creates a new plain thread.
 *
 * A plain thread is similar to @ref OFThread, but does not use exceptions and
 * is just a lightweight wrapper around the system's thread implementation.
 *
 * @param thread A pointer to the thread to create
 * @param name A name for the thread
 * @param function The function the thread should execute
 * @param object The object to pass to the thread as an argument
 * @param attr Thread attributes
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainThreadNew(OFPlainThread *thread, const char *name,
    void (*function)(id), id object, const OFPlainThreadAttributes *attr);

/**
 * @brief Sets the name of the current thread.
 *
 * @param name The name for the current thread
 */
extern void OFSetThreadName(const char *name);

/**
 * @brief Joins the specified thread.
 *
 * @param thread The thread to join
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainThreadJoin(OFPlainThread thread);

/**
 * @brief Detaches the specified thread.
 *
 * @param thread The thread to detach
 * @return 0 on success, or an error number from `<errno.h>` on error
 */
extern int OFPlainThreadDetach(OFPlainThread thread);
#ifdef __cplusplus
}
#endif