mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-23 21:21:05 +01:00
Use UMTX_OP_WAIT_UINT_PRIVATE and UMTX_OP_WAKE_PRIVATE to save
time in kernel(avoid VM lookup).
This commit is contained in:
parent
727158f6f6
commit
8d6a11a070
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=178647
@ -192,7 +192,7 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
|
||||
new_thread->tid = TID_TERMINATED;
|
||||
if (new_thread->flags & THR_FLAGS_NEED_SUSPEND) {
|
||||
new_thread->cycle++;
|
||||
_thr_umtx_wake(&new_thread->cycle, INT_MAX);
|
||||
_thr_umtx_wake(&new_thread->cycle, INT_MAX, 0);
|
||||
}
|
||||
THR_THREAD_UNLOCK(curthread, new_thread);
|
||||
THREAD_LIST_LOCK(curthread);
|
||||
|
@ -125,7 +125,7 @@ _pthread_exit(void *status)
|
||||
curthread->state = PS_DEAD;
|
||||
if (curthread->flags & THR_FLAGS_NEED_SUSPEND) {
|
||||
curthread->cycle++;
|
||||
_thr_umtx_wake(&curthread->cycle, INT_MAX);
|
||||
_thr_umtx_wake(&curthread->cycle, INT_MAX, 0);
|
||||
}
|
||||
THR_UNLOCK(curthread);
|
||||
/*
|
||||
|
@ -315,7 +315,7 @@ struct pthread {
|
||||
struct umutex lock;
|
||||
|
||||
/* Internal condition variable cycle number. */
|
||||
long cycle;
|
||||
uint32_t cycle;
|
||||
|
||||
/* How many low level locks the thread held. */
|
||||
int locklevel;
|
||||
|
@ -87,5 +87,5 @@ resume_common(struct pthread *thread)
|
||||
/* Clear the suspend flag: */
|
||||
thread->flags &= ~THR_FLAGS_NEED_SUSPEND;
|
||||
thread->cycle++;
|
||||
_thr_umtx_wake(&thread->cycle, 1);
|
||||
_thr_umtx_wake(&thread->cycle, 1, 0);
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ sem_cancel_handler(void *arg)
|
||||
|
||||
atomic_add_int(&(*sem)->nwaiters, -1);
|
||||
if ((*sem)->nwaiters && (*sem)->count)
|
||||
_thr_umtx_wake(&(*sem)->count, 1);
|
||||
_thr_umtx_wake(&(*sem)->count, 1, 0);
|
||||
}
|
||||
|
||||
int
|
||||
@ -208,7 +208,7 @@ _sem_wait(sem_t *sem)
|
||||
atomic_add_int(&(*sem)->nwaiters, 1);
|
||||
THR_CLEANUP_PUSH(curthread, sem_cancel_handler, sem);
|
||||
_thr_cancel_enter(curthread);
|
||||
retval = _thr_umtx_wait_uint(&(*sem)->count, 0, NULL);
|
||||
retval = _thr_umtx_wait_uint(&(*sem)->count, 0, NULL, 0);
|
||||
_thr_cancel_leave(curthread);
|
||||
THR_CLEANUP_POP(curthread, 0);
|
||||
atomic_add_int(&(*sem)->nwaiters, -1);
|
||||
@ -255,7 +255,7 @@ _sem_timedwait(sem_t * __restrict sem,
|
||||
atomic_add_int(&(*sem)->nwaiters, 1);
|
||||
THR_CLEANUP_PUSH(curthread, sem_cancel_handler, sem);
|
||||
_thr_cancel_enter(curthread);
|
||||
retval = _thr_umtx_wait_uint(&(*sem)->count, 0, &ts2);
|
||||
retval = _thr_umtx_wait_uint((uint32_t*)&(*sem)->count, 0, &ts2, 0);
|
||||
_thr_cancel_leave(curthread);
|
||||
THR_CLEANUP_POP(curthread, 0);
|
||||
atomic_add_int(&(*sem)->nwaiters, -1);
|
||||
@ -283,7 +283,7 @@ _sem_post(sem_t *sem)
|
||||
atomic_add_rel_int(&(*sem)->count, 1);
|
||||
|
||||
if ((*sem)->nwaiters) {
|
||||
retval = _thr_umtx_wake(&(*sem)->count, 1);
|
||||
retval = _thr_umtx_wake(&(*sem)->count, 1, 0);
|
||||
if (retval != 0)
|
||||
retval = -1;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ _thr_ast(struct pthread *curthread)
|
||||
void
|
||||
_thr_suspend_check(struct pthread *curthread)
|
||||
{
|
||||
long cycle;
|
||||
uint32_t cycle;
|
||||
int err;
|
||||
|
||||
if (curthread->force_exit)
|
||||
@ -114,7 +114,7 @@ _thr_suspend_check(struct pthread *curthread)
|
||||
cycle = curthread->cycle;
|
||||
|
||||
/* Wake the thread suspending us. */
|
||||
_thr_umtx_wake(&curthread->cycle, INT_MAX);
|
||||
_thr_umtx_wake(&curthread->cycle, INT_MAX, 0);
|
||||
|
||||
/*
|
||||
* if we are from pthread_exit, we don't want to
|
||||
@ -124,7 +124,7 @@ _thr_suspend_check(struct pthread *curthread)
|
||||
break;
|
||||
curthread->flags |= THR_FLAGS_SUSPENDED;
|
||||
THR_UMUTEX_UNLOCK(curthread, &(curthread)->lock);
|
||||
_thr_umtx_wait(&curthread->cycle, cycle, NULL);
|
||||
_thr_umtx_wait_uint(&curthread->cycle, cycle, NULL, 0);
|
||||
THR_UMUTEX_LOCK(curthread, &(curthread)->lock);
|
||||
curthread->flags &= ~THR_FLAGS_SUSPENDED;
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ suspend_common(struct pthread *curthread, struct pthread *thread,
|
||||
THR_THREAD_UNLOCK(curthread, thread);
|
||||
_thr_send_sig(thread, SIGCANCEL);
|
||||
if (waitok) {
|
||||
_thr_umtx_wait(&thread->cycle, tmp, NULL);
|
||||
_thr_umtx_wait_uint(&thread->cycle, tmp, NULL, 0);
|
||||
THR_THREAD_LOCK(curthread, thread);
|
||||
} else {
|
||||
THR_THREAD_LOCK(curthread, thread);
|
||||
|
@ -94,19 +94,20 @@ _thr_umtx_wait(volatile long *mtx, long id, const struct timespec *timeout)
|
||||
}
|
||||
|
||||
int
|
||||
_thr_umtx_wait_uint(volatile u_int *mtx, u_int id, const struct timespec *timeout)
|
||||
_thr_umtx_wait_uint(volatile u_int *mtx, u_int id, const struct timespec *timeout, int shared)
|
||||
{
|
||||
if (timeout && (timeout->tv_sec < 0 || (timeout->tv_sec == 0 &&
|
||||
timeout->tv_nsec <= 0)))
|
||||
return (ETIMEDOUT);
|
||||
return _umtx_op_err(__DEVOLATILE(void *, mtx), UMTX_OP_WAIT_UINT, id, 0,
|
||||
__DECONST(void*, timeout));
|
||||
return _umtx_op_err(__DEVOLATILE(void *, mtx),
|
||||
shared ? UMTX_OP_WAIT_UINT : UMTX_OP_WAIT_UINT_PRIVATE, id, 0,
|
||||
__DECONST(void*, timeout));
|
||||
}
|
||||
|
||||
int
|
||||
_thr_umtx_wake(volatile void *mtx, int nr_wakeup)
|
||||
_thr_umtx_wake(volatile void *mtx, int nr_wakeup, int shared)
|
||||
{
|
||||
return _umtx_op_err(__DEVOLATILE(void *, mtx), UMTX_OP_WAKE,
|
||||
return _umtx_op_err(__DEVOLATILE(void *, mtx), shared ? UMTX_OP_WAKE : UMTX_OP_WAKE_PRIVATE,
|
||||
nr_wakeup, 0, 0);
|
||||
}
|
||||
|
||||
|
@ -46,8 +46,8 @@ void _thr_umutex_init(struct umutex *mtx) __hidden;
|
||||
int _thr_umtx_wait(volatile long *mtx, long exp,
|
||||
const struct timespec *timeout) __hidden;
|
||||
int _thr_umtx_wait_uint(volatile u_int *mtx, u_int exp,
|
||||
const struct timespec *timeout) __hidden;
|
||||
int _thr_umtx_wake(volatile void *mtx, int count) __hidden;
|
||||
const struct timespec *timeout, int shared) __hidden;
|
||||
int _thr_umtx_wake(volatile void *mtx, int count, int shared) __hidden;
|
||||
int _thr_ucond_wait(struct ucond *cv, struct umutex *m,
|
||||
const struct timespec *timeout, int check_unpaking) __hidden;
|
||||
void _thr_ucond_init(struct ucond *cv) __hidden;
|
||||
|
Loading…
Reference in New Issue
Block a user