4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * Provide synchronization services.
8 * Copyright (C) 2005-2006 Texas Instruments, Inc.
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.
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.
22 #include <dspbridge/dbdefs.h>
23 #include <dspbridge/host_os.h>
26 /* Special timeout value indicating an infinite wait: */
27 #define SYNC_INFINITE 0xffffffff
30 * struct sync_object - the basic sync_object structure
31 * @comp: use to signal events
32 * @multi_comp: use to signal multiple events.
36 struct completion comp;
37 struct completion *multi_comp;
41 * sync_init_event() - set initial state for a sync_event element
42 * @event: event to be initialized.
44 * Set the initial state for a sync_event element.
47 static inline void sync_init_event(struct sync_object *event)
49 init_completion(&event->comp);
50 event->multi_comp = NULL;
54 * sync_reset_event() - reset a sync_event element
55 * @event: event to be reset.
57 * This function reset to the initial state to @event.
60 static inline void sync_reset_event(struct sync_object *event)
62 INIT_COMPLETION(event->comp);
63 event->multi_comp = NULL;
67 * sync_set_event() - set or signal and specified event
68 * @event: Event to be set..
70 * set the @event, if there is an thread waiting for the event
71 * it will be waken up, this function only wakes one thread.
74 void sync_set_event(struct sync_object *event);
77 * sync_wait_on_event() - waits for a event to be set.
78 * @event: events to wait for it.
79 * @timeout timeout on waiting for the evetn.
81 * This functios will wait until @event is set or until timeout. In case of
82 * success the function will return 0 and
83 * in case of timeout the function will return -ETIME
84 * in case of signal the function will return -ERESTARTSYS
87 static inline int sync_wait_on_event(struct sync_object *event,
92 res = wait_for_completion_interruptible_timeout(&event->comp,
93 msecs_to_jiffies(timeout));
103 * sync_wait_on_multiple_events() - waits for multiple events to be set.
104 * @events: Array of events to wait for them.
105 * @count: number of elements of the array.
106 * @timeout timeout on waiting for the evetns.
107 * @pu_index index of the event set.
109 * This functios will wait until any of the array element is set or until
110 * timeout. In case of success the function will return 0 and
111 * @pu_index will store the index of the array element set and in case
112 * of timeout the function will return -ETIME.
115 int sync_wait_on_multiple_events(struct sync_object **events,
116 unsigned count, unsigned timeout,