2017-01-11 10:06:31 +08:00
|
|
|
#ifndef JEMALLOC_INTERNAL_MUTEX_INLINES_H
|
|
|
|
#define JEMALLOC_INTERNAL_MUTEX_INLINES_H
|
|
|
|
|
2017-02-24 06:18:07 +08:00
|
|
|
void malloc_mutex_lock_slow(malloc_mutex_t *mutex);
|
|
|
|
|
2017-01-11 10:06:31 +08:00
|
|
|
#ifndef JEMALLOC_ENABLE_INLINE
|
|
|
|
void malloc_mutex_lock(tsdn_t *tsdn, malloc_mutex_t *mutex);
|
2017-02-24 06:18:07 +08:00
|
|
|
bool malloc_mutex_trylock(malloc_mutex_t *mutex);
|
2017-01-11 10:06:31 +08:00
|
|
|
void malloc_mutex_unlock(tsdn_t *tsdn, malloc_mutex_t *mutex);
|
|
|
|
void malloc_mutex_assert_owner(tsdn_t *tsdn, malloc_mutex_t *mutex);
|
|
|
|
void malloc_mutex_assert_not_owner(tsdn_t *tsdn, malloc_mutex_t *mutex);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_MUTEX_C_))
|
2017-02-24 06:18:07 +08:00
|
|
|
JEMALLOC_INLINE void
|
|
|
|
malloc_mutex_lock_final(malloc_mutex_t *mutex) {
|
|
|
|
MALLOC_MUTEX_LOCK(mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Trylock: return false if the lock is successfully acquired. */
|
|
|
|
JEMALLOC_INLINE bool
|
|
|
|
malloc_mutex_trylock(malloc_mutex_t *mutex) {
|
|
|
|
return MALLOC_MUTEX_TRYLOCK(mutex);
|
|
|
|
}
|
|
|
|
|
2017-01-11 10:06:31 +08:00
|
|
|
JEMALLOC_INLINE void
|
2017-01-16 08:56:30 +08:00
|
|
|
malloc_mutex_lock(tsdn_t *tsdn, malloc_mutex_t *mutex) {
|
2017-02-10 01:06:22 +08:00
|
|
|
witness_assert_not_owner(tsdn, &mutex->witness);
|
2017-01-11 10:06:31 +08:00
|
|
|
if (isthreaded) {
|
2017-02-24 06:18:07 +08:00
|
|
|
if (malloc_mutex_trylock(mutex)) {
|
|
|
|
malloc_mutex_lock_slow(mutex);
|
|
|
|
}
|
|
|
|
/* We own the lock now. Update a few counters. */
|
|
|
|
lock_prof_data_t *data = &mutex->prof_data;
|
|
|
|
data->n_lock_ops++;
|
|
|
|
if (data->prev_owner != tsdn) {
|
|
|
|
data->prev_owner = tsdn;
|
|
|
|
data->n_owner_switches++;
|
|
|
|
}
|
2017-01-11 10:06:31 +08:00
|
|
|
}
|
2017-02-10 01:06:22 +08:00
|
|
|
witness_lock(tsdn, &mutex->witness);
|
2017-01-11 10:06:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
JEMALLOC_INLINE void
|
2017-01-16 08:56:30 +08:00
|
|
|
malloc_mutex_unlock(tsdn_t *tsdn, malloc_mutex_t *mutex) {
|
2017-02-10 01:06:22 +08:00
|
|
|
witness_unlock(tsdn, &mutex->witness);
|
2017-01-11 10:06:31 +08:00
|
|
|
if (isthreaded) {
|
2017-02-24 06:18:07 +08:00
|
|
|
MALLOC_MUTEX_UNLOCK(mutex);
|
2017-01-11 10:06:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JEMALLOC_INLINE void
|
2017-01-16 08:56:30 +08:00
|
|
|
malloc_mutex_assert_owner(tsdn_t *tsdn, malloc_mutex_t *mutex) {
|
2017-02-10 01:06:22 +08:00
|
|
|
witness_assert_owner(tsdn, &mutex->witness);
|
2017-01-11 10:06:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
JEMALLOC_INLINE void
|
2017-01-16 08:56:30 +08:00
|
|
|
malloc_mutex_assert_not_owner(tsdn_t *tsdn, malloc_mutex_t *mutex) {
|
2017-02-10 01:06:22 +08:00
|
|
|
witness_assert_not_owner(tsdn, &mutex->witness);
|
2017-01-11 10:06:31 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* JEMALLOC_INTERNAL_MUTEX_INLINES_H */
|