summaryrefslogtreecommitdiff
path: root/parsing.c
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-11-09 22:44:06 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-11-09 22:44:06 +0100
commit3c14a9e2c368a477e22aac935c417314213b797c (patch)
tree1966a0797c0d38a0ad1a58ab5bbe9559dfbae895 /parsing.c
parentfeca811e0e0afcd67e9153522d40ae58bb468b2f (diff)
Avoid race condition on setting seen_first and seen_last.
Diffstat (limited to 'parsing.c')
-rw-r--r--parsing.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/parsing.c b/parsing.c
index 8875f61..3f38681 100644
--- a/parsing.c
+++ b/parsing.c
@@ -18,6 +18,8 @@
#define TIME_BUFFER_SIZE 0xf
#define DATE_BUFFER_SIZE 0x20
+#define max(a, b) ((a) > (b) ? (a) : (b))
+
static pthread_mutex_t user_mutex, word_mutex, channel_mutex, time_mutex;
static struct user_t *last_user = NULL;
@@ -111,10 +113,10 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
user->characters += wcslen(wtext);
user->lines[time_i]++;
- if(user->seen_first == 0) {
+ if(user->seen_first == 0 || now_ut < user->seen_first) {
user->seen_first = now_ut;
}
- user->seen_last = now_ut;
+ user->seen_last = max(now_ut, user->seen_last);
pthread_mutex_unlock(&user_mutex);
pthread_mutex_lock(&channel_mutex);
@@ -167,10 +169,10 @@ 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);
- if(user->seen_first == 0) {
+ if(user->seen_first == 0 || now_ut < user->seen_first) {
user->seen_first = now_ut;
}
- user->seen_last = now_ut;
+ user->seen_last = max(now_ut, user->seen_last);
pthread_mutex_unlock(&user_mutex);
continue;
@@ -198,10 +200,10 @@ 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);
- if(user->seen_first == 0) {
+ if(user->seen_first == 0 || now_ut < user->seen_first) {
user->seen_first = now_ut;
}
- user->seen_last = now_ut;
+ user->seen_last = max(now_ut, user->seen_last);
pthread_mutex_unlock(&user_mutex);
continue;
@@ -229,10 +231,10 @@ 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);
- if(user->seen_first == 0) {
+ if(user->seen_first == 0 || now_ut < user->seen_first) {
user->seen_first = now_ut;
}
- user->seen_last = now_ut;
+ user->seen_last = max(now_ut, user->seen_last);
pthread_mutex_unlock(&user_mutex);
continue;
@@ -260,10 +262,10 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
pthread_mutex_lock(&user_mutex);
struct user_t *user = user_get(newnick);
- if(user->seen_first == 0) {
+ if(user->seen_first == 0 || now_ut < user->seen_first) {
user->seen_first = now_ut;
}
- user->seen_last = now_ut;
+ user->seen_last = max(now_ut, user->seen_last);
pthread_mutex_unlock(&user_mutex);
continue;
@@ -338,10 +340,10 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
user->kicks++;
victim_user->kicked++;
- if(user->seen_first == 0) {
+ if(user->seen_first == 0 || now_ut < user->seen_first) {
user->seen_first = now_ut;
}
- user->seen_last = now_ut;
+ user->seen_last = max(now_ut, user->seen_last);
pthread_mutex_unlock(&user_mutex);
continue;