<commit_before>/* $Id$ */

#ifndef _PFL_COMPLETION_H_
#define _PFL_COMPLETION_H_

#define PCV_DONE	42
#define PCV_NOTDONE	43

struct psc_completion {
	struct psc_waitq	pc_wq;
	psc_spinlock_t		pc_lock;
	int			pc_done;
};

static __inline void
psc_completion_init(struct psc_completion *pc)
{
	pc->pc_done = PCV_NOTDONE;
	psc_waitq_init(&pc->pc_wq);
	LOCK_INIT(&pc->pc_lock);
}

static __inline void
psc_completion_wait(struct psc_completion *pc)
{
	spinlock(&pc->pc_lock);
	if (pc->pc_done == PCV_NOTDONE) {
		psc_waitq_wait(&pc->pc_wq, &pc->pc_lock);
		spinlock(&pc->pc_lock);
		psc_assert(pc->pc_done == PCV_DONE);
	}
	freelock(&pc->pc_lock);

}

static __inline void
psc_completion_done(struct psc_completion *pc)
{
	spinlock(&pc->pc_lock);
	pc->pc_done = PCV_DONE;
	psc_waitq_wakeall(&pc->pc_wq);
	freelock(&pc->pc_lock);
}

#endif /* _PFL_COMPLETION_H_ */<commit_msg>modify completion API to pass an integer around, useful for passing around error codes<commit_after>/* $Id$ */

#ifndef _PFL_COMPLETION_H_
#define _PFL_COMPLETION_H_

#define PCV_DONE	42
#define PCV_NOTDONE	43

struct psc_completion {
	struct psc_waitq	pc_wq;
	psc_spinlock_t		pc_lock;
	int			pc_done;
	int			pc_rc;
};

static __inline void
psc_completion_init(struct psc_completion *pc)
{
	pc->pc_done = PCV_NOTDONE;
	psc_waitq_init(&pc->pc_wq);
	LOCK_INIT(&pc->pc_lock);
	pc->pc_rc = 1;
}

static __inline int
psc_completion_wait(struct psc_completion *pc)
{
	spinlock(&pc->pc_lock);
	if (pc->pc_done == PCV_NOTDONE) {
		psc_waitq_wait(&pc->pc_wq, &pc->pc_lock);
		spinlock(&pc->pc_lock);
		psc_assert(pc->pc_done == PCV_DONE);
	}
	freelock(&pc->pc_lock);

	return (pc->pc_rc);
}

static __inline void
psc_completion_done(struct psc_completion *pc, int rc)
{
	spinlock(&pc->pc_lock);
	pc->pc_rc = rc;
	psc_assert(pc->pc_done == PCV_NOTDONE);
	pc->pc_done = PCV_DONE;
	psc_waitq_wakeall(&pc->pc_wq);
	freelock(&pc->pc_lock);
}

#endif /* _PFL_COMPLETION_H_ */
{'fraction_non_alphanumeric': 0.13619886069394097, 'fraction_numerical': 0.004660797514241326, 'mean_word_length': 5.662068965517242, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, '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': '6604733', 'n_tokens_mistral': 902, 'n_tokens_neox': 888, 'n_words': 145}