ObjFW
Loading...
Searching...
No Matches
OFPlainCondition.h
Go to the documentation of this file.
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
35#if defined(OF_HAVE_PTHREADS)
36# include <pthread.h>
37typedef pthread_cond_t OFPlainCondition;
38#elif defined(OF_WINDOWS)
39# include <windows.h>
40typedef struct {
41 HANDLE event;
42 volatile int count;
43} OFPlainCondition;
44#elif defined(OF_AMIGAOS)
45# include <exec/tasks.h>
46typedef struct {
47 struct _OFPlainConditionWaitingTask {
48 struct Task *task;
49 unsigned char sigBit;
50 struct _OFPlainConditionWaitingTask *next;
51 } *waitingTasks;
52} OFPlainCondition;
53#endif
54
55#ifdef __cplusplus
56extern "C" {
57#endif
67extern int OFPlainConditionNew(OFPlainCondition *condition);
68
75extern int OFPlainConditionSignal(OFPlainCondition *condition);
76
84extern int OFPlainConditionBroadcast(OFPlainCondition *condition);
85
93extern int OFPlainConditionWait(OFPlainCondition *condition,
94 OFPlainMutex *mutex);
95
105extern int OFPlainConditionTimedWait(OFPlainCondition *condition,
106 OFPlainMutex *mutex, OFTimeInterval timeout);
107
108#if defined(OF_AMIGAOS) || defined(DOXYGEN)
118extern int OFPlainConditionWaitOrExecSignal(OFPlainCondition *condition,
119 OFPlainMutex *mutex, ULONG *signalMask);
120
131extern int OFPlainConditionTimedWaitOrExecSignal(OFPlainCondition *condition,
132 OFPlainMutex *mutex, OFTimeInterval timeout, ULONG *signalMask);
133#endif
134
141extern int OFPlainConditionFree(OFPlainCondition *condition);
142#ifdef __cplusplus
143}
144#endif
double OFTimeInterval
A time interval in seconds.
Definition OFObject.h:154
int OFPlainConditionBroadcast(OFPlainCondition *condition)
Broadcasts the specified condition, meaning it will be signaled to everyone waiting.
int OFPlainConditionSignal(OFPlainCondition *condition)
Signals the specified condition.
int OFPlainConditionNew(OFPlainCondition *condition)
Creates a new plain condition.
int OFPlainConditionTimedWait(OFPlainCondition *condition, OFPlainMutex *mutex, OFTimeInterval timeout)
Waits on the specified condition with the specified mutex with a timeout.
int OFPlainConditionWait(OFPlainCondition *condition, OFPlainMutex *mutex)
Waits on the specified condition with the specified mutex.
int OFPlainConditionTimedWaitOrExecSignal(OFPlainCondition *condition, OFPlainMutex *mutex, OFTimeInterval timeout, ULONG *signalMask)
Waits on the specified condition with the specified mutex or the specified Exec signal,...
int OFPlainConditionFree(OFPlainCondition *condition)
Destroys the specified plain condition.
int OFPlainConditionWaitOrExecSignal(OFPlainCondition *condition, OFPlainMutex *mutex, ULONG *signalMask)
Waits on the specified condition with the specified mutex or the specified Exec signal.