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); }
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); }
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); }
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); }
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); }
int pthread_spin_unlock(pthread_spinlock_t *lock) { if (lock == NULL) { return EINVAL; } return atomic_set_return((unsigned *) lock, 0) != 0 ? 0 : EPERM; }
int pthread_spin_trylock(pthread_spinlock_t *lock) { if (lock == NULL) { return EINVAL; } return atomic_set_return((unsigned *) lock, 1) == 0 ? 0 : EBUSY; }
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; }
int pthread_spin_lock(pthread_spinlock_t *lock) { if (lock == NULL) { return EINVAL; } while (atomic_set_return((unsigned *) lock, 1) != 0) { /* spin */ } return 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); }