ObjFW
condition.h
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #include "objfw-defs.h"
17 
18 #include "platform.h"
19 
20 #if !defined(OF_HAVE_THREADS) || \
21  (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS))
22 # error No conditions available!
23 #endif
24 
25 /* For of_time_interval_t */
26 #import "OFObject.h"
27 
28 #import "mutex.h"
29 
30 #if defined(OF_HAVE_PTHREADS)
31 # include <pthread.h>
32 typedef pthread_cond_t of_condition_t;
33 #elif defined(OF_WINDOWS)
34 # include <windows.h>
35 typedef struct {
36  HANDLE event;
37  volatile int count;
38 } of_condition_t;
39 #elif defined(OF_AMIGAOS)
40 # include <exec/tasks.h>
41 typedef struct {
42  struct of_condition_waiting_task {
43  struct Task *task;
44  unsigned char sigBit;
45  struct of_condition_waiting_task *next;
46  } *waitingTasks;
47 } of_condition_t;
48 #endif
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 extern int of_condition_new(of_condition_t *condition);
54 extern int of_condition_signal(of_condition_t *condition);
55 extern int of_condition_broadcast(of_condition_t *condition);
56 extern int of_condition_wait(of_condition_t *condition, of_mutex_t *mutex);
57 extern int of_condition_timed_wait(of_condition_t *condition,
58  of_mutex_t *mutex, of_time_interval_t timeout);
59 #ifdef OF_AMIGAOS
60 extern int of_condition_wait_or_signal(of_condition_t *condition,
61  of_mutex_t *mutex, ULONG *signalMask);
62 extern int of_condition_timed_wait_or_signal(of_condition_t *condition,
63  of_mutex_t *mutex, of_time_interval_t timeout, ULONG *signalMask);
64 #endif
65 extern int of_condition_free(of_condition_t *condition);
66 #ifdef __cplusplus
67 }
68 #endif
double of_time_interval_t
A time interval in seconds.
Definition: OFObject.h:138