ObjFW
OFRunLoop.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
3  * Jonathan Schleifer <js@heap.zone>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "OFObject.h"
18 #ifdef OF_HAVE_SOCKETS
19 # import "OFTCPSocket.h"
20 #endif
21 
22 OF_ASSUME_NONNULL_BEGIN
23 
24 @class OFSortedList OF_GENERIC(ObjectType);
25 #ifdef OF_HAVE_THREADS
26 @class OFMutex;
27 @class OFCondition;
28 #endif
29 #ifdef OF_HAVE_SOCKETS
31 #endif
32 @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType);
33 @class OFTimer;
34 @class OFDate;
35 
41 @interface OFRunLoop: OFObject
42 #ifdef OF_HAVE_SOCKETS
44 #endif
45 {
46  OFSortedList *_timersQueue;
47 #ifdef OF_HAVE_THREADS
48  OFMutex *_timersQueueLock;
49 #endif
50 #if defined(OF_HAVE_SOCKETS)
51  OFKernelEventObserver *_kernelEventObserver;
52  OFMutableDictionary *_readQueues;
53 #elif defined(OF_HAVE_THREADS)
54  OFCondition *_condition;
55 #endif
56  volatile bool _stop;
57 }
58 
65 
72 
78 - (void)addTimer: (OFTimer *)timer;
79 
83 - (void)run;
84 
90 - (void)runUntilDate: (nullable OFDate *)deadline;
91 
96 - (void)stop;
97 @end
98 
99 OF_ASSUME_NONNULL_END
void stop()
Stops the run loop. If there is still an operation being executed, it is finished before the run loop...
Definition: OFRunLoop.m:771
OFRunLoop * currentRunLoop()
Returns the run loop for the current thread.
Definition: OFRunLoop.m:346
A protocol that needs to be implemented by delegates for OFKernelEventObserver.
Definition: OFKernelEventObserver.h:28
An abstract class for storing and changing objects in a dictionary.
Definition: OFMutableDictionary.h:39
A class for creating mutual exclusions.
Definition: OFMutex.h:29
A class providing a run loop for the application and its processes.
Definition: OFRunLoop.h:41
OFRunLoop * mainRunLoop()
Returns the run loop for the main thread.
Definition: OFRunLoop.m:341
The root class for all other classes inside ObjFW.
Definition: OFObject.h:379
A class for storing, accessing and comparing dates.
Definition: OFDate.h:30
A class which provides easy to use sorted double-linked lists.
Definition: OFSortedList.h:29
A class that can observe multiple kernel events (e.g. streams being ready to read) at once...
Definition: OFKernelEventObserver.h:108
void run()
Starts the run loop.
Definition: OFRunLoop.m:652
A class for creating and firing timers.
Definition: OFTimer.h:44
A class implementing a condition variable for thread synchronization.
Definition: OFCondition.h:28