<commit_before>/* $Id$ */

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <errno.h>
#include <string.h>

#include "psc_util/assert.h"
#include "psc_util/atomic.h"
#include "psc_util/cdefs.h"
#include "psc_util/lock.h"
#include "psc_util/log.h"
#include "psc_util/waitq.h"

#if HAVE_LIBPTHREAD

#include <pthread.h>

#ifndef timespecadd
#define timespecadd(tsp, usp, vsp)					\
	do {								\
		(vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec;		\
		(vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec;	\
		if ((vsp)->tv_nsec >= 1000000000L) {			\
			(vsp)->tv_sec++;				\
			(vsp)->tv_nsec -= 1000000000L;			\
		}							\
	} while (0)
#endif

/**
 * psc_waitq_init - prepare the queue struct for use.
 * @q: the struct to be initialized.
 */
void
psc_waitq_init(struct psc_waitq *q)
{
	pthread_mutexattr_t attr;
	int rc;

	memset(q, 0, sizeof(*q));
	atomic_set(&q->wq_nwaitors, 0);

	rc = pthread_mutexattr_init(&attr);
	if (rc)
		psc_fatalx("pthread_mutexattr_init: %s", strerror(rc));
	rc = pthread_mutexattr_settype(&attr,
	    PTHREAD_MUTEX_ERRORCHECK_NP);
	if (rc)
		psc_fatalx("pthread_mutexattr_settype: %s",
		    strerror(rc));
	rc = pthread_mutex_init(&q->wq_mut, &attr);
	if (rc)
		psc_fatalx("pthread_mutex_init: %s", strerror(rc));
	rc = pthread_mutexattr_destroy(&attr);
	if (rc)
		psc_fatalx("pthread_mutexattr_destroy: %s",
		    strerror(rc));
	rc = pthread_cond_init(&q->wq_cond, NULL);
	if (rc)
		psc_fatalx("pthread_cond_init: %s", strerror(rc));
}

/*<commit_msg>temporarily remove ERRORCHECK type of mutex due to suspiscion of a pthread bug<commit_after>/* $Id$ */

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <errno.h>
#include <string.h>

#include "psc_util/assert.h"
#include "psc_util/atomic.h"
#include "psc_util/cdefs.h"
#include "psc_util/lock.h"
#include "psc_util/log.h"
#include "psc_util/waitq.h"

#if HAVE_LIBPTHREAD

#include <pthread.h>

#ifndef timespecadd
#define timespecadd(tsp, usp, vsp)					\
	do {								\
		(vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec;		\
		(vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec;	\
		if ((vsp)->tv_nsec >= 1000000000L) {			\
			(vsp)->tv_sec++;				\
			(vsp)->tv_nsec -= 1000000000L;			\
		}							\
	} while (0)
#endif

/**
 * psc_waitq_init - prepare the queue struct for use.
 * @q: the struct to be initialized.
 */
void
psc_waitq_init(struct psc_waitq *q)
{
	pthread_mutexattr_t attr;
	int rc;

	memset(q, 0, sizeof(*q));
	atomic_set(&q->wq_nwaitors, 0);

#if 0
	rc = pthread_mutexattr_init(&attr);
	if (rc)
		psc_fatalx("pthread_mutexattr_init: %s", strerror(rc));
	rc = pthread_mutexattr_settype(&attr,
	    PTHREAD_MUTEX_ERRORCHECK_NP);
	if (rc)
		psc_fatalx("pthread_mutexattr_settype: %s",
		    strerror(rc));
	rc = pthread_mutex_init(&q->wq_mut, &attr);
	if (rc)
		psc_fatalx("pthread_mutex_init: %s", strerror(rc));
	rc = pthread_mutexattr_destroy(&attr);
	if (rc)
		psc_fatalx("pthread_mutexattr_destroy: %s",
		    strerror(rc));
	rc = pthread_cond_init(&q->wq_cond, NULL);
	if (rc)
		psc_fatalx("pthread_cond_init: %s", strerror(rc));
#else
	rc = pthread_mutex_init(&q->wq_mut, &attr);
	if (rc)
		psc_fatalx("pthread_mutex_init: %s", strerror(rc));
	rc = pthread_cond_init(&q->wq_cond, NULL);
	if (rc)
		psc_fatalx("pthread_cond_init: %s", strerror(rc));
#endif
}

/*
{'fraction_non_alphanumeric': 0.1704337202199145, 'fraction_numerical': 0.014355528405620037, 'mean_word_length': 4.360065466448445, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '3846010', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1459, 'n_words': 258}