<commit_before>#ifndef OPENOOC_H
#define OPENOOC_H


#define OPENOOC_MAJOR 0
#define OPENOOC_MINOR 0
#define OPENOOC_PATCH 0
#define OPENOOC_RCAND -pre


/* struct aiocb */
#include <aio.h>

/* EINPROGRESS, ECANCELED */
#include <errno.h>

/* memcpy */
#include <string.h>

/* jmp_buf */
#include <setjmp.h>

/* ucontext_t */
#include <ucontext.h>


/* Maximum number of fibers per thread. */
#define OOC_NUM_FIBERS 10


/* State flags for an OOC fiber. */
enum ooc_state_flags
{
  OOC_RUNNABLE,
  OOC_AIO_INPROGRESS
};


/* An execution context, henceforth known as a fiber. */
typedef struct ooc_fiber
{
  unsigned int state;
  struct aiocb aio;
  ucontext_t uc;
} ooc_fiber_t;


/* The stack environment to return to via longjmp. */
extern __thread jmp_buf ooc_ret_env;

/* The thread context at the point SIGSEGV was raised. */
extern __thread ucontext_t ooc_ret_uc;

/* The fibers. */
extern __thread ooc_fiber_t ooc_fiber[OOC_NUM_FIBERS];

/* Number of active fibers. */
extern __thread int ooc_cur_fibers;

/* My fiber id. */
extern __thread int ooc_me;


/* The OOC black magic. */
#define OOC_FOR(loops) \
  for (loops) {\
    int _ret, _i;\
\
    /* Initialize myself. */\
    ooc_fiber[ooc_me].state = OOC_RUNNABLE;\
\
    /* Set SIGSEGV return point. */\
    _ret = setjmp(ooc_ret_env);\
\
    /* If we arrived here via longjmp. */\
    if (_ret) {\
      /* Save my pre-sigsegv context. */\
      memcpy(&(ooc_fiber[ooc_me].uc), &ooc_ret_uc, sizeof(ooc_ret_uc));\
\
      /* Find a fiber that is runnable */\
      for (;;) {\
        /* Search existing fibers for one whose async-io is finished. */\
        for (_i=0; _i<ooc_cur_fibers; ++_i) {\
          if (OOC_AIO_INPROGRESS == ooc_fiber[_i].state) {\
            _ret = aio_error(&(ooc_fiber[_i].aio));\
\
            switch (_ret) {\
              case 0:\
              ooc_fiber[_i].state = OOC_RUNNABLE;\
              goto OOC_SEARCH_DONE;\
              break;\
\<commit_msg>removed self initalization, since this will happen with the appropriate state in sigsegv.c in the future<commit_after>#ifndef OPENOOC_H
#define OPENOOC_H


#define OPENOOC_MAJOR 0
#define OPENOOC_MINOR 0
#define OPENOOC_PATCH 0
#define OPENOOC_RCAND -pre


/* struct aiocb */
#include <aio.h>

/* EINPROGRESS, ECANCELED */
#include <errno.h>

/* memcpy */
#include <string.h>

/* jmp_buf */
#include <setjmp.h>

/* ucontext_t */
#include <ucontext.h>


/* Maximum number of fibers per thread. */
#define OOC_NUM_FIBERS 10


/* State flags for an OOC fiber. */
enum ooc_state_flags
{
  OOC_RUNNABLE,
  OOC_AIO_INPROGRESS
};


/* An execution context, henceforth known as a fiber. */
typedef struct ooc_fiber
{
  unsigned int state;
  struct aiocb aio;
  ucontext_t uc;
} ooc_fiber_t;


/* The stack environment to return to via longjmp. */
extern __thread jmp_buf ooc_ret_env;

/* The thread context at the point SIGSEGV was raised. */
extern __thread ucontext_t ooc_ret_uc;

/* The fibers. */
extern __thread ooc_fiber_t ooc_fiber[OOC_NUM_FIBERS];

/* Number of active fibers. */
extern __thread int ooc_cur_fibers;

/* My fiber id. */
extern __thread int ooc_me;


/* The OOC black magic. */
#define OOC_FOR(loops) \
  for (loops) {\
    int _ret, _i;\
\
    /* Set SIGSEGV return point. */\
    _ret = setjmp(ooc_ret_env);\
\
    /* If we arrived here via longjmp. */\
    if (_ret) {\
      /* Save my pre-sigsegv context. */\
      memcpy(&(ooc_fiber[ooc_me].uc), &ooc_ret_uc, sizeof(ooc_ret_uc));\
\
      /* Find a fiber that is runnable */\
      for (;;) {\
        /* Search existing fibers for one whose async-io is finished. */\
        for (_i=0; _i<ooc_cur_fibers; ++_i) {\
          if (OOC_AIO_INPROGRESS == ooc_fiber[_i].state) {\
            _ret = aio_error(&(ooc_fiber[_i].aio));\
\
            switch (_ret) {\
              case 0:\
              ooc_fiber[_i].state = OOC_RUNNABLE;\
              goto OOC_SEARCH_DONE;\
              break;\
\
{'fraction_non_alphanumeric': 0.12538304392236976, 'fraction_numerical': 0.003575076608784474, 'mean_word_length': 2.6676029962546814, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '3990961', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1492, 'n_words': 387}