<commit_before>/*
  This is written by <NAME> for MySQL AB and is in public domain.

  Simple implementation of semaphores, needed to compile MySQL with
  MIT-pthreads.
*/

#include <pthread.h>
#include <errno.h>
#include <semaphore.h>

int sem_init(sem_t * sem, int pshared, uint value)
{
  sem->count=value;
  pthread_cond_init(&sem->cond, 0);
  pthread_mutex_init(&sem->mutex, 0);
  return 0;
}

int sem_destroy(sem_t * sem)
{
  int err1,err2;
  err1=pthread_cond_destroy(&sem->cond);
  err2=pthread_mutex_destroy(&sem->mutex);
  if (err1 || err2)
  {
    errno=err1 ? err1 : err2;
    return -1;
  }
  return 0;
}

int sem_wait(sem_t * sem)
{
  while ((errno=pthread_mutex_lock(&sem->mutex)) || !sem->count)
    pthread_cond_wait(&sem->cond, &sem->mutex);
  if (errno)
    return -1;
  sem->count--; /* mutex is locked here */
  pthread_mutex_unlock(&sem->mutex);
  return 0;
}
<commit_msg>semaphore.c:   semaphore fix<commit_after>/*
  This is written by <NAME> for MySQL AB and is in public domain.

  Simple implementation of semaphores, needed to compile MySQL with
  MIT-pthreads.
*/

#include <pthread.h>
#include <errno.h>
#include <semaphore.h>

int sem_init(sem_t * sem, int pshared, uint value)
{
  sem->count=value;
  pthread_cond_init(&sem->cond, 0);
  pthread_mutex_init(&sem->mutex, 0);
  return 0;
}

int sem_destroy(sem_t * sem)
{
  int err1,err2;
  err1=pthread_cond_destroy(&sem->cond);
  err2=pthread_mutex_destroy(&sem->mutex);
  if (err1 || err2)
  {
    errno=err1 ? err1 : err2;
    return -1;
  }
  return 0;
}

int sem_wait(sem_t * sem)
{
  if ((errno=pthread_mutex_lock(&sem->mutex)))
    return -1;
  while (!sem->count)
    pthread_cond_wait(&sem->cond, &sem->mutex);
  if (errno)
    return -1;
  sem->count--; /* mutex is locked here */
  pthread_mutex_unlock(&sem->mutex);
  return 0;
}

{'fraction_non_alphanumeric': 0.150384193194292, 'fraction_numerical': 0.018111964873765093, 'mean_word_length': 3.784776902887139, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 33, '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': '2249468', 'n_tokens_mistral': 732, 'n_tokens_neox': 712, 'n_words': 167}