Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0a2804ea04e02e4d259c6e46595d97b10db1569a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*******************************************************************************
 * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Eclipse Distribution License v1.0 which accompany this distribution.
 * The Eclipse Public License is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * and the Eclipse Distribution License is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 * You may elect to redistribute this code under either of these licenses.
 *
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/

/*
 * Event queue manager.
 * Event is a data pointer plus a function pointer (a.k.a. event handler).
 *
 * Posting event means placing event into event queue.
 * Dispatching event means removing event from the queue and then calling
 * event function with event data as argument.
 *
 * All events are dispatched by single thread - dispatch thread. This makes it safe
 * to access global data structures from event handlers without further synchronization,
 * while allows for high level of concurrency.
 */

#ifndef D_events
#define D_events

typedef void EventCallBack(void *);

/*
 * Causes event to have its handler
 * function called in the dispatch thread of the framework.
 * Events are dispatched in same order as queued.
 * If post_event is called from the dispatching thread
 * the handler will still be deferred until
 * all pending events have been processed.
 *
 * This function can be invoked from any thread.
 *
 * handler - the function that should be executed asynchronously.
 * arg - pointer to event data.
 */
extern void post_event(EventCallBack * handler, void * arg);

/*
 * Causes event to have its handler
 * function called in the dispatch thread of the framework.
 * The event is dispatched after given delay.
 *
 * This function can be invoked from any thread.
 *
 * handler - the function that should be executed asynchronously.
 * arg - pointer to event data.
 * us_delay - microseconds to delay event dispatch.
 */
extern void post_event_with_delay(EventCallBack * handler, void * arg, unsigned long us_delay);

/*
 * Cancel pending event with matching 'handler' and 'arg', or if event
 * is not pending and 'wait' is true then wait for matching event to
 * be posted.  Can only be called from the dispatch thread.  Returns
 * true if a posted event was canceled.
 */
extern int cancel_event(EventCallBack * handler, void * arg, int wait);

/*
 * Returns true if the calling thread is TCF event dispatch thread.
 * Use this call the ensure that a given task is being executed (or not being)
 * on dispatch thread.
 */
extern int is_dispatch_thread(void);

/*
 * Run TCF event loop.
 * Calling thread becomes event dispatch thread.
 * Event loop runs until it is canceled by cancel_event_loop().
 */
extern void run_event_loop(void);

/*
 * Cancel event loop.
 * The function causes run_event_loop() to stop event dispatching and return.
 */
extern void cancel_event_loop(void);

/*
 * Initialize event queue.
 * Should be called from main before run_event_loop().
 */
extern void ini_events_queue(void);

#endif /* D_events */

Back to the top