<commit_before>#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <sys/resource.h>
#include <libtorque/events/evq.h>
#include <libtorque/events/sysdep.h>
#include <libtorque/events/thread.h>
#include <libtorque/events/signal.h>
#include <libtorque/events/sources.h>

static __thread evhandler *tsd_evhandler;

static void
handle_event(evhandler *eh,const kevententry *e){
	int ret = 0;

#ifdef LIBTORQUE_LINUX
	if(e->events & EPOLLIN){
#else
	if(e->filter == EVFILT_READ){
#endif
		ret |= handle_evsource_read(eh->evsources->fdarray,KEVENTENTRY_FD(e));
	}
#ifdef LIBTORQUE_LINUX
	if(e->events & EPOLLOUT){
#else
	if(e->filter == EVFILT_WRITE){
#endif
		ret |= handle_evsource_write(eh->evsources->fdarray,KEVENTENTRY_FD(e));
	}
}

static int
rxcommonsignal(int sig,libtorque_cbctx *nullv __attribute__ ((unused)),
				void *cbstate __attribute__ ((unused))){
	if(sig == EVTHREAD_TERM){
		void *ret = PTHREAD_CANCELED;
		evhandler *e = tsd_evhandler;
		int r;

		// FIXME this is kind of lame. I'd like to emulate
		// RUSAGE_THREAD when it's unavailable, and either way the test
		// ought be based on whether RUSAGE_THREAD is *expected*, not
		// *defined* (Linux 2.6.26+) for future-proofing.
#ifdef RUSAGE_THREAD
		struct rusage ru;
		getrusage(RUSAGE_THREAD,&ru);
		e->stats.utimeus = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
		e->stats.stimeus = ru.ru_stime.tv_sec * 1000000 + ru.ru_stime.tv_usec;
#endif
		e->stats.utimeus = e->stats.stimeus = 0;
		--e->stats.events;
		pthread_kill(e->nexttid,EVTHREAD_TERM);
		// We rely on EDEADLK to cut off our circular join()list
		if((r = pthread_join(e->nexttid,&ret)) && r != EDEADLK){
			ret = NULL;
		}
		if(destroy_evhandler(e)){
			ret = NULL;
		}
		pthread_exit(ret);
	}
	// FIXME else?
	return 0;
}

void event_thread(evhandler *e){<commit_msg>comment this out...<commit_after>#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <sys/resource.h>
#include <libtorque/events/evq.h>
#include <libtorque/events/sysdep.h>
#include <libtorque/events/thread.h>
#include <libtorque/events/signal.h>
#include <libtorque/events/sources.h>

static __thread evhandler *tsd_evhandler;

static void
handle_event(evhandler *eh,const kevententry *e){
	int ret = 0;

#ifdef LIBTORQUE_LINUX
	if(e->events & EPOLLIN){
#else
	if(e->filter == EVFILT_READ){
#endif
		ret |= handle_evsource_read(eh->evsources->fdarray,KEVENTENTRY_FD(e));
	}
#ifdef LIBTORQUE_LINUX
	if(e->events & EPOLLOUT){
#else
	if(e->filter == EVFILT_WRITE){
#endif
		ret |= handle_evsource_write(eh->evsources->fdarray,KEVENTENTRY_FD(e));
	}
}

static int
rxcommonsignal(int sig,libtorque_cbctx *nullv __attribute__ ((unused)),
				void *cbstate __attribute__ ((unused))){
	if(sig == EVTHREAD_TERM){
		void *ret = PTHREAD_CANCELED;
		evhandler *e = tsd_evhandler;
		int r;

		// FIXME this is kind of lame. I'd like to emulate
		// RUSAGE_THREAD when it's unavailable, and either way the test
		// ought be based on whether RUSAGE_THREAD is *expected*, not
		// *defined* (Linux 2.6.26+) for future-proofing.
#ifdef RUSAGE_THREAD
		struct rusage ru;
		getrusage(RUSAGE_THREAD,&ru);
		e->stats.utimeus = ru.ru_utime.tv_sec * 1000000 + ru.ru_utime.tv_usec;
		e->stats.stimeus = ru.ru_stime.tv_sec * 1000000 + ru.ru_stime.tv_usec;
#endif
		e->stats.utimeus = e->stats.stimeus = 0;
		--e->stats.events;
		// There's no POSIX thread cancellation going on here, nor are
		// we terminating due to signal; we're catching the signal and
		// exiting from this thread only. The trigger signal might be
		// delivered to any one of our threads; if we're here, though,
		// we cannot be holding the efd. Progress is thus assured.
		pthread_kill(e->nexttid,EVTHREAD_TERM);
		// We rely on EDEADLK to cut off our circular join()list
		if((r = pthread_join(e->nexttid,&ret)) && r != EDEADLK){
			ret = NULL;
		}
		if(destroy_evhandler(e)){
			ret = NULL;
		}
		pthread_exit(ret);
	}
	// FIXME else?
	return 0;
}

void event_thread(evhandler *e){
{'fraction_non_alphanumeric': 0.1398009950248756, 'fraction_numerical': 0.010447761194029851, 'mean_word_length': 4.426450742240216, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 53, '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': '336129', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1554, 'n_words': 361}