<commit_before>/* Copyright (C) 2010, Parrot Foundation.
 * $Id$
 */

#ifndef PARROT_THREADS_H_GUARD
#define PARROT_THREADS_H_GUARD

#include "parrot/thread.h"

enum Thread_states {
    THREAD_STATE_INITIALIZED = 0x01, /* Thread has been created */
    THREAD_STATE_RUNNABLE    = 0x02, /* We could signal this thread and it would run */
    THREAD_STATE_SCAN_STACK  = 0x04, /* This thread may have PMCs on its stack */
    THREAD_STATE_RESTLESS    = 0x08, /* This thread wants to run ASAP */
    THREAD_STATE_DEATH_MARK  = 0x10  /* This thread is marked for death */
};

#define THREAD_STATE_TEST(interp, tidx, flag) \
    ((interp)->thread_table->threads[(tidx)].state & (THREAD_STATE_ ## flag))
#define THREAD_STATE_SET(interp, tidx, flag) \
    ((interp)->thread_table->threads[(tidx)].state |= (THREAD_STATE_ ## flag))
#define THREAD_STATE_CLEAR(interp, tidx, flag) \
    ((interp)->thread_table->threads[(tidx)].state &= ~(THREAD_STATE_ ## flag))

typedef struct Thread_info {
    Parrot_thread id;
    INTVAL        state;
    Parrot_cond   cvar;
    void         *lo_var_ptr; /* Full range of stack for GC scan */
    void         *hi_var_ptr;
    PMC          *cur_task;
} Thread_info;

typedef struct Thread_table {
    Thread_info   *threads;
    INTVAL         size;
    INTVAL         count;
    Parrot_tls_key tid_key;
} Thread_table;

typedef struct Thread_args {
    Interp* interp;
    INTVAL  idx;
} Thread_args;

#define LOCK_INTERP(interp) \
    LOCK((interp)->interp_lock)

#define UNLOCK_INTERP(interp) \
    UNLOCK((interp)->interp_lock)

#define BLOCK_THREAD_ON((interp), (blocking_call)) \
    do { \
      INTVAL tid, runloop_id, runloop_level; \
      PMC *context = Parrot_pmc_new((interp), enum_class_Continuation); \
      runloop_id    = interp->current_runloop_id; \
      runloop_level = interp->current_runloop_level; \
      Parrot_threads_block((interp), &tid); \
      blocking_call; \
      Parrot_threads_unblock((interp), &tid); \
      (void) VTABLE_invoke((interp), context, 0); \
      interp->current_runloop_id    = runloop_id; \
      interp->current_runloop_level = runloop_level; \
    } while (0)

/* HEADERIZER BEGIN: src/threads.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */

void Parrot_check_if_task_killed(PARROT_INTERP)
        __attribute__nonnull__(1);

void Parrot_threads_block(PARROT_INTERP, ARGOUT(INTVAL *tidx))
        __attribute__nonnull__(1)
        __attribute__nonnull__(2)
        FUNC_MODIFIES(*tidx);

INTVAL Parrot_threads_check_and_reset(PARROT_INTERP)
        __attribute__nonnull__(1);

void Parrot_threads_cleanup(PARROT_INTERP)
        __attribute__nonnull__(1);
<commit_msg>revert f27900c32af063ea55ab75f0b1f12bca4b5d98b6, fixing build failure<commit_after>/* Copyright (C) 2010, Parrot Foundation.
 * $Id$
 */

#ifndef PARROT_THREADS_H_GUARD
#define PARROT_THREADS_H_GUARD

#include "parrot/thread.h"

enum Thread_states {
    THREAD_STATE_INITIALIZED = 0x01, /* Thread has been created */
    THREAD_STATE_RUNNABLE    = 0x02, /* We could signal this thread and it would run */
    THREAD_STATE_SCAN_STACK  = 0x04, /* This thread may have PMCs on its stack */
    THREAD_STATE_RESTLESS    = 0x08, /* This thread wants to run ASAP */
    THREAD_STATE_DEATH_MARK  = 0x10  /* This thread is marked for death */
};

#define THREAD_STATE_TEST(interp, tidx, flag) \
    ((interp)->thread_table->threads[(tidx)].state & (THREAD_STATE_ ## flag))
#define THREAD_STATE_SET(interp, tidx, flag) \
    ((interp)->thread_table->threads[(tidx)].state |= (THREAD_STATE_ ## flag))
#define THREAD_STATE_CLEAR(interp, tidx, flag) \
    ((interp)->thread_table->threads[(tidx)].state &= ~(THREAD_STATE_ ## flag))

typedef struct Thread_info {
    Parrot_thread id;
    INTVAL        state;
    Parrot_cond   cvar;
    void         *lo_var_ptr; /* Full range of stack for GC scan */
    void         *hi_var_ptr;
    PMC          *cur_task;
} Thread_info;

typedef struct Thread_table {
    Thread_info   *threads;
    INTVAL         size;
    INTVAL         count;
    Parrot_tls_key tid_key;
} Thread_table;

typedef struct Thread_args {
    Interp* interp;
    INTVAL  idx;
} Thread_args;

#define LOCK_INTERP(interp) \
    LOCK((interp)->interp_lock)

#define UNLOCK_INTERP(interp) \
    UNLOCK((interp)->interp_lock)

#define BLOCK_THREAD_ON(interp, blocking_call) \
    do { \
      INTVAL tid, runloop_id, runloop_level; \
      PMC *context = Parrot_pmc_new((interp), enum_class_Continuation); \
      runloop_id    = interp->current_runloop_id; \
      runloop_level = interp->current_runloop_level; \
      Parrot_threads_block((interp), &tid); \
      blocking_call; \
      Parrot_threads_unblock((interp), &tid); \
      (void) VTABLE_invoke((interp), context, 0); \
      interp->current_runloop_id    = runloop_id; \
      interp->current_runloop_level = runloop_level; \
    } while (0)

/* HEADERIZER BEGIN: src/threads.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */

void Parrot_check_if_task_killed(PARROT_INTERP)
        __attribute__nonnull__(1);

void Parrot_threads_block(PARROT_INTERP, ARGOUT(INTVAL *tidx))
        __attribute__nonnull__(1)
        __attribute__nonnull__(2)
        FUNC_MODIFIES(*tidx);

INTVAL Parrot_threads_check_and_reset(PARROT_INTERP)
        __attribute__nonnull__(1);

void Parrot_threads_cleanup(PARROT_INTERP)
        __attribute__nonnull__(1);

{'fraction_non_alphanumeric': 0.10840058694057227, 'fraction_numerical': 0.013756419662509171, 'mean_word_length': 3.525311203319502, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '3066675', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1918, 'n_words': 384}