Subversion Repositories HelenOS

Rev

Rev 2310 | Rev 2914 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2310 Rev 2909
Line 52... Line 52...
52
#include <time/timeout.h>
52
#include <time/timeout.h>
53
#include <arch.h>
53
#include <arch.h>
54
#include <context.h>
54
#include <context.h>
55
#include <adt/list.h>
55
#include <adt/list.h>
56
 
56
 
57
static void waitq_timeouted_sleep(void *data);
57
static void waitq_sleep_timed_out(void *data);
58
 
58
 
59
/** Initialize wait queue
59
/** Initialize wait queue
60
 *
60
 *
61
 * Initialize wait queue.
61
 * Initialize wait queue.
62
 *
62
 *
Line 79... Line 79...
79
 * overlap. In that case it behaves just as though there was no
79
 * overlap. In that case it behaves just as though there was no
80
 * timeout at all.
80
 * timeout at all.
81
 *
81
 *
82
 * @param data Pointer to the thread that called waitq_sleep_timeout().
82
 * @param data Pointer to the thread that called waitq_sleep_timeout().
83
 */
83
 */
84
void waitq_timeouted_sleep(void *data)
84
void waitq_sleep_timed_out(void *data)
85
{
85
{
86
    thread_t *t = (thread_t *) data;
86
    thread_t *t = (thread_t *) data;
87
    waitq_t *wq;
87
    waitq_t *wq;
88
    bool do_wakeup = false;
88
    bool do_wakeup = false;
89
    DEADLOCK_PROBE_INIT(p_wqlock);
89
    DEADLOCK_PROBE_INIT(p_wqlock);
Line 198... Line 198...
198
 * the call will not return until wakeup or interruption comes.
198
 * the call will not return until wakeup or interruption comes.
199
 *
199
 *
200
 * If usec is zero and the SYNCH_FLAGS_NON_BLOCKING bit is set in flags, the
200
 * If usec is zero and the SYNCH_FLAGS_NON_BLOCKING bit is set in flags, the
201
 * call will immediately return, reporting either success or failure.
201
 * call will immediately return, reporting either success or failure.
202
 *
202
 *
203
 * @return One of: ESYNCH_WOULD_BLOCK, ESYNCH_TIMEOUT, ESYNCH_INTERRUPTED,
203
 * @return      Returns one of ESYNCH_WOULD_BLOCK, ESYNCH_TIMEOUT,
204
 * ESYNCH_OK_ATOMIC, ESYNCH_OK_BLOCKED.
204
 *          ESYNCH_INTERRUPTED, ESYNCH_OK_ATOMIC and
-
 
205
 *          ESYNCH_OK_BLOCKED.
205
 *
206
 *
206
 * @li ESYNCH_WOULD_BLOCK means that the sleep failed because at the time of the
207
 * @li  ESYNCH_WOULD_BLOCK means that the sleep failed because at the time of
207
 * call there was no pending wakeup.
208
 *  the call there was no pending wakeup.
208
 *
209
 *
209
 * @li ESYNCH_TIMEOUT means that the sleep timed out.
210
 * @li  ESYNCH_TIMEOUT means that the sleep timed out.
210
 *
211
 *
211
 * @li ESYNCH_INTERRUPTED means that somebody interrupted the sleeping thread.
212
 * @li  ESYNCH_INTERRUPTED means that somebody interrupted the sleeping thread.
212
 *
213
 *
Line 353... Line 354...
353
            spinlock_unlock(&THREAD->lock);
354
            spinlock_unlock(&THREAD->lock);
354
            return ESYNCH_TIMEOUT;
355
            return ESYNCH_TIMEOUT;
355
        }
356
        }
356
        THREAD->timeout_pending = true;
357
        THREAD->timeout_pending = true;
357
        timeout_register(&THREAD->sleep_timeout, (uint64_t) usec,
358
        timeout_register(&THREAD->sleep_timeout, (uint64_t) usec,
358
            waitq_timeouted_sleep, THREAD);
359
            waitq_sleep_timed_out, THREAD);
359
    }
360
    }
360
 
361
 
361
    list_append(&THREAD->wq_link, &wq->head);
362
    list_append(&THREAD->wq_link, &wq->head);
362
 
363
 
363
    /*
364
    /*
Line 429... Line 430...
429
   
430
   
430
    /*
431
    /*
431
     * Lock the thread prior to removing it from the wq.
432
     * Lock the thread prior to removing it from the wq.
432
     * This is not necessary because of mutual exclusion
433
     * This is not necessary because of mutual exclusion
433
     * (the link belongs to the wait queue), but because
434
     * (the link belongs to the wait queue), but because
434
     * of synchronization with waitq_timeouted_sleep()
435
     * of synchronization with waitq_sleep_timed_out()
435
     * and thread_interrupt_sleep().
436
     * and thread_interrupt_sleep().
436
     *
437
     *
437
     * In order for these two functions to work, the following
438
     * In order for these two functions to work, the following
438
     * invariant must hold:
439
     * invariant must hold:
439
     *
440
     *