diff options
author | rpj <rpj> | 1998-07-29 01:57:32 +0000 |
---|---|---|
committer | rpj <rpj> | 1998-07-29 01:57:32 +0000 |
commit | 96600f6d50eeeef1f660352b8455d4df1aed69ff (patch) | |
tree | 2aa58c10df37284ab9a130f7cc7585d51f28c5aa /private.c | |
parent | 0379281c3fc3bedede0177d43871ae5b1006eef7 (diff) |
Wed Jul 29 11:39:03 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* private.c: Corrections in comments.
(_pthread_new_thread): Alter "if" flow to be more natural.
Diffstat (limited to 'private.c')
-rw-r--r-- | private.c | 47 |
1 files changed, 24 insertions, 23 deletions
@@ -12,10 +12,11 @@ /* Thread ID management. --------------------- - We started by simply mapping the Win32 thread handle to directly to - pthread_t. Then, is order to process pthread_join()'s, needed to be - able to keep our POSIX thread ID (pthread_t) around after the Win32 - thread has terminated and possibly reused the Win32 handle. + We started by simply mapping the Win32 thread handle directly to + pthread_t. However, in order to process pthread_join()'s, we need + to be able to keep our POSIX thread ID (pthread_t) around after the + Win32 thread has terminated. Win32 may reuse the Win32 handle during that + time, which will conflict. The pthread_t value is now actually the pointer to a thread struct: @@ -47,7 +48,7 @@ Having the thread ID as a pointer to the thread struct itself avoids the need to search the threads table in all but the initial - occation where we create the thread. + occasion where we create the thread. Initially we used a hash function to select a free thread struct from the table, possibly needing a walk through the table if the @@ -73,20 +74,20 @@ The code for choosing a new (pthread_t) thread from the pool of free thread structs looks like: - if (_pthread_reuse_top == -1) + if (_pthread_reuse_top >= 0) { - if (_pthread_virgin_next >= PTHREAD_THREADS_MAX) - { - return EAGAIN; - } - else - { - thread = _pthread_virgin[_pthread_virgin_next++]; - } + new_thread = _pthread_reuse[_pthread_reuse_top--]; } else { - thread = _pthread_reuse[_pthread_reuse_top--]; + if (_pthread_virgin_next < PTHREAD_THREADS_MAX) + { + new_thread = _pthread_virgin[_pthread_virgin_next++]; + } + else + { + return EAGAIN; + } } @@ -101,21 +102,21 @@ _pthread_new_thread(pthread_t * thread) { pthread_t new_thread; - if (_pthread_reuse_top == -1) + if (_pthread_reuse_top >= 0) + { + new_thread = _pthread_reuse[_pthread_reuse_top--]; + } + else { - if (_pthread_virgin_next >= PTHREAD_THREADS_MAX) + if (_pthread_virgin_next < PTHREAD_THREADS_MAX) { - return EAGAIN; + new_thread = _pthread_virgin[_pthread_virgin_next++]; } else { - new_thread = _pthread_virgin[_pthread_virgin_next++]; + return EAGAIN; } } - else - { - new_thread = _pthread_reuse[_pthread_reuse_top--]; - } new_thread->win32handle = NULL; new_thread->ptstatus = _PTHREAD_NEW; |