sync.h revision 6280238c13e16a105fe658e1b6e68380cbc9f055
1/*
2 * sync.h
3 *
4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5 *
6 * Provide synchronization services.
7 *
8 * Copyright (C) 2005-2006 Texas Instruments, Inc.
9 *
10 * This package is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 */
18
19#ifndef _SYNC_H
20#define _SYNC_H
21
22#include <dspbridge/dbdefs.h>
23
24
25/* Special timeout value indicating an infinite wait: */
26#define SYNC_INFINITE  0xffffffff
27
28/**
29 * struct sync_object - the basic sync_object structure
30 * @comp:	use to signal events
31 * @multi_comp:	use to signal multiple events.
32 *
33 */
34struct sync_object{
35	struct completion comp;
36	struct completion *multi_comp;
37};
38
39/**
40 * sync_init_event() - set initial state for a sync_event element
41 * @event:	event to be initialized.
42 *
43 * Set the initial state for a sync_event element.
44 */
45
46static inline void sync_init_event(struct sync_object *event)
47{
48	init_completion(&event->comp);
49	event->multi_comp = NULL;
50}
51
52/**
53 * sync_reset_event() - reset a sync_event element
54 * @event:	event to be reset.
55 *
56 * This function reset to the initial state to @event.
57 */
58
59static inline void sync_reset_event(struct sync_object *event)
60{
61	INIT_COMPLETION(event->comp);
62	event->multi_comp = NULL;
63}
64
65/**
66 * sync_set_event() - set or signal and specified event
67 * @event:	Event to be set..
68 *
69 * set the @event, if there is an thread waiting for the event
70 * it will be waken up, this function only wakes one thread.
71 */
72
73void sync_set_event(struct sync_object *event);
74
75/**
76 * sync_wait_on_event() - waits for a event to be set.
77 * @event:	events to wait for it.
78 * @timeout	timeout on waiting for the evetn.
79 *
80 * This functios will wait until @event is set or until timeout. In case of
81 * success the function will return 0 and
82 * in case of timeout the function will return -ETIME
83 */
84
85static inline int sync_wait_on_event(struct sync_object *event,
86							unsigned timeout)
87{
88	return wait_for_completion_timeout(&event->comp,
89		msecs_to_jiffies(timeout)) ? 0 : -ETIME;
90}
91
92/**
93 * sync_wait_on_multiple_events() - waits for multiple events to be set.
94 * @events:	Array of events to wait for them.
95 * @count:	number of elements of the array.
96 * @timeout	timeout on waiting for the evetns.
97 * @pu_index	index of the event set.
98 *
99 * This functios will wait until any of the array element is set or until
100 * timeout. In case of success the function will return 0 and
101 * @pu_index will store the index of the array element set and in case
102 * of timeout the function will return -ETIME.
103 */
104
105int sync_wait_on_multiple_events(struct sync_object **events,
106				     unsigned count, unsigned timeout,
107				     unsigned *index);
108
109#endif /* _SYNC_H */
110