]> git.meshlink.io Git - catta/blob - include/catta/thread-watch.h
moved back windows compat headers and fixed catta headers to stop clutter dependent...
[catta] / include / catta / thread-watch.h
1 #ifndef foothreadedwatchhfoo
2 #define foothreadedwatchhfoo
3
4 /***
5   This file is part of catta.
6
7   catta is free software; you can redistribute it and/or modify it
8   under the terms of the GNU Lesser General Public License as
9   published by the Free Software Foundation; either version 2.1 of the
10   License, or (at your option) any later version.
11
12   catta is distributed in the hope that it will be useful, but WITHOUT
13   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15   Public License for more details.
16
17   You should have received a copy of the GNU Lesser General Public
18   License along with catta; if not, write to the Free Software
19   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20   USA.
21 ***/
22
23 /** \file thread-watch.h Threaded poll() based main loop implementation */
24
25 #include <catta/cdecl.h>
26 #include <catta/watch.h>
27
28 CATTA_C_DECL_BEGIN
29
30 /** A main loop object that runs an CattaSimplePoll in its own thread. \since 0.6.4 */
31 typedef struct CattaThreadedPoll CattaThreadedPoll;
32
33 /** Create a new event loop object. This will allocate the internal
34  * CattaSimplePoll, but will not start the helper thread. \since 0.6.4 */
35 CattaThreadedPoll *catta_threaded_poll_new(void);
36
37 /** Free an event loop object. This will stop the associated event loop
38  * thread (if it is running). \since 0.6.4 */
39 void catta_threaded_poll_free(CattaThreadedPoll *p);
40
41 /** Return the abstracted poll API object for this event loop
42  * object. The will return the same pointer each time it is
43  * called. \since 0.6.4 */
44 const CattaPoll* catta_threaded_poll_get(CattaThreadedPoll *p);
45
46 /** Start the event loop helper thread. After the thread has started
47  * you must make sure to access the event loop object
48  * (CattaThreadedPoll, CattaPoll and all its associated objects)
49  * synchronized, i.e. with proper locking. You may want to use
50  * catta_threaded_poll_lock()/catta_threaded_poll_unlock() for this,
51  * which will lock the the entire event loop. Please note that event
52  * loop callback functions are called from the event loop helper thread
53  * with that lock held, i.e. catta_threaded_poll_lock() calls are not
54  * required from event callbacks. \since 0.6.4 */
55 int catta_threaded_poll_start(CattaThreadedPoll *p);
56
57 /** Request that the event loop quits and the associated thread
58  stops. Call this from outside the helper thread if you want to shut
59  it down. \since 0.6.4 */
60 int catta_threaded_poll_stop(CattaThreadedPoll *p);
61
62 /** Request that the event loop quits and the associated thread
63  stops. Call this from inside the helper thread if you want to shut it
64  down. \since 0.6.4  */
65 void catta_threaded_poll_quit(CattaThreadedPoll *p);
66
67 /** Lock the main loop object. Use this if you want to access the event
68  * loop objects (such as creating a new event source) from anything
69  * else but the event loop helper thread, i.e. from anything else but event
70  * loop callbacks \since 0.6.4  */
71 void catta_threaded_poll_lock(CattaThreadedPoll *p);
72
73 /** Unlock the event loop object, use this as counterpart to
74  * catta_threaded_poll_lock() \since 0.6.4 */
75 void catta_threaded_poll_unlock(CattaThreadedPoll *p);
76
77 CATTA_C_DECL_END
78
79 #endif