Remove priority mutex code because it does not work correctly,
to make it work, turnstile like mechanism to support priority propagating and other realtime scheduling options in kernel should be available to userland mutex, for the moment, I just want to make libthr be simple and efficient thread library. Discussed with: deischen, julian
This commit is contained in:
parent
6bf81397d7
commit
255936645e
@ -30,8 +30,6 @@ SRCS+= \
|
||||
thr_multi_np.c \
|
||||
thr_mutex.c \
|
||||
thr_mutexattr.c \
|
||||
thr_mutex_prioceiling.c \
|
||||
thr_mutex_protocol.c \
|
||||
thr_once.c \
|
||||
thr_printf.c \
|
||||
thr_pspinlock.c \
|
||||
|
@ -129,7 +129,6 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr,
|
||||
|
||||
/* Initialize the mutex queue: */
|
||||
TAILQ_INIT(&new_thread->mutexq);
|
||||
TAILQ_INIT(&new_thread->pri_mutexq);
|
||||
|
||||
/* Initialise hooks in the thread structure: */
|
||||
if (new_thread->attr.suspend == THR_CREATE_SUSPENDED) {
|
||||
|
@ -68,7 +68,7 @@ atfork_head _thr_atfork_list = TAILQ_HEAD_INITIALIZER(_thr_atfork_list);
|
||||
umtx_t _thr_atfork_lock;
|
||||
|
||||
struct pthread_attr _pthread_attr_default = {
|
||||
.sched_policy = SCHED_RR,
|
||||
.sched_policy = SCHED_OTHER,
|
||||
.sched_inherit = 0,
|
||||
.sched_interval = TIMESLICE_USEC,
|
||||
.prio = THR_DEFAULT_PRIORITY,
|
||||
@ -424,7 +424,6 @@ init_main_thread(struct pthread *thread)
|
||||
|
||||
/* Initialize the mutex queue: */
|
||||
TAILQ_INIT(&thread->mutexq);
|
||||
TAILQ_INIT(&thread->pri_mutexq);
|
||||
|
||||
thread->state = PS_RUNNING;
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -79,6 +79,10 @@ __weak_reference(_pthread_mutexattr_settype, pthread_mutexattr_settype);
|
||||
__weak_reference(_pthread_mutexattr_destroy, pthread_mutexattr_destroy);
|
||||
__weak_reference(_pthread_mutexattr_getpshared, pthread_mutexattr_getpshared);
|
||||
__weak_reference(_pthread_mutexattr_setpshared, pthread_mutexattr_setpshared);
|
||||
__weak_reference(_pthread_mutexattr_getprotocol, pthread_mutexattr_getprotocol);
|
||||
__weak_reference(_pthread_mutexattr_setprotocol, pthread_mutexattr_setprotocol);
|
||||
__weak_reference(_pthread_mutexattr_getprioceiling, pthread_mutexattr_getprioceiling);
|
||||
__weak_reference(_pthread_mutexattr_setprioceiling, pthread_mutexattr_setprioceiling);
|
||||
|
||||
int
|
||||
_pthread_mutexattr_init(pthread_mutexattr_t *attr)
|
||||
@ -193,3 +197,62 @@ _pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared)
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
_pthread_mutexattr_getprotocol(pthread_mutexattr_t *mattr, int *protocol)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if ((mattr == NULL) || (*mattr == NULL))
|
||||
ret = EINVAL;
|
||||
else
|
||||
*protocol = (*mattr)->m_protocol;
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
int
|
||||
_pthread_mutexattr_setprotocol(pthread_mutexattr_t *mattr, int protocol)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if ((mattr == NULL) || (*mattr == NULL) ||
|
||||
(protocol < PTHREAD_PRIO_NONE) || (protocol > PTHREAD_PRIO_PROTECT))
|
||||
ret = EINVAL;
|
||||
else {
|
||||
(*mattr)->m_protocol = protocol;
|
||||
(*mattr)->m_ceiling = THR_MAX_PRIORITY;
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
int
|
||||
_pthread_mutexattr_getprioceiling(pthread_mutexattr_t *mattr, int *prioceiling)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if ((mattr == NULL) || (*mattr == NULL))
|
||||
ret = EINVAL;
|
||||
else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
|
||||
ret = EINVAL;
|
||||
else
|
||||
*prioceiling = (*mattr)->m_ceiling;
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
int
|
||||
_pthread_mutexattr_setprioceiling(pthread_mutexattr_t *mattr, int prioceiling)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if ((mattr == NULL) || (*mattr == NULL))
|
||||
ret = EINVAL;
|
||||
else if ((*mattr)->m_protocol != PTHREAD_PRIO_PROTECT)
|
||||
ret = EINVAL;
|
||||
else
|
||||
(*mattr)->m_ceiling = prioceiling;
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
@ -312,10 +312,6 @@ enum pthread_state {
|
||||
PS_DEAD
|
||||
};
|
||||
|
||||
union pthread_wait_data {
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
|
||||
struct pthread_specific_elem {
|
||||
const void *data;
|
||||
int seqno;
|
||||
@ -332,22 +328,15 @@ struct pthread_key {
|
||||
* Thread structure.
|
||||
*/
|
||||
struct pthread {
|
||||
/*
|
||||
* Magic value to help recognize a valid thread structure
|
||||
* from an invalid one:
|
||||
*/
|
||||
#define THR_MAGIC ((u_int32_t) 0xd09ba115)
|
||||
u_int32_t magic;
|
||||
/* Kernel thread id. */
|
||||
long tid;
|
||||
#define TID_TERMINATED 1
|
||||
|
||||
/*
|
||||
* Lock for accesses to this thread structure.
|
||||
*/
|
||||
umtx_t lock;
|
||||
|
||||
/* Kernel thread id. */
|
||||
long tid;
|
||||
#define TID_TERMINATED 1
|
||||
|
||||
/* Internal condition variable cycle number. */
|
||||
umtx_t cycle;
|
||||
|
||||
@ -424,12 +413,6 @@ struct pthread {
|
||||
*/
|
||||
TAILQ_ENTRY(pthread) sqe;
|
||||
|
||||
/* Wait data. */
|
||||
union pthread_wait_data data;
|
||||
|
||||
int sflags;
|
||||
#define THR_FLAGS_IN_SYNCQ 0x0001
|
||||
|
||||
/* Miscellaneous flags; only set with scheduling lock held. */
|
||||
int flags;
|
||||
#define THR_FLAGS_PRIVATE 0x0001
|
||||
@ -469,15 +452,9 @@ struct pthread {
|
||||
*/
|
||||
char active_priority;
|
||||
|
||||
/* Number of priority ceiling or protection mutexes owned. */
|
||||
int priority_mutex_count;
|
||||
|
||||
/* Queue of currently owned simple type mutexes. */
|
||||
TAILQ_HEAD(, pthread_mutex) mutexq;
|
||||
|
||||
/* Queue of currently owned priority type mutexs. */
|
||||
TAILQ_HEAD(, pthread_mutex) pri_mutexq;
|
||||
|
||||
void *ret;
|
||||
struct pthread_specific_elem *specific;
|
||||
int specific_data_count;
|
||||
@ -495,6 +472,13 @@ struct pthread {
|
||||
/* Cleanup handlers Link List */
|
||||
struct pthread_cleanup *cleanup;
|
||||
|
||||
/*
|
||||
* Magic value to help recognize a valid thread structure
|
||||
* from an invalid one:
|
||||
*/
|
||||
#define THR_MAGIC ((u_int32_t) 0xd09ba115)
|
||||
u_int32_t magic;
|
||||
|
||||
/* Enable event reporting */
|
||||
int report_events;
|
||||
|
||||
@ -602,8 +586,6 @@ do { \
|
||||
|
||||
#define GC_NEEDED() (_gc_count >= 5)
|
||||
|
||||
#define THR_IN_SYNCQ(thrd) (((thrd)->sflags & THR_FLAGS_IN_SYNCQ) != 0)
|
||||
|
||||
#define SHOULD_REPORT_EVENT(curthr, e) \
|
||||
(curthr->report_events && \
|
||||
(((curthr)->event_mask | _thread_event_mask ) & e) != 0)
|
||||
@ -664,7 +646,6 @@ __BEGIN_DECLS
|
||||
int _thr_setthreaded(int) __hidden;
|
||||
int _mutex_cv_lock(pthread_mutex_t *) __hidden;
|
||||
int _mutex_cv_unlock(pthread_mutex_t *) __hidden;
|
||||
void _mutex_notify_priochange(struct pthread *, struct pthread *, int) __hidden;
|
||||
int _mutex_reinit(pthread_mutex_t *) __hidden;
|
||||
void _mutex_fork(struct pthread *curthread) __hidden;
|
||||
void _mutex_unlock_private(struct pthread *) __hidden;
|
||||
@ -731,7 +712,6 @@ void _thr_unlink(struct pthread *, struct pthread *) __hidden;
|
||||
void _thr_suspend_check(struct pthread *) __hidden;
|
||||
void _thr_assert_lock_level(void) __hidden __dead2;
|
||||
void _thr_ast(struct pthread *) __hidden;
|
||||
void _thr_timer_init(void) __hidden;
|
||||
void _thr_once_init(void) __hidden;
|
||||
void _thr_report_creation(struct pthread *curthread,
|
||||
struct pthread *newthread) __hidden;
|
||||
|
@ -40,25 +40,22 @@
|
||||
|
||||
__weak_reference(_pthread_setschedparam, pthread_setschedparam);
|
||||
|
||||
/*
|
||||
* Set a thread's scheduling parameters, this should be done
|
||||
* in kernel, doing it in userland is no-op.
|
||||
*/
|
||||
int
|
||||
_pthread_setschedparam(pthread_t pthread, int policy,
|
||||
const struct sched_param *param)
|
||||
{
|
||||
struct pthread *curthread = _get_curthread();
|
||||
int in_syncq;
|
||||
int in_readyq = 0;
|
||||
int old_prio;
|
||||
int ret = 0;
|
||||
|
||||
if ((param == NULL) || (policy < SCHED_FIFO) || (policy > SCHED_RR)) {
|
||||
/* Return an invalid argument error: */
|
||||
ret = EINVAL;
|
||||
} else if ((param->sched_priority < THR_MIN_PRIORITY) ||
|
||||
(param->sched_priority > THR_MAX_PRIORITY)) {
|
||||
/* Return an unsupported value error. */
|
||||
ret = ENOTSUP;
|
||||
|
||||
/* Find the thread in the list of active threads: */
|
||||
} else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0))
|
||||
== 0) {
|
||||
/*
|
||||
@ -71,7 +68,6 @@ _pthread_setschedparam(pthread_t pthread, int policy,
|
||||
_thr_ref_delete(curthread, pthread);
|
||||
return (ESRCH);
|
||||
}
|
||||
in_syncq = pthread->sflags & THR_FLAGS_IN_SYNCQ;
|
||||
|
||||
/* Set the scheduling policy: */
|
||||
pthread->attr.sched_policy = policy;
|
||||
@ -84,51 +80,13 @@ _pthread_setschedparam(pthread_t pthread, int policy,
|
||||
*/
|
||||
THR_THREAD_UNLOCK(curthread, pthread);
|
||||
else {
|
||||
/*
|
||||
* Remove the thread from its current priority
|
||||
* queue before any adjustments are made to its
|
||||
* active priority:
|
||||
*/
|
||||
old_prio = pthread->active_priority;
|
||||
/* if ((pthread->flags & THR_FLAGS_IN_RUNQ) != 0) */ {
|
||||
in_readyq = 1;
|
||||
/* THR_RUNQ_REMOVE(pthread); */
|
||||
}
|
||||
|
||||
/* Set the thread base priority: */
|
||||
pthread->base_priority &=
|
||||
(THR_SIGNAL_PRIORITY | THR_RT_PRIORITY);
|
||||
pthread->base_priority = param->sched_priority;
|
||||
|
||||
/* Recalculate the active priority: */
|
||||
pthread->active_priority = MAX(pthread->base_priority,
|
||||
pthread->inherited_priority);
|
||||
|
||||
if (in_readyq) {
|
||||
if ((pthread->priority_mutex_count > 0) &&
|
||||
(old_prio > pthread->active_priority)) {
|
||||
/*
|
||||
* POSIX states that if the priority is
|
||||
* being lowered, the thread must be
|
||||
* inserted at the head of the queue for
|
||||
* its priority if it owns any priority
|
||||
* protection or inheritence mutexes.
|
||||
*/
|
||||
/* THR_RUNQ_INSERT_HEAD(pthread); */
|
||||
}
|
||||
else
|
||||
/* THR_RUNQ_INSERT_TAIL(pthread)*/ ;
|
||||
}
|
||||
|
||||
/* Unlock the threads scheduling queue: */
|
||||
THR_THREAD_UNLOCK(curthread, pthread);
|
||||
|
||||
/*
|
||||
* Check for any mutex priority adjustments. This
|
||||
* includes checking for a priority mutex on which
|
||||
* this thread is waiting.
|
||||
*/
|
||||
_mutex_notify_priochange(curthread, pthread, in_syncq);
|
||||
}
|
||||
_thr_ref_delete(curthread, pthread);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user