Reputation: 4771
I am looking at the pthread_mutex_t structure in the pthreadtypes.h file. What does the "__lock" stand for? Is it like a lock number assigned to the mutex?
typedef union
{
struct __pthread_mutex_s
{
int __lock;
unsigned int __count;
int __owner;
#if __WORDSIZE == 64
unsigned int __nusers;
#endif
/* KIND must stay at this position in the structure to maintain
binary compatibility. */
int __kind;
#if __WORDSIZE == 64
int __spins;
__pthread_list_t __list;
# define __PTHREAD_MUTEX_HAVE_PREV 1
#else
unsigned int __nusers;
__extension__ union
{
int __spins;
__pthread_slist_t __list;
};
#endif
} __data;
char __size[__SIZEOF_PTHREAD_MUTEX_T];
long int __align;
} pthread_mutex_t;
Upvotes: 5
Views: 5367
Reputation: 340426
The __lock
member of struct __pthread_mutex_s
__data
is used as a futex object on Linux. Many of the following details may differ depending on the architecture you're looking at:
See the pthread_mutex_lock.c
code for the high level locking function for pthread mutexes - __pthread_mutex_lock()
, which generally will end up calling LLL_MUTEX_LOCK()
and the definitions of LLL_MUTEX_LOCK()
and friends, which end up calling lll_lock()
, etc., in lowlevellock.h
.
The lll_lock()
macro in turn calls __lll_lock_wait_private()
, which calls lll_futex_wait()
, which makes the sys_futex
system call.
Upvotes: 4