// Grab a plain mutex.
INLINE void dvmLockMutex(pthread_mutex_t
pMutex) { int cc __attribute__ ((__unused__)) =
pthread_mutex_lock(pMutex); assert(cc == 0);
}and here's pthread_mutex_lock.
int pthread_mutex_lock(pthread_mutex_t mutex) { if (mutex->kind == PTHREAD_MUTEX_NORMAL) { if (atomic_exchange(&mutex->lock, 1) != 0) { while (atomic_exchange(&mutex->lock, -1) != 0) {
if (wait(mutex->event, INFINITE) != 0) return EINVAL;
}
}
}
else
{
pthread_t self = pthread_self();
if (atomic_exchange(&mutex->lock, 1) == 0)
{
mutex->recursion = 1;
mutex->owner = self;
}
else
{
if (pthread_equal(mutex->owner, self))
{
if (mutex->kind == PTHREAD_MUTEX_RECURSIVE)
mutex->recursion++;
else
return EDEADLK;
}
else
{
while (atomic_exchange(&mutex->lock, -1) != 0)
{
if (wait(mutex->event, INFINITE) != 0) return EINVAL;
mutex->recursion = 1;
mutex->owner = self;
}
}
}
}
return 0;
}and here's an excerpt of dalvik/vm/Thread.c
Notes on Threading
All threads are native pthreads. All threads, except the JDWP debugger thread, are visible to code running in the VM and to the debugger. (We don't want the debugger to try to manipulate the thread that listens for instructions from the debugger.) Internal VM threads are in the "system" ThreadGroup, all others are in the "main" ThreadGroup, per convention.
The GC only runs when all threads have been suspended.
...