 复制if (__sync_lock_test_and_set(mutex->lock_word,擎特 1) == 0) { get mutex successfully; return; } loop1: i = 0; loop2: /*指示点1*/ while (mutex->lock_word ! = 0 && i < SPIN_ROUNDS) { random spin using ut_delay, spin maxtime depend on SPIN_WAIT_DELAY; i++; } if (i == SPIN_ROUNDS) { yield_cpu; } /*指示点2*/ if (__sync_lock_test_and_set(mutex->lock_word, 1) == 0) { get mutex successfully; return; } if (i < SPIN_ROUNDS) { goto loop2 } /*指示点4*/ get cell from sync array and call os_event_reset(mutex->event); mutex->waiter =1; /*指示点3*/ for (i = 0; i < 4; i++) { if (__sync_lock_test_and_set(mutex->lock_word, 1) == 0) { get mutex successfully; free cell; return; } } sync array wait and os_event_wait(mutex->event); goto loop1; 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71. |