<commit_before>/* $Id$ */

struct psc_locked_list {
	struct psclist_head	pll_listhd;
	psc_spinlock_t		pll_lock;
	int			pll_nitems;
	int			pll_offset;
};

#define pll_init(pll, type, member) \
	_pll_init((pll), offsetof(type, member))

static inline void
_pll_init(struct psc_locked_list *pll, int offset)
{
	PSCLIST_INIT_HEAD(&pll->pll_listhd);
	LOCK_INIT(&pll->pll_lock);
	pll->pll_offset = offset;
	pll->pll_nitems = 0;
}

#define pll_add(pll, e)		_pll_add((pll), (e), 0)
#define pll_addstack(pll, e)	_pll_add((pll), (e), 0)
#define pll_addqueue(pll, e)	_pll_add((pll), (e), 1)
#define pll_addhead(pll, e)	_pll_add((pll), (e), 0)
#define pll_addtail(pll, e)	_pll_add((pll), (e), 1)

static inline void
_pll_add(struct psc_locked_list *pll, void *p, int tail)
{
	struct psclist_head *e;
	int locked;

	psc_assert(p);
	e = (char *)p + pll->pll_offset;

	locked = reqlock(&pll->pll_lock);
	if (tail)
		psclist_xadd_tail(e, &pll->pll_listhd);
	else
		psclist_xadd_head(e, &pll->pll_listhd);
	pll->pll_nitems++;
	ureqlock(&pll->pll_lock, locked);
}

static inline void *
pll_get(struct psc_locked_list *pll, int tail)
{
	struct psclist_head *e;

	locked = reqlock(&pll->pll_lock);
	if (psclist_empty(&pll->pll)) {
		ureqlock(&pll->pll_lock, locked);
		return (NULL);
	}
	if (tail)
		e = psclist_last(&pll);
	else
		e = psclist_first(&pll);
	psclist_del(e);
	ureqlock(&pll->pll_lock, locked);
	return ((char *)e - pll->pll_offset);
}

static inline int
pll_empty(struct psc_locked_list *pll)
{
	int empty;

	locked = reqlock(&pll->pll_lock);
	empty = psclist_empty(&pll->pll_lock);
	ureqlock(&pll->pll_lock, locked);
	return (empty);
}

static inline int
pll_sz(struct psc_locked_list *pll)
{
	int nitems;

	locked = reqlock(&pll->pll_lock);
	nitems = &pll->pll_nitems;
	ureqlock(&pll->pll_lock, locked);
	return (nitems);
}<commit_msg>track nitems better, compilation fixes<commit_after>/* $Id$ */

#include "psc_ds/list.h"
#include "psc_util/assert.h"
#include "psc_util/atomic.h"
#include "psc_util/lock.h"

struct psc_locked_list {
	struct psclist_head	pll_listhd;
	psc_spinlock_t		pll_lock;
	atomic_t		pll_nitems;
	int			pll_offset;
};

#define pll_init(pll, type, member) \
	_pll_init((pll), offsetof(type, member))

static inline void
_pll_init(struct psc_locked_list *pll, int offset)
{
	PSCLIST_INIT_HEAD(&pll->pll_listhd);
	LOCK_INIT(&pll->pll_lock);
	pll->pll_offset = offset;
	atomic_set(&pll->pll_nitems, 0);
}

#define pll_add(pll, e)		_pll_add((pll), (e), 0)
#define pll_addstack(pll, e)	_pll_add((pll), (e), 0)
#define pll_addqueue(pll, e)	_pll_add((pll), (e), 1)
#define pll_addhead(pll, e)	_pll_add((pll), (e), 0)
#define pll_addtail(pll, e)	_pll_add((pll), (e), 1)

static inline void
_pll_add(struct psc_locked_list *pll, void *p, int tail)
{
	struct psclist_head *e;
	int locked;

	psc_assert(p);
	e = (char *)p + pll->pll_offset;

	locked = reqlock(&pll->pll_lock);
	if (tail)
		psclist_xadd_tail(e, &pll->pll_listhd);
	else
		psclist_xadd_head(e, &pll->pll_listhd);
	atomic_inc(&pll->pll_nitems);
	ureqlock(&pll->pll_lock, locked);
}

static inline void *
pll_get(struct psc_locked_list *pll, int tail)
{
	struct psclist_head *e;

	locked = reqlock(&pll->pll_lock);
	if (psclist_empty(&pll->pll)) {
		ureqlock(&pll->pll_lock, locked);
		return (NULL);
	}
	if (tail)
		e = psclist_last(&pll);
	else
		e = psclist_first(&pll);
	psclist_del(e);
	atomic_dec(&pll->pll_nitems);
	ureqlock(&pll->pll_lock, locked);
	return ((char *)e - pll->pll_offset);
}

static inline int
pll_empty(struct psc_locked_list *pll)
{
	int empty;

	locked = reqlock(&pll->pll_lock);
	empty = psclist_empty(&pll->pll_lock);
	ureqlock(&pll->pll_lock, locked);
	return (empty);
}
{'fraction_non_alphanumeric': 0.16271463614063778, 'fraction_numerical': 0.003270645952575634, 'mean_word_length': 5.565295169946332, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, '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': '4813120', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1586, 'n_words': 319}