summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--parsing.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/parsing.c b/parsing.c
index c66fb6f..1172cd1 100644
--- a/parsing.c
+++ b/parsing.c
@@ -16,10 +16,10 @@
#define LINE_BUFFER_SIZE 0x400
#define TIME_BUFFER_SIZE 0xf
-static pthread_mutex_t user_mutex, word_mutex;
+static pthread_mutex_t user_mutex, word_mutex, channel_mutex;
static struct user_t *last_user = NULL;
-static int in_monolog = 0, monolog_len = 0;;
+static int in_monolog = 0, monolog_len = 0;
static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *rs) {
char line[LINE_BUFFER_SIZE];
@@ -60,13 +60,19 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
min = atoi(min_s);
time_i = hour*4 + min / 15;
- user->lines[time_i]++;
- channel->hours[time_i]++;
-
/* Count words. */
wchar_t wtext[TEXT_BUFFER_SIZE];
mbstowcs(wtext, text, TEXT_BUFFER_SIZE);
+
+ pthread_mutex_lock(&user_mutex);
user->characters += wcslen(wtext);
+ user->lines[time_i]++;
+ pthread_mutex_unlock(&user_mutex);
+
+ pthread_mutex_lock(&channel_mutex);
+ channel->hours[time_i]++;
+ pthread_mutex_unlock(&channel_mutex);
+
wchar_t word[TEXT_BUFFER_SIZE];
wchar_t *end = wcschr(wtext, '\0');
*word = '\0';
@@ -74,14 +80,16 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
for(wchar_t *pos = wtext; pos < end; pos++) {
if(iswblank(*pos)) {
if(len) {
+ pthread_mutex_lock(&user_mutex);
user->words++;
+ pthread_mutex_unlock(&user_mutex);
word[len] = '\0';
char mbword[TEXT_BUFFER_SIZE];
wcstombs(mbword, word, TEXT_BUFFER_SIZE);
pthread_mutex_lock(&word_mutex);
struct word_t *word_s = word_get(mbword);
- pthread_mutex_unlock(&word_mutex);
word_s->count++;
+ pthread_mutex_unlock(&word_mutex);
}
len = 0;
*word = '\0';
@@ -93,14 +101,16 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
}
}
if(len) {
+ pthread_mutex_lock(&user_mutex);
user->words++;
+ pthread_mutex_unlock(&user_mutex);
word[len] = '\0';
char mbword[TEXT_BUFFER_SIZE];
wcstombs(mbword, word, TEXT_BUFFER_SIZE);
pthread_mutex_lock(&word_mutex);
struct word_t *word_s = word_get(mbword);
- pthread_mutex_unlock(&word_mutex);
word_s->count++;
+ pthread_mutex_unlock(&word_mutex);
}
continue;
}
@@ -123,9 +133,9 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
pthread_mutex_lock(&user_mutex);
struct user_t *user = user_get(nick),
*victim_user = user_get(victim);
- pthread_mutex_unlock(&user_mutex);
user->kicks++;
victim_user->kicked++;
+ pthread_mutex_unlock(&user_mutex);
continue;
}
}
@@ -145,6 +155,7 @@ static void *thread_func(void *arg) {
void process(int thread_n) {
pthread_mutex_init(&user_mutex, NULL);
pthread_mutex_init(&word_mutex, NULL);
+ pthread_mutex_init(&channel_mutex, NULL);
/* Parsing stuff goes here. */
for(int chan_i = 0; chan_i < channel_get_count(); chan_i++) {
user_init();
@@ -188,4 +199,5 @@ void process(int thread_n) {
}
pthread_mutex_destroy(&user_mutex);
pthread_mutex_destroy(&word_mutex);
+ pthread_mutex_destroy(&channel_mutex);
}