summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConstruct5
-rw-r--r--config.c4
-rw-r--r--config.h2
-rw-r--r--main.c2
-rw-r--r--parsing.c86
-rw-r--r--parsing.h2
6 files changed, 7 insertions, 94 deletions
diff --git a/SConstruct b/SConstruct
index 1f20d54..cbc8521 100644
--- a/SConstruct
+++ b/SConstruct
@@ -3,20 +3,19 @@ AddOption('--release', action = 'store_true')
env = Environment()
conf = Configure(env)
-for lib in ('config', 'pcre', 'xml2', 'pthread'):
+for lib in ('config', 'pcre', 'xml2'):
if not conf.CheckLib(lib):
print 'Could not find %s' % lib
Exit(1)
env = conf.Finish()
-env.Append(CCFLAGS = ['-std=c99', '-D_GNU_SOURCE', '-pthread'])
+env.Append(CCFLAGS = ['-std=c99', '-D_GNU_SOURCE'])
if GetOption('release'):
env.Append(CCFLAGS = ['-O2'])
else:
env.Append(CCFLAGS = ['-Wall', '-g'])
-env.Append(LINKFLAGS = ['-pthread'])
env.ParseConfig('pkg-config --cflags --libs libconfig')
env.ParseConfig('pcre-config --cflags --libs')
env.ParseConfig('xml2-config --cflags --libs')
diff --git a/config.c b/config.c
index 19a427a..84bcf39 100644
--- a/config.c
+++ b/config.c
@@ -27,10 +27,6 @@ int cfg_init() {
return 0;
}
- if(!config_lookup_int(&config, "threads", &ircstats_config.threads)) {
- ircstats_config.threads = 1;
- }
-
if(!config_lookup_int(&config, "monolog_min", &ircstats_config.monolog_min)) {
ircstats_config.monolog_min = 5;
}
diff --git a/config.h b/config.h
index 163be18..ef2e3a4 100644
--- a/config.h
+++ b/config.h
@@ -5,7 +5,7 @@ int cfg_init();
void cfg_free();
struct ircstats_config_t {
- int threads, monolog_min, wordlen_min;
+ int monolog_min, wordlen_min;
const char *log_date_format, *day_date_format;
};
diff --git a/main.c b/main.c
index c864b8d..b6fb6ca 100644
--- a/main.c
+++ b/main.c
@@ -25,7 +25,7 @@ int main(int argc, char **argv) {
return 1;
}
- process(ircstats_config.threads);
+ process();
nick_free();
cfg_free();
diff --git a/parsing.c b/parsing.c
index 54d6078..2447363 100644
--- a/parsing.c
+++ b/parsing.c
@@ -2,7 +2,6 @@
#include <string.h>
#include <wctype.h>
#include <wchar.h>
-#include <pthread.h>
#include <errno.h>
#include "parsing.h"
@@ -20,32 +19,24 @@
#define max(a, b) ((a) > (b) ? (a) : (b))
-static pthread_mutex_t file_mutex, user_mutex, word_mutex, channel_mutex, time_mutex;
-
static struct user_t *last_user = NULL;
static int in_monolog = 0, monolog_len = 0;
static struct tm now_global;
static inline void add_word(struct user_t *user, wchar_t *word, int 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);
word_s->count++;
- pthread_mutex_unlock(&word_mutex);
}
static inline char *parse_getline(char *buffer, int bufsize, FILE *f) {
char *r;
- pthread_mutex_lock(&file_mutex);
r = fgets(buffer, bufsize, f);
- pthread_mutex_unlock(&file_mutex);
return r;
}
@@ -82,7 +73,6 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
pcre_copy_named_substring(rs->text, line, ovector, rc, "text", text, TEXT_BUFFER_SIZE);
pcre_copy_named_substring(rs->text, line, ovector, rc, "hour", hour_s, TIME_BUFFER_SIZE);
pcre_copy_named_substring(rs->text, line, ovector, rc, "minute", min_s, TIME_BUFFER_SIZE);
- pthread_mutex_lock(&user_mutex);
struct user_t *user = user_get(nick);
if(user == last_user) {
monolog_len++;
@@ -99,7 +89,6 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
in_monolog = 0;
monolog_len = 1;
}
- pthread_mutex_unlock(&user_mutex);
/* Calculate array index for lines. */
int hour, min, time_i;
@@ -111,15 +100,12 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
wchar_t wtext[TEXT_BUFFER_SIZE];
mbstowcs(wtext, text, TEXT_BUFFER_SIZE);
- pthread_mutex_lock(&time_mutex);
now = now_global;
- pthread_mutex_unlock(&time_mutex);
now.tm_hour = hour;
now.tm_min = min;
time_t now_ut = mktime(&now);
- pthread_mutex_lock(&user_mutex);
user->characters += wcslen(wtext);
user->lines[time_i]++;
@@ -127,11 +113,8 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
user->seen_first = now_ut;
}
user->seen_last = max(now_ut, user->seen_last);
- 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');
@@ -168,22 +151,18 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
hour = atoi(hour_s);
min = atoi(min_s);
- pthread_mutex_lock(&time_mutex);
now = now_global;
- pthread_mutex_unlock(&time_mutex);
now.tm_hour = hour;
now.tm_min = min;
time_t now_ut = mktime(&now);
- pthread_mutex_lock(&user_mutex);
struct user_t *user = user_get(nick);
if(user->seen_first == 0 || now_ut < user->seen_first) {
user->seen_first = now_ut;
}
user->seen_last = max(now_ut, user->seen_last);
- pthread_mutex_unlock(&user_mutex);
continue;
}
@@ -199,22 +178,18 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
hour = atoi(hour_s);
min = atoi(min_s);
- pthread_mutex_lock(&time_mutex);
now = now_global;
- pthread_mutex_unlock(&time_mutex);
now.tm_hour = hour;
now.tm_min = min;
time_t now_ut = mktime(&now);
- pthread_mutex_lock(&user_mutex);
struct user_t *user = user_get(nick);
if(user->seen_first == 0 || now_ut < user->seen_first) {
user->seen_first = now_ut;
}
user->seen_last = max(now_ut, user->seen_last);
- pthread_mutex_unlock(&user_mutex);
continue;
}
@@ -230,22 +205,18 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
hour = atoi(hour_s);
min = atoi(min_s);
- pthread_mutex_lock(&time_mutex);
now = now_global;
- pthread_mutex_unlock(&time_mutex);
now.tm_hour = hour;
now.tm_min = min;
time_t now_ut = mktime(&now);
- pthread_mutex_lock(&user_mutex);
struct user_t *user = user_get(nick);
if(user->seen_first == 0 || now_ut < user->seen_first) {
user->seen_first = now_ut;
}
user->seen_last = max(now_ut, user->seen_last);
- pthread_mutex_unlock(&user_mutex);
continue;
}
@@ -261,22 +232,18 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
hour = atoi(hour_s);
min = atoi(min_s);
- pthread_mutex_lock(&time_mutex);
now = now_global;
- pthread_mutex_unlock(&time_mutex);
now.tm_hour = hour;
now.tm_min = min;
time_t now_ut = mktime(&now);
- pthread_mutex_lock(&user_mutex);
struct user_t *user = user_get(newnick);
if(user->seen_first == 0 || now_ut < user->seen_first) {
user->seen_first = now_ut;
}
user->seen_last = max(now_ut, user->seen_last);
- pthread_mutex_unlock(&user_mutex);
continue;
}
@@ -291,18 +258,12 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
pcre_copy_named_substring(rs->log_opened, line, ovector, rc, "date", date, DATE_BUFFER_SIZE);
- /* TODO: Find a better way around this.
- * Locking early to allow setting of correct date before any other threads start setting time
- * before date is set. */
- pthread_mutex_lock(&time_mutex);
if(!strptime(date, log_date_format, &now)) {
fprintf(stderr, "log fail: %s\n", date);
- pthread_mutex_unlock(&time_mutex);
continue;
}
now_global = now;
- pthread_mutex_unlock(&time_mutex);
continue;
}
@@ -318,16 +279,12 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
pcre_copy_named_substring(rs->day_changed, line, ovector, rc, "date", date, DATE_BUFFER_SIZE);
- /* See comment in log_opened parsing. */
- pthread_mutex_lock(&time_mutex);
if(!strptime(date, day_date_format, &now)) {
fprintf(stderr, "day fail: %s\n", date);
- pthread_mutex_unlock(&time_mutex);
continue;
}
now_global = now;
- pthread_mutex_unlock(&time_mutex);
continue;
}
@@ -344,15 +301,12 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
hour = atoi(hour_s);
min = atoi(min_s);
- pthread_mutex_lock(&time_mutex);
now = now_global;
- pthread_mutex_unlock(&time_mutex);
now.tm_hour = hour;
now.tm_min = min;
time_t now_ut = mktime(&now);
- pthread_mutex_lock(&user_mutex);
struct user_t *user = user_get(nick),
*victim_user = user_get(victim);
user->kicks++;
@@ -362,32 +316,13 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
user->seen_first = now_ut;
}
user->seen_last = max(now_ut, user->seen_last);
- pthread_mutex_unlock(&user_mutex);
continue;
}
}
}
-struct thread_arg_t {
- FILE *f;
- struct channel_t *channel;
- struct regexset_t *rs;
-};
-
-static void *thread_func(void *arg) {
- struct thread_arg_t *ta = arg;
- process_file(ta->f, ta->channel, ta->rs);
-
- return NULL;
-}
-
-void process(int thread_n) {
- pthread_mutex_init(&file_mutex, NULL);
- pthread_mutex_init(&user_mutex, NULL);
- pthread_mutex_init(&word_mutex, NULL);
- pthread_mutex_init(&channel_mutex, NULL);
- pthread_mutex_init(&time_mutex, NULL);
+void process() {
/* Parsing stuff goes here. */
for(int chan_i = 0; chan_i < channel_get_count(); chan_i++) {
user_init();
@@ -408,19 +343,7 @@ void process(int thread_n) {
last_user = NULL;
in_monolog = monolog_len = 0;
- pthread_t *threads;
- threads = malloc(sizeof(pthread_t) * thread_n);
- struct thread_arg_t ta;
- ta.f = f;
- ta.channel = channel;
- ta.rs = rs;
- for(int i = 0; i < thread_n; i++) {
- pthread_create(&threads[i], NULL, thread_func, &ta);
- }
- for(int i = 0; i < thread_n; i++) {
- pthread_join(threads[i], NULL);
- }
- free(threads);
+ process_file(f, channel, rs);
fclose(f);
file = file->next;
@@ -430,9 +353,4 @@ void process(int thread_n) {
user_free();
word_free();
}
- pthread_mutex_destroy(&file_mutex);
- pthread_mutex_destroy(&time_mutex);
- pthread_mutex_destroy(&user_mutex);
- pthread_mutex_destroy(&word_mutex);
- pthread_mutex_destroy(&channel_mutex);
}
diff --git a/parsing.h b/parsing.h
index b991d55..6188d34 100644
--- a/parsing.h
+++ b/parsing.h
@@ -1,6 +1,6 @@
#ifndef _PARSING_H_
#define _PARSING_H_
-void process(int thread_n);
+void process();
#endif