pthread_mutex_t Critters[MAX_SEMAPHORES]; // Things needing locking
int server_shutting_down = 0; // set to nonzero during shutdown
pthread_mutex_t ThreadCountMutex;
-char locks[MAX_SEMAPHORES+1];
void InitializeSemaphores(void) {
int i;
// Set up a bunch of semaphores to be used for critical sections
for (i=0; i<MAX_SEMAPHORES; ++i) {
pthread_mutex_init(&Critters[i], NULL);
- locks[i] = ' ';
}
- locks[MAX_SEMAPHORES] = 0;
}
// For all types of critical sections except those listed here,
// ensure nobody ever tries to do a critical section within a
// transaction; this could lead to deadlock.
- if ( (which_one != S_FLOORCACHE)
- && (which_one != S_NETCONFIGS)
- ) {
+ if ((which_one != S_FLOORCACHE) && (which_one != S_NETCONFIGS)) {
cdb_check_handles();
}
- //syslog(LOG_ERR, "\033[3%dm lock(%14p, %2d, %s)\033[0m", (which_one%6)+1, pthread_self(), which_one, locks);
pthread_mutex_lock(&Critters[which_one]);
- //if (locks[which_one] != 'X') {
- //syslog(LOG_ERR, "\033[31mThread %p had to wait to get a lock on %d\033[0m", pthread_self(), which_one);
- //}
- locks[which_one] = 'X';
}
// Release a semaphore lock to end a critical section.
void end_critical_section(int which_one) {
- locks[which_one] = '_';
- //syslog(LOG_ERR, "\033[3%dmunlock(%14p, %2d, %s)\033[0m", (which_one%6)+1, pthread_self(), which_one, locks);
pthread_mutex_unlock(&Critters[which_one]);
}