<commit_before>#pragma once

#include    <stddef.h>
#include    <stdint.h>

#include    "./util_list.h"


static uint8_t index_mapping_[] = {
    [0]            = 0,
    [(uint8_t) -1] = 1
};

struct cp_queue {
    uint8_t index_producer;
    struct link_index buffers[2];
};

#define producer_index_of(queue_) __atomic_load_n(&((queue_)->index_producer), __ATOMIC_ACQUIRE)
#define consumer_index_of(queue_) (1 - producer_index_of((queue_)))
#define new_consumer_index_of(queue_) \
    ({ \
        __auto_type queue__ = (queue_); \
        index_mapping_[ \
            __atomic_fetch_xor(&(queue__->index_producer), (uint8_t) -1, __ATOMIC_ACQ_REL) \
        ]; \
    })

static inline
struct link_index *cp_queue_consume(struct cp_queue *queue) {
    uint8_t index_consumer = consumer_index_of(queue);
    return
        list_is_empty(&(queue->buffers[index_consumer])) ?
            &(queue->buffers[index_consumer]) :
            &(queue->buffers[new_consumer_index_of(queue)]);
}

static inline
void cp_queue_produce(struct cp_queue *queue, struct link_index *product) {
    list_add_tail(product, &(queue->buffers[producer_index_of(queue)]));
}

static inline
struct cp_queue *cp_queue_init(struct cp_queue *queue) {
    __atomic_store_n(&(queue->index_producer), 0, __ATOMIC_RELEASE);
    list_init(&(queue->buffers[0]));
    list_init(&(queue->buffers[1]));
}<commit_msg>Error fix: wrong consuming order.<commit_after>#pragma once

#include    <stddef.h>
#include    <stdint.h>

#include    "./util_list.h"


static uint8_t index_mapping_[] = {
    [0]            = 0,
    [(uint8_t) -1] = 1
};

struct cp_queue {
    uint8_t index_producer;
    struct link_index buffers[2];
};

#define producer_index_of(queue_) __atomic_load_n(&((queue_)->index_producer), __ATOMIC_ACQUIRE)
#define consumer_index_of(queue_) (1 - producer_index_of((queue_)))
#define new_consumer_index_of(queue_) \
    ({ \
        __auto_type queue__ = (queue_); \
        index_mapping_[ \
            __atomic_fetch_xor(&(queue__->index_producer), (uint8_t) -1, __ATOMIC_ACQ_REL) \
        ]; \
    })

static inline
struct link_index *cp_queue_consume(struct cp_queue *queue) {
    uint8_t index_consumer = consumer_index_of(queue);
    return
        list_is_empty(&(queue->buffers[index_consumer])) ?
            &(queue->buffers[new_consumer_index_of(queue)]) :
            &(queue->buffers[index_consumer]);
}

static inline
void cp_queue_produce(struct cp_queue *queue, struct link_index *product) {
    list_add_tail(product, &(queue->buffers[producer_index_of(queue)]));
}

static inline
struct cp_queue *cp_queue_init(struct cp_queue *queue) {
    __atomic_store_n(&(queue->index_producer), 0, __ATOMIC_RELEASE);
    list_init(&(queue->buffers[0]));
    list_init(&(queue->buffers[1]));
}
{'fraction_non_alphanumeric': 0.1375089992800576, 'fraction_numerical': 0.01079913606911447, 'mean_word_length': 4.052727272727273, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, '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': '2437008', 'n_tokens_mistral': 1013, 'n_tokens_neox': 992, 'n_words': 160}