Ejemplo n.º 1
0
static void test_atomic_set_return_limit_null(void)
{
    unsigned int res = UINT_MAX;

    TEST_ASSERT_EQUAL_INT(UINT_MAX, atomic_set_return(&res, 0));
    TEST_ASSERT_EQUAL_INT(0, res);
}
Ejemplo n.º 2
0
static void test_atomic_set_return_null_limit(void)
{
    unsigned int res = 0;

    TEST_ASSERT_EQUAL_INT(0, atomic_set_return(&res, UINT_MAX));
    TEST_ASSERT_EQUAL_INT(UINT_MAX, res);
}
Ejemplo n.º 3
0
static void test_atomic_set_return_one_null(void)
{
    unsigned int res = 1;

    TEST_ASSERT_EQUAL_INT(1, atomic_set_return(&res, 0));
    TEST_ASSERT_EQUAL_INT(0, res);
}
Ejemplo n.º 4
0
static void test_atomic_set_return_null_one(void)
{
    unsigned int res = 0;

    TEST_ASSERT_EQUAL_INT(0, atomic_set_return(&res, 1));
    TEST_ASSERT_EQUAL_INT(1, res);
}
Ejemplo n.º 5
0
static void test_atomic_set_return_null_random(void)
{
    unsigned int res = 0;
    unsigned int r = 45;    /* XXX: decided by fair dice-roll ;-) */

    TEST_ASSERT_EQUAL_INT(0, atomic_set_return(&res, r));
    TEST_ASSERT_EQUAL_INT(r, res);
}
Ejemplo n.º 6
0
int pthread_spin_unlock(pthread_spinlock_t *lock)
{
    if (lock == NULL) {
        return EINVAL;
    }

    return atomic_set_return((unsigned *) lock, 0) != 0 ? 0 : EPERM;
}
Ejemplo n.º 7
0
int pthread_spin_trylock(pthread_spinlock_t *lock)
{
    if (lock == NULL) {
        return EINVAL;
    }

    return atomic_set_return((unsigned *) lock, 1) == 0 ? 0 : EBUSY;
}
Ejemplo n.º 8
0
int mutex_lock(struct mutex_t *mutex)
{
    DEBUG("%s: trying to get mutex. val: %u\n", active_thread->name, mutex->val);

    if (atomic_set_return(&mutex->val, 1) != 0) {
        /* mutex was locked. */
        mutex_wait(mutex);
    }

    return 1;
}
Ejemplo n.º 9
0
int pthread_spin_lock(pthread_spinlock_t *lock)
{
    if (lock == NULL) {
        return EINVAL;
    }

    while (atomic_set_return((unsigned *) lock, 1) != 0) {
        /* spin */
    }
    return 0;
}
Ejemplo n.º 10
0
int mutex_trylock(struct mutex_t *mutex)
{
    DEBUG("%s: trylocking to get mutex. val: %u\n", active_thread->name, mutex->val);
    return (atomic_set_return(&mutex->val, thread_pid) == 0);
}