<commit_before>#include <stdio.h>

#include "bg_manager.h"
#include "login_server.h"
#include "cli.h"

pthread_t bg_manager;

pthread_mutex_t bg_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t bg_wait  = PTHREAD_COND_INITIALIZER;

#define WAITTIME ((uint64_t) 1e5)

int add_umessage(struct message *m) {
	return -1;
}

int add_pkeyresp(struct message *m) {
	return -1;
}

int add_unotfound(struct message *m) {
	return -1;
}

void *background_thread(void *_arg) {
	struct server_connection *sc = (struct server_connection *) _arg;

	while(get_mode() != -1) {
		struct message *m = recv_message(sc->ch, &sc->keys, WAITTIME);
		if(m == NULL) continue;

		int ret = 0;
		switch(m->message[0]) {
		case 0:
			ret = add_umessage(m);
			break;
		case 1:
			ret = add_pkeyresp(m);
			break;
		case 0xff:
			ret = add_unotfound(m);
			break;
		}
		if(ret != 0) {
			break;
		}
	}

	fprintf(stderr, "background thread crashed\n");
	acquire_writelock(&lock);
	stop = 1;<commit_msg>background thread delivers key responses now<commit_after>#include <stdio.h>

#include "bg_manager.h"
#include "login_server.h"
#include "cli.h"
#include "friendreq.h"

pthread_t bg_manager;

pthread_mutex_t bg_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t bg_wait  = PTHREAD_COND_INITIALIZER;

#define WAITTIME ((uint64_t) 1e5)

int add_umessage(struct message *m) {
	return -1;
}

int add_pkeyresp(struct message *m) {
	pthread_mutex_lock(&bg_lock);
	if(get_mode() != 2) {
		pthread_mutex_unlock(&bg_lock);
		return -1;
	}

	pkey_resp = m;
	pthread_cond_broadcast(&bg_wait);
	pthread_mutex_unlock(&bg_lock);
	return 0;
}

int add_unotfound(struct message *m) {
	pthread_mutex_lock(&bg_lock);
	if(get_mode() != 2) {
		pthread_mutex_unlock(&bg_lock);
		return -1;
	}

	pkey_resp = m;
	pthread_cond_broadcast(&bg_wait);
	pthread_mutex_unlock(&bg_lock);
	return 0;
}

void *background_thread(void *_arg) {
	struct server_connection *sc = (struct server_connection *) _arg;

	while(get_mode() != -1) {
		struct message *m = recv_message(sc->ch, &sc->keys, WAITTIME);
		if(m == NULL) continue;

		int ret = 0;
		switch(m->message[0]) {
		case 0:
			ret = add_umessage(m);
			break;
		case 1:
			ret = add_pkeyresp(m);
			break;
		case 0xff:
			ret = add_unotfound(m);
			break;
		}
		if(ret != 0) {
			break;
		}
	}

	fprintf(stderr, "background thread crashed\n");
	acquire_writelock(&lock);
	stop = 1;
{'fraction_non_alphanumeric': 0.13816343723673125, 'fraction_numerical': 0.014321819713563605, 'mean_word_length': 4.510440835266821, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1026284', 'n_tokens_mistral': 1058, 'n_tokens_neox': 975, 'n_words': 200}