Rev 1229 | Rev 1375 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1229 | Rev 1248 | ||
---|---|---|---|
Line 24... | Line 24... | ||
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
- | 29 | /** |
|
- | 30 | * @file waitq.c |
|
- | 31 | * @brief Wait queue. |
|
- | 32 | * |
|
- | 33 | * Wait queue is the basic synchronization primitive upon all |
|
- | 34 | * other synchronization primitives build. |
|
- | 35 | * |
|
- | 36 | * It allows threads to wait for an event in first-come, first-served |
|
- | 37 | * fashion. Conditional operation as well as timeouts and interruptions |
|
- | 38 | * are supported. |
|
- | 39 | */ |
|
- | 40 | ||
29 | #include <synch/waitq.h> |
41 | #include <synch/waitq.h> |
30 | #include <synch/synch.h> |
42 | #include <synch/synch.h> |
31 | #include <synch/spinlock.h> |
43 | #include <synch/spinlock.h> |
32 | #include <proc/thread.h> |
44 | #include <proc/thread.h> |
33 | #include <proc/scheduler.h> |
45 | #include <proc/scheduler.h> |
Line 158... | Line 170... | ||
158 | * |
170 | * |
159 | * @param wq Pointer to wait queue. |
171 | * @param wq Pointer to wait queue. |
160 | * @param usec Timeout in microseconds. |
172 | * @param usec Timeout in microseconds. |
161 | * @param nonblocking Blocking vs. non-blocking operation mode switch. |
173 | * @param nonblocking Blocking vs. non-blocking operation mode switch. |
162 | * |
174 | * |
163 | * If @usec is greater than zero, regardless of the value of @nonblocking, |
175 | * If usec is greater than zero, regardless of the value of nonblocking, |
164 | * the call will not return until either timeout or wakeup comes. |
176 | * the call will not return until either timeout or wakeup comes. |
165 | * |
177 | * |
166 | * If @usec is zero and @nonblocking is zero (false), the call |
178 | * If usec is zero and @nonblocking is zero (false), the call |
167 | * will not return until wakeup comes. |
179 | * will not return until wakeup comes. |
168 | * |
180 | * |
169 | * If @usec is zero and @nonblocking is non-zero (true), the call will |
181 | * If usec is zero and nonblocking is non-zero (true), the call will |
170 | * immediately return, reporting either success or failure. |
182 | * immediately return, reporting either success or failure. |
171 | * |
183 | * |
172 | * @return Returns one of: ESYNCH_WOULD_BLOCK, ESYNCH_TIMEOUT, |
184 | * @return Returns one of: ESYNCH_WOULD_BLOCK, ESYNCH_TIMEOUT, |
173 | * ESYNCH_OK_ATOMIC, ESYNCH_OK_BLOCKED. |
185 | * ESYNCH_OK_ATOMIC, ESYNCH_OK_BLOCKED. |
174 | * |
186 | * |
175 | * ESYNCH_WOULD_BLOCK means that the sleep failed because at the time |
187 | * @li ESYNCH_WOULD_BLOCK means that the sleep failed because at the time |
176 | * of the call there was no pending wakeup. |
188 | * of the call there was no pending wakeup. |
177 | * |
189 | * |
178 | * ESYNCH_TIMEOUT means that the sleep timed out. |
190 | * @li ESYNCH_TIMEOUT means that the sleep timed out. |
179 | * |
191 | * |
180 | * ESYNCH_INTERRUPTED means that somebody interrupted the sleeping thread. |
192 | * @li ESYNCH_INTERRUPTED means that somebody interrupted the sleeping thread. |
181 | * |
193 | * |
182 | * ESYNCH_OK_ATOMIC means that the sleep succeeded and that there was |
194 | * @li ESYNCH_OK_ATOMIC means that the sleep succeeded and that there was |
183 | * a pending wakeup at the time of the call. The caller was not put |
195 | * a pending wakeup at the time of the call. The caller was not put |
184 | * asleep at all. |
196 | * asleep at all. |
185 | * |
197 | * |
186 | * ESYNCH_OK_BLOCKED means that the sleep succeeded; the full sleep was |
198 | * @li ESYNCH_OK_BLOCKED means that the sleep succeeded; the full sleep was |
187 | * attempted. |
199 | * attempted. |
188 | */ |
200 | */ |
189 | int waitq_sleep_timeout(waitq_t *wq, __u32 usec, int nonblocking) |
201 | int waitq_sleep_timeout(waitq_t *wq, __u32 usec, int nonblocking) |
190 | { |
202 | { |
191 | volatile ipl_t ipl; /* must be live after context_restore() */ |
203 | volatile ipl_t ipl; /* must be live after context_restore() */ |