<commit_before>/* $Id$ */

/*
 * Multilockable lists are essentially multilock-aware list caches.
 */

#include "psc_ds/list.h"
#include "psc_ds/lockedlist.h"
#include "psc_util/assert.h"
#include "psc_util/lock.h"
#include "psc_util/mlist.h"
#include "psc_util/multilock.h"

struct psc_lockedlist psc_mlists =
    PLL_INITIALIZER(&psc_mlists, struct psc_mlist, pml_index_lentry);

/**
 * psc_mlist_size - determine number of elements on an mlist.
 * @pml: the multilockable list to inspect.
 */
int
psc_mlist_size(struct psc_mlist *pml)
{
	int locked, size;

	locked = reqlock(&pml->pml_lock);
	size = psclist_empty(&pml->pml_listhd);
	ureqlock(&pml->pml_lock, locked);
	return (size);
}

/**
 * psc_mlist_get - get an item from a multilockable list.
 * @pml: the multilockable list to access.
 */
struct psclist_head *
psc_mlist_tryget(struct psc_mlist *pml)
{
	struct psclist_head *e;
	int locked;

	locked = reqlock(&pml->pml_lock);
	if (psclist_empty(&pml->pml_listhd)) {
		ureqlock(&pml->pml_lock, locked);
		return (NULL);
	}
	e = psclist_first(&pml->pml_listhd);
	psclist_del(e);
	psc_assert(pml->pml_size-- > 0);
	ureqlock(&pml->pml_lock, locked);
	return (e);
}

/**
 * psc_mlist_put - put an item on a multilockable list.
 * @pml: the multilockable list to access.<commit_msg>fix big thinko that prevented psc_mlist_size from working, which screwed up the zest syncer in a very subtle way eventually halting behavior entirely in zestiond, discovered by paul<commit_after>/* $Id$ */

/*
 * Multilockable lists are essentially multilock-aware list caches.
 */

#include "psc_ds/list.h"
#include "psc_ds/lockedlist.h"
#include "psc_util/assert.h"
#include "psc_util/lock.h"
#include "psc_util/mlist.h"
#include "psc_util/multilock.h"

struct psc_lockedlist psc_mlists =
    PLL_INITIALIZER(&psc_mlists, struct psc_mlist, pml_index_lentry);

/**
 * psc_mlist_size - determine number of elements on an mlist.
 * @pml: the multilockable list to inspect.
 */
int
psc_mlist_size(struct psc_mlist *pml)
{
	int locked, size;

	locked = reqlock(&pml->pml_lock);
	size = pml->pml_size;
	ureqlock(&pml->pml_lock, locked);
	return (size);
}

/**
 * psc_mlist_get - get an item from a multilockable list.
 * @pml: the multilockable list to access.
 */
struct psclist_head *
psc_mlist_tryget(struct psc_mlist *pml)
{
	struct psclist_head *e;
	int locked;

	locked = reqlock(&pml->pml_lock);
	if (psclist_empty(&pml->pml_listhd)) {
		ureqlock(&pml->pml_lock, locked);
		return (NULL);
	}
	e = psclist_first(&pml->pml_listhd);
	psclist_del(e);
	psc_assert(pml->pml_size-- > 0);
	ureqlock(&pml->pml_lock, locked);
	return (e);
}

/**
 * psc_mlist_put - put an item on a multilockable list.
 * @pml: the multilockable list to access.
{'fraction_non_alphanumeric': 0.13252569750367107, 'fraction_numerical': 0.0007342143906020558, 'mean_word_length': 4.677083333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '2247878', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1116, 'n_words': 250}