<commit_before>#include "types.h"
#include "user.h"
#include "lib.h"
#include "amd64.h"
#include "wq.hh"

#define NEW_DELETE_OPS(classname)                                   \
  static void* operator new(unsigned long nbytes) {                 \
    assert(nbytes == sizeof(classname));                            \
    return malloc(sizeof(classname));                               \
  }                                                                 \
                                                                    \
  static void operator delete(void *p) {                            \
    free(p);                                                        \
  }

struct testwork : public work {
  testwork(forframe *b) : barrier_(b) {}

  virtual void run() {
    barrier_->dec();
    delete this;
  }

  NEW_DELETE_OPS(testwork);
  struct forframe *barrier_;
};

static void
test0(void)
{
  enum { pushes = 100 };
  struct forframe wqbarrier(pushes);

  printf("test0...\n");
  for (int i = 0; i < pushes; i++) {
    testwork *w = new testwork(&wqbarrier);
    wq_push(w);
  }

  while (!wqbarrier.zero())
    nop_pause();
  printf("test0 done\n");
}

struct forkwork : public work {
  forkwork(forframe *b) : barrier_(b) {}

  virtual void run() {
    int pid;

    pid = fork(0);
    if (pid < 0)
      die("forkwork::run: fork");
    else if (pid == 0)
      exit();
    wait();

    barrier_->dec();
    delete this;
  }

  NEW_DELETE_OPS(forkwork);
  struct forframe *barrier_;
};

static void
testfork(void)
{
  enum { forks = 100 };
  struct forframe wqbarrier(forks);

  printf("testfork...\n");
  for (int i = 0; i < forks; i++) {
    forkwork *w = new forkwork(&wqbarrier);
    wq_push(w);
  }

  while (!wqbarrier.zero())
    nop_pause();
  printf("testfork done\n");
}

int
main(int ac, char **av)
{
  initwq();
  test0();
  testfork();
  exitwq();
  return 0;
}<commit_msg>More wq tests<commit_after>#include "types.h"
#include "user.h"
#include "lib.h"
#include "amd64.h"
#include "wq.hh"

#define NEW_DELETE_OPS(classname)                                   \
  static void* operator new(unsigned long nbytes) {                 \
    assert(nbytes == sizeof(classname));                            \
    return malloc(sizeof(classname));                               \
  }                                                                 \
                                                                    \
  static void operator delete(void *p) {                            \
    free(p);                                                        \
  }

struct testwork : public work {
  testwork(forframe *b) : barrier_(b) {}

  virtual void run() {
    barrier_->dec();
    delete this;
  }

  NEW_DELETE_OPS(testwork);
  struct forframe *barrier_;
};

static void
test0(void)
{
  enum { pushes = 100 };
  struct forframe wqbarrier(pushes);

  printf("test0...\n");
  for (int i = 0; i < pushes; i++) {
    testwork *w = new testwork(&wqbarrier);
    wq_push(w);
  }

  while (!wqbarrier.zero())
    nop_pause();
  printf("test0 done\n");
}

struct forkwork : public work {
  forkwork(forframe *b) : barrier_(b) {}

  virtual void run() {
    int pid;

    pid = fork(0);
    if (pid < 0)
      die("forkwork::run: fork");
    else if (pid == 0)
      exit();
    wait();

    barrier_->dec();
    delete this;
  }

  NEW_DELETE_OPS(forkwork);
  struct forframe *barrier_;
};

static void
testfork(void)
{
  enum { forks = 100 };
  struct forframe wqbarrier(forks);

  printf("testfork...\n");
  for (int i = 0; i < forks; i++) {
    forkwork *w = new forkwork(&wqbarrier);
    wq_push(w);
  }

  while (!wqbarrier.zero())
    nop_pause();
  printf("testfork done\n");
}

struct execwork : public work {
  execwork(forframe *b) : barrier_(b) {}

  virtual void run() {
    int pid;

    pid = fork(0);
    if (pid < 0)
      die("execwork::run: fork");
    else if (pid == 0) {
      static const char *args[] = { "echo", 0 };
      exec(args[0], args);
      die("execwork: exec failed");
    }
    wait();

    barrier_->dec();
    delete this;
  }

  static void test(void) {
    enum { execs = 100 };
    struct forframe wqbarrier(execs);

    printf("testexec...\n");
    for (int i = 0; i < execs; i++) {
      execwork *w = new execwork(&wqbarrier);
      wq_push(w);
    }
    
    while (!wqbarrier.zero())
      nop_pause();
    printf("testexec done\n");
  }

  NEW_DELETE_OPS(execwork);
  struct forframe *barrier_;
};

int
main(int ac, char **av)
{
  initwq();
  test0();
  testfork();
  execwork::test();
  exitwq();
  return 0;
}
{'fraction_non_alphanumeric': 0.14595185995623633, 'fraction_numerical': 0.009846827133479213, 'mean_word_length': 1.7719830200121285, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4349795', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1485, 'n_words': 356}