diff --git a/bot.c b/bot.c index 71e8144..90321f3 100644 --- a/bot.c +++ b/bot.c @@ -9,13 +9,21 @@ botChanList_t *chans = 0x0; +pthread_mutex_t chanMutex = PTHREAD_MUTEX_INITIALIZER; + botChanList_t *botFindChan(char *channel) { botChanList_t *tmpChan = 0x0; + pthread_mutex_lock(&chanMutex); + for (tmpChan = chans;tmpChan != 0x0;tmpChan = tmpChan->next) { - if (!strcasecmp(tmpChan->channel,channel)) + if (!strcasecmp(tmpChan->channel,channel)) { + pthread_mutex_unlock(&chanMutex); return(tmpChan); + } } + + pthread_mutex_unlock(&chanMutex); return(0x0); } @@ -37,6 +45,8 @@ tmpChan->updated = 0x0; bzero(tmpChan->modes,CHAN_MODES); + pthread_mutex_lock(&chanMutex); + if (chans == 0x0) chans = tmpChan; else { @@ -44,6 +54,8 @@ chans->prev = tmpChan; chans = tmpChan; } + + pthread_mutex_unlock(&chanMutex); return(tmpChan); } diff --git a/main.c b/main.c index 7e1d5d0..da6a927 100644 --- a/main.c +++ b/main.c @@ -75,6 +75,8 @@ pthread_t threads[NUM_THREADS]; pthread_create(&threads[t], NULL, botCMD_Thread, (void *)t); + + pthread_mutex_init(&chanMutex, NULL); sConnect(SERVER_HOST,SERVER_PORT); diff --git a/tuvebot.h b/tuvebot.h index 452280e..9d87ec9 100644 --- a/tuvebot.h +++ b/tuvebot.h @@ -67,6 +67,7 @@ extern int mySocket; extern int connected; +extern pthread_mutex_t chanMutex; extern int highSock; extern FILE *logFile;