<commit_before>/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
#ident "Copyright (c) 2011 Tokutek Inc.  All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."

#include <config.h>
#include <toku_pthread.h>
#include "kibbutz.h"
#include "includes.h"

// A Kibbutz is a collection of workers and some work to do.
struct todo {
    void (*f)(void *extra);
    void *extra;
    struct todo *next;
    struct todo *prev;
};

struct kid {
    struct kibbutz *k;
};

struct kibbutz {
    toku_mutex_t mutex;
    toku_cond_t  cond;
    bool please_shutdown;
    struct todo *head, *tail; // head is the next thing to do.
    int n_workers;
    pthread_t *workers; // an array of n_workers
    struct kid *ids;    // pass this in when creating a worker so it knows who it is.
};

static void *work_on_kibbutz (void *);

KIBBUTZ toku_kibbutz_create (int n_workers) {
    KIBBUTZ XMALLOC(k);
    toku_mutex_init(&k->mutex, NULL);
    toku_cond_init(&k->cond, NULL);
    k->please_shutdown = false;
    k->head = NULL;
    k->tail = NULL;
    k->n_workers = n_workers;
    XMALLOC_N(n_workers, k->workers);
    XMALLOC_N(n_workers, k->ids);
    for (int i=0; i<n_workers; i++) {
        k->ids[i].k = k;
        int r = toku_pthread_create(&k->workers[i], NULL, work_on_kibbutz, &k->ids[i]);
        assert(r==0);
    }
    return k;
}

static void klock (KIBBUTZ k) {
    toku_mutex_lock(&k->mutex);
}
static void kunlock (KIBBUTZ k) {
    toku_mutex_unlock(&k->mutex);
}
static void kwait (KIBBUTZ k) {
    toku_cond_wait(&k->cond, &k->mutex);<commit_msg>refs #5507 clear kibbutz mutex<commit_after>/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id$"
#ident "Copyright (c) 2011 Tokutek Inc.  All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."

#include <config.h>
#include <toku_pthread.h>
#include "kibbutz.h"
#include "includes.h"

// A Kibbutz is a collection of workers and some work to do.
struct todo {
    void (*f)(void *extra);
    void *extra;
    struct todo *next;
    struct todo *prev;
};

struct kid {
    struct kibbutz *k;
};

struct kibbutz {
    toku_mutex_t mutex;
    toku_cond_t  cond;
    bool please_shutdown;
    struct todo *head, *tail; // head is the next thing to do.
    int n_workers;
    pthread_t *workers; // an array of n_workers
    struct kid *ids;    // pass this in when creating a worker so it knows who it is.
};

static void *work_on_kibbutz (void *);

KIBBUTZ toku_kibbutz_create (int n_workers) {
    KIBBUTZ XCALLOC(k);
    toku_mutex_init(&k->mutex, NULL);
    toku_cond_init(&k->cond, NULL);
    k->please_shutdown = false;
    k->head = NULL;
    k->tail = NULL;
    k->n_workers = n_workers;
    XMALLOC_N(n_workers, k->workers);
    XMALLOC_N(n_workers, k->ids);
    for (int i=0; i<n_workers; i++) {
        k->ids[i].k = k;
        int r = toku_pthread_create(&k->workers[i], NULL, work_on_kibbutz, &k->ids[i]);
        assert(r==0);
    }
    return k;
}

static void klock (KIBBUTZ k) {
    toku_mutex_lock(&k->mutex);
}
static void kunlock (KIBBUTZ k) {
    toku_mutex_unlock(&k->mutex);
}
static void kwait (KIBBUTZ k) {
    toku_cond_wait(&k->cond, &k->mutex);
{'fraction_non_alphanumeric': 0.12914166449256456, 'fraction_numerical': 0.010435690060005217, 'mean_word_length': 3.4119677790563867, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 37, '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': '6907410', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1378, 'n_words': 423}