<commit_before>//<NAME>
//<EMAIL>
//<NAME>
//<EMAIL>
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
#include "psem.h"

void psem_init(psem_t *semaphore, int value) {
	//FIXME error checking (........)
	pthread_mutex_init(&semaphore->lock, NULL);
	pthread_cond_init(&semaphore->condvar, NULL); 
	semaphore->counter = value;
}

psem_t * psem_new(int value) {
	psem_t *ret = calloc(1, sizeof(psem_t));
	if(ret == NULL) {
		errno = ENOMEM;
	}
	else {
		psem_init(ret, value);
	}
	return ret;
}

void psem_free(psem_t *semaphore) {
	free(semaphore);
}

void psem_up(psem_t *semaphore) {
	pthread_mutex_lock(&semaphore->lock);
	if(++(semaphore->counter) <= 0) {
		pthread_cond_signal(&semaphore->condvar);
	}
	pthread_mutex_unlock(&semaphore->lock);
}

void psem_down(psem_t *semaphore) {
	pthread_mutex_lock(&semaphore->lock);
	if(--(semaphore->counter) < 0) {
		pthread_cond_wait(&semaphore->condvar, &semaphore->lock); 
	}
	pthread_mutex_unlock(&semaphore->lock);
}

int psem_peek(psem_t *semaphore) {
	//returns the value in the semaphore. Because we cant use this for "real" decisions using this information anyway, we don't bother taking the lock.
	return semaphore->counter;
}<commit_msg>oops hadn't committed the changes to the real psem xD<commit_after>//<NAME>
//<EMAIL>
//<NAME>
//<EMAIL>
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
#include "psem.h"

void psem_init(psem_t *semaphore, int value) {
	//FIXME error checking (........)
	pthread_mutex_init(&semaphore->lock, NULL);
	pthread_cond_init(&semaphore->condvar, NULL); 
	semaphore->counter = value;
}

psem_t * psem_new(int value) {
	psem_t *ret = calloc(1, sizeof(psem_t));
	if(ret == NULL) {
		errno = ENOMEM;
	}
	else {
		psem_init(ret, value);
	}
	return ret;
}

void psem_free(psem_t *semaphore) {
	free(semaphore);
}

void psem_up(psem_t *semaphore) {
	pthread_mutex_lock(&semaphore->lock);
	if(++(semaphore->counter) <= 0) {
		pthread_cond_signal(&semaphore->condvar);
	}
	pthread_mutex_unlock(&semaphore->lock);
}

void psem_down(psem_t *semaphore) {
	pthread_mutex_lock(&semaphore->lock);
	if(--(semaphore->counter) < 0) {
		pthread_cond_wait(&semaphore->condvar, &semaphore->lock); 
	}
	pthread_mutex_unlock(&semaphore->lock);
}

int psem_peek(psem_t *semaphore) {
	pthread_mutex_lock(&semaphore->lock);
	int ret = semaphore->counter;
	pthread_mutex_unlock(&semaphore->lock);
	return ret;
}
{'fraction_non_alphanumeric': 0.1668757841907152, 'fraction_numerical': 0.002509410288582183, 'mean_word_length': 5.196891191709844, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 45, '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': '4161026', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1036, 'n_words': 174}