<commit_before>#include "mir_stack.h"
#include "mir_utils.h"
#include "mir_memory.h"
#include "mir_defines.h"
#include "mir_lock.h"

struct mir_stack_t* mir_stack_create(uint32_t capacity)
{/*{{{*/
    struct mir_stack_t* stack = mir_cmalloc_int(sizeof(struct mir_stack_t));
    MIR_ASSERT(stack != NULL);

    stack->buffer = NULL;
    stack->buffer = mir_cmalloc_int(capacity * sizeof(void*));
    MIR_ASSERT(stack->buffer != NULL);

    stack->capacity = capacity;
    stack->head = 0;

    mir_lock_create(&(stack->lock));
    return stack;
}/*}}}*/

void mir_stack_destroy(struct mir_stack_t* stack)
{/*{{{*/
    MIR_ASSERT(stack != NULL);
    MIR_ASSERT(stack->buffer != NULL);

    mir_lock_destroy(&(stack->lock));
    mir_free_int(stack->buffer, stack->capacity * sizeof(void*));
    stack->buffer = NULL;
    mir_free_int(stack, sizeof(struct mir_stack_t));
    stack = NULL;
}/*}}}*/

int mir_stack_push(struct mir_stack_t* stack, void* data)
{/*{{{*/
    MIR_ASSERT(stack != NULL);
    MIR_ASSERT(data != NULL);

    mir_lock_set(&(stack->lock));

    if (STACK_FULL(stack))
    {
        S_DBG("stack full!", stack);
        //__sync_synchronize();
        mir_lock_unset(&(stack->lock));
        return 0;
    }
    stack->buffer[stack->head] = (void*) data;
    stack->head++;

    //__sync_synchronize();
    mir_lock_unset(&(stack->lock));

    return 1;
}/*}}}*/

void mir_stack_pop(struct mir_stack_t* stack, void** data)
{/*{{{*/
    MIR_ASSERT(stack != NULL);
    MIR_ASSERT(data != NULL);

    mir_lock_set(&(stack->lock));
    if (STACK_EMPTY(stack))
    {
        S_DBG("stack empty", stack);
        mir_lock_unset(&(stack->lock));
        return;
    }
    *data = stack->buffer[stack->head - 1];
    MIR_ASSERT(*data != NULL);
    stack->head--;
    //__sync_synchronize();
    mir_lock_unset(&(stack->lock));
    return;
}/*}}}*/

uint32_t mir_stack_size(const struct mir_stack_t *stack)
{/*{{{*/
    MIR_ASSERT(stack != NULL);

    //__sync_synchronize();
    //mir_lock_set(&(stack->lock));
    uint32_t size = stack->head ;
    //mir_lock_unset(&(stack->lock));
    return size;
}/*}}}*/
<commit_msg>Indentation and stripped white space.<commit_after>#include "mir_stack.h"
#include "mir_utils.h"
#include "mir_memory.h"
#include "mir_defines.h"
#include "mir_lock.h"

struct mir_stack_t* mir_stack_create(uint32_t capacity)
{ /*{{{*/
    struct mir_stack_t* stack = mir_cmalloc_int(sizeof(struct mir_stack_t));
    MIR_ASSERT(stack != NULL);

    stack->buffer = NULL;
    stack->buffer = mir_cmalloc_int(capacity * sizeof(void*));
    MIR_ASSERT(stack->buffer != NULL);

    stack->capacity = capacity;
    stack->head = 0;

    mir_lock_create(&(stack->lock));
    return stack;
} /*}}}*/

void mir_stack_destroy(struct mir_stack_t* stack)
{ /*{{{*/
    MIR_ASSERT(stack != NULL);
    MIR_ASSERT(stack->buffer != NULL);

    mir_lock_destroy(&(stack->lock));
    mir_free_int(stack->buffer, stack->capacity * sizeof(void*));
    stack->buffer = NULL;
    mir_free_int(stack, sizeof(struct mir_stack_t));
    stack = NULL;
} /*}}}*/

int mir_stack_push(struct mir_stack_t* stack, void* data)
{ /*{{{*/
    MIR_ASSERT(stack != NULL);
    MIR_ASSERT(data != NULL);

    mir_lock_set(&(stack->lock));

    if (STACK_FULL(stack)) {
        S_DBG("stack full!", stack);
        //__sync_synchronize();
        mir_lock_unset(&(stack->lock));
        return 0;
    }
    stack->buffer[stack->head] = (void*)data;
    stack->head++;

    //__sync_synchronize();
    mir_lock_unset(&(stack->lock));

    return 1;
} /*}}}*/

void mir_stack_pop(struct mir_stack_t* stack, void** data)
{ /*{{{*/
    MIR_ASSERT(stack != NULL);
    MIR_ASSERT(data != NULL);

    mir_lock_set(&(stack->lock));
    if (STACK_EMPTY(stack)) {
        S_DBG("stack empty", stack);
        mir_lock_unset(&(stack->lock));
        return;
    }
    *data = stack->buffer[stack->head - 1];
    MIR_ASSERT(*data != NULL);
    stack->head--;
    //__sync_synchronize();
    mir_lock_unset(&(stack->lock));
    return;
} /*}}}*/

uint32_t mir_stack_size(const struct mir_stack_t* stack)
{ /*{{{*/
    MIR_ASSERT(stack != NULL);

    //__sync_synchronize();
    //mir_lock_set(&(stack->lock));
    uint32_t size = stack->head;
    //mir_lock_unset(&(stack->lock));
    return size;
} /*}}}*/

{'fraction_non_alphanumeric': 0.18735417638824078, 'fraction_numerical': 0.004666355576294913, 'mean_word_length': 3.4470954356846475, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 55, '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': '5126291', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1554, 'n_words': 251}