lt_test_trylocks()
{
boolean_t success;
+ extern unsigned int real_ncpus;
/*
* First mtx try lock succeeds, second fails.
lt_start_trylock_thread(lt_trylock_hw_lock_with_to);
success = hw_lock_to(<_hw_lock, 100);
T_ASSERT_NOTNULL(success, "First spin lock with timeout should succeed");
+ if (real_ncpus == 1) {
+ mp_enable_preemption(); /* if we re-enable preemption, the other thread can timeout and exit */
+ }
OSIncrementAtomic((volatile SInt32*)<_thread_lock_grabbed);
lt_wait_for_lock_test_threads();
T_ASSERT_NULL(lt_thread_lock_success, "Second spin lock with timeout should fail and timeout");
+ if (real_ncpus == 1) {
+ mp_disable_preemption(); /* don't double-enable when we unlock */
+ }
hw_lock_unlock(<_hw_lock);
lt_reset();
OSMemoryBarrier();
lt_start_trylock_thread(lt_trylock_hw_lock_with_to);
hw_lock_lock(<_hw_lock);
+ if (real_ncpus == 1) {
+ mp_enable_preemption(); /* if we re-enable preemption, the other thread can timeout and exit */
+ }
OSIncrementAtomic((volatile SInt32*)<_thread_lock_grabbed);
lt_wait_for_lock_test_threads();
T_ASSERT_NULL(lt_thread_lock_success, "after taking a spin lock, lock attempt with timeout should fail");
+ if (real_ncpus == 1) {
+ mp_disable_preemption(); /* don't double-enable when we unlock */
+ }
hw_lock_unlock(<_hw_lock);
success = lck_spin_try_lock(<_lck_spin_t);
lt_target_done_threads = 1;
lt_start_trylock_thread(lt_trylock_spin_try_lock);
lck_spin_lock(<_lck_spin_t);
+ if (real_ncpus == 1) {
+ mp_enable_preemption(); /* if we re-enable preemption, the other thread can timeout and exit */
+ }
OSIncrementAtomic((volatile SInt32*)<_thread_lock_grabbed);
lt_wait_for_lock_test_threads();
T_ASSERT_NULL(lt_thread_lock_success, "spin trylock attempt of previously held lock should fail");
+ if (real_ncpus == 1) {
+ mp_disable_preemption(); /* don't double-enable when we unlock */
+ }
lck_spin_unlock(<_lck_spin_t);
return KERN_SUCCESS;