Beispiel #1
0
void __cilkrts_mutex_lock(__cilkrts_worker *w, struct mutex *m)
{
    int count;
    const int maxspin = 1000; /* SWAG */

    NOTE_INTERVAL(w, INTERVAL_MUTEX_LOCK);
    if (!TRY_ACQUIRE(m)) {
        START_INTERVAL(w, INTERVAL_MUTEX_LOCK_SPINNING);
        count = 0;
        do {
            do {
                __cilkrts_short_pause();
                if (++count >= maxspin) {
                    STOP_INTERVAL(w, INTERVAL_MUTEX_LOCK_SPINNING);
                    START_INTERVAL(w, INTERVAL_MUTEX_LOCK_YIELDING);
                    /* let the OS reschedule every once in a while */
                    __cilkrts_yield();
                    STOP_INTERVAL(w, INTERVAL_MUTEX_LOCK_YIELDING);
                    START_INTERVAL(w, INTERVAL_MUTEX_LOCK_SPINNING);
                    count = 0;
                }
            } while (m->lock != 0);
        } while (!TRY_ACQUIRE(m));
        STOP_INTERVAL(w, INTERVAL_MUTEX_LOCK_SPINNING);
    }

    CILK_ASSERT(m->owner == 0);
    m->owner = w;
}
Beispiel #2
0
void spin_mutex_lock(struct spin_mutex *m)
{
    int count;
    const int maxspin = 1000; /* SWAG */
    if (!TRY_ACQUIRE(m)) {
        count = 0;
        do {
            do {
                __cilkrts_short_pause();
                if (++count >= maxspin) {
                    /* let the OS reschedule every once in a while */
                    __cilkrts_yield();
                    count = 0;
                }
            } while (m->lock != 0);
        } while (!TRY_ACQUIRE(m));
    }
}
Beispiel #3
0
int __cilkrts_mutex_trylock(__cilkrts_worker *w, struct mutex *m)
{
    NOTE_INTERVAL(w, INTERVAL_MUTEX_TRYLOCK);
    if (TRY_ACQUIRE(m)) {
        CILK_ASSERT(m->owner == 0);
        m->owner = w;
        return 1;
    } else {
        return 0;
    }
}
Beispiel #4
0
int spin_mutex_trylock(struct spin_mutex *m)
{
    return TRY_ACQUIRE(m);
}