rx-thread-id-startup-20030303

FIXES 1304

avoid using rxi_availProcs to allocate thread ids as it may decrement from under us
This commit is contained in:
Rainer Toebbicke 2003-03-03 15:53:28 +00:00 committed by Derrick Brashear
parent dd4ade14d5
commit 45a4d9cb08
3 changed files with 22 additions and 8 deletions

View File

@ -1429,8 +1429,8 @@ struct rx_call *rx_GetCall(int tno, struct rx_service *cur_service, osi_socket *
if (!QuotaOK(service)) {
continue;
}
if (!tno || !tcall->queue_item_header.next) {
/* If we're thread 0, then we'll just use
if (tno==rxi_fcfs_thread_num || !tcall->queue_item_header.next ) {
/* If we're the fcfs thread , then we'll just use
* this call. If we haven't been able to find an optimal
* choice, and we're at the end of the list, then use a
* 2d choice if one has been identified. Otherwise... */
@ -1578,8 +1578,8 @@ struct rx_call *rx_GetCall(int tno, struct rx_service *cur_service, osi_socket *
for (queue_Scan(&rx_incomingCallQueue, tcall, ncall, rx_call)) {
service = tcall->conn->service;
if (QuotaOK(service)) {
if (!tno || !tcall->queue_item_header.next ) {
/* If we're thread 0, then we'll just use
if (tno==rxi_fcfs_thread_num || !tcall->queue_item_header.next ) {
/* If we're the fcfs thread, then we'll just use
* this call. If we haven't been able to find an optimal
* choice, and we're at the end of the list, then use a
* 2d choice if one has been identified. Otherwise... */

View File

@ -316,10 +316,13 @@ EXT int rxi_callAbortDelay INIT(3000);
*/
#if defined(AFS_PTHREAD_ENV)
EXT int rxi_fcfs_thread_num INIT(0);
EXT pthread_key_t rx_thread_id_key;
/* keep track of pthread numbers - protected by rx_stats_mutex,
except in rx_Init() before mutex exists! */
EXT int rxi_pthread_hinum INIT(0);
#else
#define rxi_fcfs_thread_num (0)
#endif
#if defined(RX_ENABLE_LOCKS)

View File

@ -130,9 +130,6 @@ void rxi_StartServerProc(void (*proc)(void), int stacksize)
printf("Unable to Create Rx server thread\n");
exit(1);
}
MUTEX_ENTER(&rx_stats_mutex);
++rxi_pthread_hinum;
MUTEX_EXIT(&rx_stats_mutex);
AFS_SIGSET_RESTORE();
}
@ -277,7 +274,21 @@ void rx_ServerProc(void)
rxi_dataQuota += rx_initSendWindow; /* Reserve some pkts for hard times */
/* threadID is used for making decisions in GetCall. Get it by bumping
* number of threads handling incoming calls */
threadID = rxi_availProcs++;
/* Unique thread ID: used for scheduling purposes *and* as index into
the host hold table (fileserver).
The previously used rxi_availProcs is unsuitable as it
will already go up and down as packets arrive while the server
threads are still initialising! The recently introduced
rxi_pthread_hinum does not necessarily lead to a server
thread with id 0, which is not allowed to hop through the
incoming call queue.
So either introduce yet another counter or flag the FCFS
thread... chose the latter.
*/
threadID = ++rxi_pthread_hinum;
if (rxi_fcfs_thread_num==0 && rxi_fcfs_thread_num!=threadID)
rxi_fcfs_thread_num=threadID;
++rxi_availProcs;
MUTEX_EXIT(&rx_stats_mutex);
while(1) {