ObjFW
OFPlainCondition.h
1 /*
2  * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "objfw-defs.h"
21 
22 #include "platform.h"
23 
24 #if !defined(OF_HAVE_THREADS) || \
25  (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS))
26 # error No conditions available!
27 #endif
28 
29 /* For OFTimeInterval */
30 #import "OFObject.h"
31 #import "OFPlainMutex.h"
32 
33 #if defined(OF_HAVE_PTHREADS)
34 # include <pthread.h>
35 typedef pthread_cond_t OFPlainCondition;
36 #elif defined(OF_WINDOWS)
37 # include <windows.h>
38 typedef struct {
39  HANDLE event;
40  volatile int count;
41 } OFPlainCondition;
42 #elif defined(OF_AMIGAOS)
43 # include <exec/tasks.h>
44 typedef struct {
45  struct OFPlainConditionWaitingTask {
46  struct Task *task;
47  unsigned char sigBit;
48  struct OFPlainConditionWaitingTask *next;
49  } *waitingTasks;
50 } OFPlainCondition;
51 #endif
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 extern int OFPlainConditionNew(OFPlainCondition *condition);
57 extern int OFPlainConditionSignal(OFPlainCondition *condition);
58 extern int OFPlainConditionBroadcast(OFPlainCondition *condition);
59 extern int OFPlainConditionWait(OFPlainCondition *condition,
60  OFPlainMutex *mutex);
61 extern int OFPlainConditionTimedWait(OFPlainCondition *condition,
62  OFPlainMutex *mutex, OFTimeInterval timeout);
63 #if defined(OF_AMIGAOS) || defined(DOXYGEN)
64 extern int OFPlainConditionWaitOrExecSignal(OFPlainCondition *condition,
65  OFPlainMutex *mutex, ULONG *signalMask);
66 extern int OFPlainConditionTimedWaitOrExecSignal(OFPlainCondition *condition,
67  OFPlainMutex *mutex, OFTimeInterval timeout, ULONG *signalMask);
68 #endif
69 extern int OFPlainConditionFree(OFPlainCondition *condition);
70 #ifdef __cplusplus
71 }
72 #endif
double OFTimeInterval
A time interval in seconds.
Definition: OFObject.h:154