<commit_before>#include "silly_conf.h"
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

#include "silly.h"
#include "compiler.h"
#include "silly_log.h"
#include "silly_env.h"
#include "silly_malloc.h"
#include "silly_timer.h"
#include "silly_socket.h"
#include "silly_worker.h"
#include "silly_daemon.h"

#include "silly_run.h"

struct {
	int running;
	int workerstatus; /* 0:sleep 1:running -1:dead */
	const struct silly_config *conf;
	pthread_mutex_t mutex;
	pthread_cond_t cond;
} R;


static void *
thread_timer(void *arg)
{
	(void)arg;
	for (;;) {
		silly_timer_update();
		if (R.workerstatus == -1)
			break;
		usleep(TIMER_ACCURACY);
		if (R.workerstatus == 0)
			pthread_cond_signal(&R.cond);
	}
	silly_socket_terminate();
	return NULL;
}


static void *
thread_socket(void *arg)
{
	(void)arg;
	for (;;) {
		int err = silly_socket_poll();
		if (err < 0)
			break;
		if (R.workerstatus == 0)
			pthread_cond_signal(&R.cond);
	}
	return NULL;
}

static void *
thread_worker(void *arg)
{
	const struct silly_config *c;
	c = (struct silly_config *)arg;
	silly_worker_start(c);
	while (R.running) {
		silly_worker_dispatch();
		//allow spurious wakeup, it's harmless
		R.workerstatus = 0;
		pthread_cond_wait(&R.cond, &R.mutex);
		R.workerstatus = 1;
	}<commit_msg>bugfix incorrect use of pthread_cond_wait<commit_after>#include "silly_conf.h"
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

#include "silly.h"
#include "compiler.h"
#include "silly_log.h"
#include "silly_env.h"
#include "silly_malloc.h"
#include "silly_timer.h"
#include "silly_socket.h"
#include "silly_worker.h"
#include "silly_daemon.h"

#include "silly_run.h"

struct {
	int running;
	int workerstatus; /* 0:sleep 1:running -1:dead */
	const struct silly_config *conf;
	pthread_mutex_t mutex;
	pthread_cond_t cond;
} R;


static void *
thread_timer(void *arg)
{
	(void)arg;
	for (;;) {
		silly_timer_update();
		if (R.workerstatus == -1)
			break;
		usleep(TIMER_ACCURACY);
		if (R.workerstatus == 0)
			pthread_cond_signal(&R.cond);
	}
	silly_socket_terminate();
	return NULL;
}


static void *
thread_socket(void *arg)
{
	(void)arg;
	for (;;) {
		int err = silly_socket_poll();
		if (err < 0)
			break;
		if (R.workerstatus == 0)
			pthread_cond_signal(&R.cond);
	}
	return NULL;
}

static void *
thread_worker(void *arg)
{
	const struct silly_config *c;
	c = (struct silly_config *)arg;
	silly_worker_start(c);
	pthread_mutex_lock(&R.mutex);
	while (R.running) {
		silly_worker_dispatch();
		//allow spurious wakeup, it's harmless
		R.workerstatus = 0;
		pthread_cond_wait(&R.cond, &R.mutex);
		R.workerstatus = 1;
	}
	pthread_mutex_unlock(&R.mutex);
{'fraction_non_alphanumeric': 0.15220483641536273, 'fraction_numerical': 0.006401137980085348, 'mean_word_length': 4.682828282828283, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, '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': '3355418', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1161, 'n_words': 242}