changed pthread_self() to return thread IDs > 0
This commit is contained in:
parent
47d3f8e7d5
commit
f3566f0b8a
@ -76,7 +76,7 @@ static char pthread_reaper_stack[PTHREAD_REAPER_STACKSIZE];
|
|||||||
static void pthread_start_routine(void)
|
static void pthread_start_routine(void)
|
||||||
{
|
{
|
||||||
pthread_t self = pthread_self();
|
pthread_t self = pthread_self();
|
||||||
pthread_thread_t *pt = pthread_sched_threads[self];
|
pthread_thread_t *pt = pthread_sched_threads[self-1];
|
||||||
void *retval = pt->start_routine(pt->arg);
|
void *retval = pt->start_routine(pt->arg);
|
||||||
pthread_exit(retval);
|
pthread_exit(retval);
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ static int insert(pthread_thread_t *pt)
|
|||||||
for (int i = 0; i < MAXTHREADS; i++){
|
for (int i = 0; i < MAXTHREADS; i++){
|
||||||
if (!pthread_sched_threads[i]) {
|
if (!pthread_sched_threads[i]) {
|
||||||
pthread_sched_threads[i] = pt;
|
pthread_sched_threads[i] = pt;
|
||||||
result = i;
|
result = i+1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ int pthread_create(pthread_t *newthread, const pthread_attr_t *attr, void *(*sta
|
|||||||
if (pt->thread_pid < 0) {
|
if (pt->thread_pid < 0) {
|
||||||
free(pt->stack);
|
free(pt->stack);
|
||||||
free(pt);
|
free(pt);
|
||||||
pthread_sched_threads[pthread_pid] = NULL;
|
pthread_sched_threads[pthread_pid-1] = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ int pthread_create(pthread_t *newthread, const pthread_attr_t *attr, void *(*sta
|
|||||||
|
|
||||||
void pthread_exit(void *retval)
|
void pthread_exit(void *retval)
|
||||||
{
|
{
|
||||||
pthread_thread_t *self = pthread_sched_threads[pthread_self()];
|
pthread_thread_t *self = pthread_sched_threads[pthread_self()-1];
|
||||||
|
|
||||||
while (self->cleanup_top) {
|
while (self->cleanup_top) {
|
||||||
__pthread_cleanup_datum_t *ct = self->cleanup_top;
|
__pthread_cleanup_datum_t *ct = self->cleanup_top;
|
||||||
@ -193,7 +193,7 @@ void pthread_exit(void *retval)
|
|||||||
|
|
||||||
int pthread_join(pthread_t th, void **thread_return)
|
int pthread_join(pthread_t th, void **thread_return)
|
||||||
{
|
{
|
||||||
pthread_thread_t *other = pthread_sched_threads[th];
|
pthread_thread_t *other = pthread_sched_threads[th-1];
|
||||||
if (!other) {
|
if (!other) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -211,7 +211,7 @@ int pthread_join(pthread_t th, void **thread_return)
|
|||||||
free(other);
|
free(other);
|
||||||
/* we only need to free the pthread layer struct,
|
/* we only need to free the pthread layer struct,
|
||||||
native thread stack is freed by other */
|
native thread stack is freed by other */
|
||||||
pthread_sched_threads[th] = NULL;
|
pthread_sched_threads[th-1] = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
case (PTS_DETACHED):
|
case (PTS_DETACHED):
|
||||||
return -1;
|
return -1;
|
||||||
@ -222,7 +222,7 @@ int pthread_join(pthread_t th, void **thread_return)
|
|||||||
|
|
||||||
int pthread_detach(pthread_t th)
|
int pthread_detach(pthread_t th)
|
||||||
{
|
{
|
||||||
pthread_thread_t *other = pthread_sched_threads[th];
|
pthread_thread_t *other = pthread_sched_threads[th-1];
|
||||||
if (!other) {
|
if (!other) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -231,7 +231,7 @@ int pthread_detach(pthread_t th)
|
|||||||
free(other);
|
free(other);
|
||||||
/* we only need to free the pthread layer struct,
|
/* we only need to free the pthread layer struct,
|
||||||
native thread stack is freed by other */
|
native thread stack is freed by other */
|
||||||
pthread_sched_threads[th] = NULL;
|
pthread_sched_threads[th-1] = NULL;
|
||||||
} else {
|
} else {
|
||||||
other->status = PTS_DETACHED;
|
other->status = PTS_DETACHED;
|
||||||
}
|
}
|
||||||
@ -246,7 +246,7 @@ pthread_t pthread_self(void)
|
|||||||
int pid = thread_pid; /* thread_pid is volatile */
|
int pid = thread_pid; /* thread_pid is volatile */
|
||||||
for (int i = 0; i < MAXTHREADS; i++) {
|
for (int i = 0; i < MAXTHREADS; i++) {
|
||||||
if (pthread_sched_threads[i] && pthread_sched_threads[i]->thread_pid == pid) {
|
if (pthread_sched_threads[i] && pthread_sched_threads[i]->thread_pid == pid) {
|
||||||
result = i;
|
result = i+1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,7 +261,7 @@ int pthread_equal(pthread_t thread1, pthread_t thread2)
|
|||||||
|
|
||||||
int pthread_cancel(pthread_t th)
|
int pthread_cancel(pthread_t th)
|
||||||
{
|
{
|
||||||
pthread_thread_t *other = pthread_sched_threads[th];
|
pthread_thread_t *other = pthread_sched_threads[th-1];
|
||||||
if (!other) {
|
if (!other) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -288,21 +288,21 @@ int pthread_setcanceltype(int type, int *oldtype)
|
|||||||
void pthread_testcancel(void)
|
void pthread_testcancel(void)
|
||||||
{
|
{
|
||||||
pthread_t self = pthread_self();
|
pthread_t self = pthread_self();
|
||||||
if (pthread_sched_threads[self]->should_cancel) {
|
if (pthread_sched_threads[self-1]->should_cancel) {
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void __pthread_cleanup_push(__pthread_cleanup_datum_t *datum)
|
void __pthread_cleanup_push(__pthread_cleanup_datum_t *datum)
|
||||||
{
|
{
|
||||||
pthread_thread_t *self = pthread_sched_threads[pthread_self()];
|
pthread_thread_t *self = pthread_sched_threads[pthread_self()-1];
|
||||||
datum->__next = self->cleanup_top;
|
datum->__next = self->cleanup_top;
|
||||||
self->cleanup_top = datum;
|
self->cleanup_top = datum;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __pthread_cleanup_pop(__pthread_cleanup_datum_t *datum, int execute)
|
void __pthread_cleanup_pop(__pthread_cleanup_datum_t *datum, int execute)
|
||||||
{
|
{
|
||||||
pthread_thread_t *self = pthread_sched_threads[pthread_self()];
|
pthread_thread_t *self = pthread_sched_threads[pthread_self()-1];
|
||||||
self->cleanup_top = datum->__next;
|
self->cleanup_top = datum->__next;
|
||||||
|
|
||||||
if (execute != 0) {
|
if (execute != 0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user