- xorl %ecx,%ecx
- xchgl %ecx,M_ILK
-
- ENABLE_PREEMPTION(%eax)
-
-#if ETAP_LOCK_TRACE
- movl L_PC,%eax /* fetch pc */
- pushl SWT_LO /* push wait time (low) */
- pushl SWT_HI /* push wait time (high) */
- pushl %eax /* push pc */
- pushl %edx /* push mutex address */
- call EXT(etap_mutex_hold) /* collect hold timestamp */
- addl $16+12,%esp /* clean up stack, adjusting for locals */
-#endif /* ETAP_LOCK_TRACE */
-
- EMARF
- ret
-
-ml_fail:
-#if ETAP_LOCK_TRACE
- cmp $0,MISSED /* did we already take a wait timestamp? */
- jne ml_block /* yup. carry-on */
- pushl %edx /* push mutex address */
- call EXT(etap_mutex_miss) /* get wait timestamp */
- movl %eax,SWT_HI /* set wait time (high word) */
- movl %edx,SWT_LO /* set wait time (low word) */
- popl %edx /* clean up stack */
- movl $1,MISSED /* mark wait timestamp as taken */
-#endif /* ETAP_LOCK_TRACE */
-
-ml_block:
- CHECK_MYLOCK(M_THREAD)
- xorl %eax,%eax
- pushl %eax /* no promotion here yet */
- pushl %edx /* push mutex address */
- call EXT(mutex_lock_wait) /* wait for the lock */
- addl $8,%esp
- movl L_ARG0,%edx /* refetch lock pointer */
- jmp ml_retry /* and try again */
-
-ENTRY2(mutex_try,_mutex_try)
- FRAME
+
+Llml_slow:
+ test $M_ILOCKED_MSK, %ecx /* is the interlock held */
+ jz Llml_contended /* no, must have been the mutex */
+
+ cmp $(MUTEX_DESTROYED), %ecx /* check to see if its marked destroyed */
+ je lck_mtx_destroyed
+ cmp $(MUTEX_IND), %ecx /* Is this an indirect mutex? */
+ jne Llml_loop /* no... must be interlocked */
+
+ LMTX_ENTER_EXTENDED
+
+ mov M_STATE(%rdx), %ecx
+ test $(M_SPIN_MSK), %ecx
+ jz Llml_loop1
+
+ LMTX_UPDATE_MISS /* M_SPIN_MSK was set, so M_ILOCKED_MSK must also be present */
+Llml_loop:
+ PAUSE
+ mov M_STATE(%rdx), %ecx
+Llml_loop1:
+ test $(M_ILOCKED_MSK | M_MLOCKED_MSK), %ecx
+ jz Llml_try
+ test $(M_MLOCKED_MSK), %ecx
+ jnz Llml_contended /* mutex owned by someone else, go contend for it */
+ jmp Llml_loop
+
+Llml_busy_disabled:
+ PREEMPTION_ENABLE
+ jmp Llml_loop