<commit_before>#include "types.h"
#include "kernel.hh"
#include "spinlock.h"
#include "amd64.h"
#include "cpu.hh"
#include "kalloc.hh"
#include "wq.hh"

static wq *wq_;
static wq *wqcrit_;

void*
xallocwork(unsigned long nbytes)
{
  return kmalloc(nbytes, "xallocwork");
}

void 
xfreework(void* ptr, unsigned long nbytes)
{
  kmfree(ptr, nbytes);
}

size_t
wq_size(void)
{
  return sizeof(wq);
}

int
wq_push(work *w)
{
  return wq_->push(w, mycpuid());
}

void
wqcrit_trywork(void)
{
  while (wqcrit_->trywork(false))
    ;
}

int
wqcrit_push(work *w, int c)
{
  return wqcrit_->push(w, c);
}

int
wq_trywork(void)
{
  return wqcrit_->trywork(false) || wq_->trywork(true);
}

void
wq_dump(void)
{
  return wq_->dump();
}

void
initwq(void)
{
  wq_ = new wq();<commit_msg>Assert if work queues are used too early<commit_after>#include "types.h"
#include "kernel.hh"
#include "spinlock.h"
#include "amd64.h"
#include "cpu.hh"
#include "kalloc.hh"
#include "wq.hh"

static wq *wq_;
static wq *wqcrit_;

void*
xallocwork(unsigned long nbytes)
{
  return kmalloc(nbytes, "xallocwork");
}

void 
xfreework(void* ptr, unsigned long nbytes)
{
  kmfree(ptr, nbytes);
}

size_t
wq_size(void)
{
  return sizeof(wq);
}

int
wq_push(work *w)
{
  assert(wq_);
  return wq_->push(w, mycpuid());
}

void
wqcrit_trywork(void)
{
  assert(wqcrit_);
  while (wqcrit_->trywork(false))
    ;
}

int
wqcrit_push(work *w, int c)
{
  assert(wqcrit_);
  return wqcrit_->push(w, c);
}

int
wq_trywork(void)
{
  assert(wq_ && wqcrit_);
  return wqcrit_->trywork(false) || wq_->trywork(true);
}

void
wq_dump(void)
{
  if (wq_)
    return wq_->dump();
}

void
initwq(void)
{
  wq_ = new wq();
{'fraction_non_alphanumeric': 0.16576576576576577, 'fraction_numerical': 0.0024024024024024023, 'mean_word_length': 4.553333333333334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '6295751', 'n_tokens_mistral': 732, 'n_tokens_neox': 758, 'n_words': 155}