-
-/* int // we return 0 on acquire, 1 on syscall
- * pthread_mutex_lock( uint32_t *lvalp, // ptr to mutex LVAL/UVAL pair
- * int flags, // flags to pass kernel if we do syscall
- * uint64_t mtid, // my Thread ID
- * uint32_t mask, // bits to test in LVAL (ie, EBIT etc)
- * uint64_t *tidp, // ptr to TID field of mutex
- * int *syscall_return ); // if syscall, return value stored here
- */
-COMMPAGE_FUNCTION_START(pthread_mutex_lock, 32, 4)
- pushl %ebp // set up frame for backtrace
- movl %esp,%ebp
- pushl %esi
- pushl %edi
- pushl %ebx
- xorl %ebx,%ebx // clear "preemption pending" flag
- movl 20(%esp),%edi // %edi == ptr to LVAL/UVAL structure
- lea 20(%esp),%esi // %esi == ptr to argument list
- movl _COMM_PAGE_SPIN_COUNT, %edx
- movl 16(%esi),%ecx // get mask (ie, PTHRW_EBIT etc)
-1:
- testl PTHRW_LVAL(%edi),%ecx // is mutex available?
- jz 2f // yes, it is available
- pause
- decl %edx // decrement max spin count
- jnz 1b // keep spinning
-2:
- COMMPAGE_CALL(_COMM_PAGE_PFZ_MUTEX_LOCK,_COMM_PAGE_MUTEX_LOCK,pthread_mutex_lock)
- testl %ebx,%ebx // pending preemption?
- jz 3f
- pushl %eax // save return value across sysenter
- COMMPAGE_CALL(_COMM_PAGE_PREEMPT,_COMM_PAGE_MUTEX_LOCK,pthread_mutex_lock)
- popl %eax
-3:
- popl %ebx
- popl %edi
- popl %esi
- popl %ebp
- ret
-COMMPAGE_DESCRIPTOR(pthread_mutex_lock,_COMM_PAGE_MUTEX_LOCK,0,0)
-