<commit_before>/*
 * Copyright 2014 - 2017 Real Logic Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define _GNU_SOURCE

#include <string.h>
#include <stdio.h>
#include <dlfcn.h>
#include <sched.h>
#include "aeron_agent.h"
#include "aeron_alloc.h"
#include "aeron_driver_context.h"

static void aeron_idle_strategy_sleeping_idle(void *state, int work_count)
{
    if (work_count > 0)
    {
        return;
    }

    nanosleep(&(struct timespec){.tv_nsec=1}, NULL);
}

static void aeron_idle_strategy_yielding_idle(void *state, int work_count)
{
    if (work_count > 0)
    {
        return;
    }

    sched_yield();
}

static void aeron_idle_strategy_noop_idle(void *state, int work_count)
{
    if (work_count > 0)
    {
        return;
    }

    __asm__ volatile("pause\n": : :"memory");
}

aeron_idle_strategy_func_t aeron_idle_strategy_load(
    const char *idle_strategy_name,
    void **idle_strategy_state)
{
    char idle_func_name[AERON_MAX_PATH];
    aeron_idle_strategy_func_t idle_func = NULL;
    aeron_idle_strategy_init_func_t idle_init_func = NULL;
    void *idle_state = NULL;

    if (NULL == idle_strategy_name || NULL == idle_strategy_state)
    {
        /* TODO: EINVAL */
        return NULL;
    }

    *idle_strategy_state = NULL;

    if (strncmp(idle_strategy_name, "sleeping", sizeof("sleeping")) == 0)<commit_msg>[C]: add basic idle strategies for external loading.<commit_after>/*
 * Copyright 2014 - 2017 Real Logic Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define _GNU_SOURCE

#include <string.h>
#include <stdio.h>
#include <dlfcn.h>
#include <sched.h>
#include "aeron_agent.h"
#include "aeron_alloc.h"
#include "aeron_driver_context.h"

static void aeron_idle_strategy_sleeping_idle(void *state, int work_count)
{
    if (work_count > 0)
    {
        return;
    }

    nanosleep(&(struct timespec){.tv_nsec=1}, NULL);
}

static void aeron_idle_strategy_yielding_idle(void *state, int work_count)
{
    if (work_count > 0)
    {
        return;
    }

    sched_yield();
}

static void aeron_idle_strategy_noop_idle(void *state, int work_count)
{
    if (work_count > 0)
    {
        return;
    }

    __asm__ volatile("pause\n": : :"memory");
}

static int aeron_idle_strategy_init_null(void **state)
{
    *state = NULL;
    return 0;
}

aeron_idle_strategy_t aeron_idle_strategy_sleeping =
    {
        aeron_idle_strategy_sleeping_idle,
        aeron_idle_strategy_init_null
    };

aeron_idle_strategy_t aeron_idle_strategy_yielding =
    {
        aeron_idle_strategy_yielding_idle,
        aeron_idle_strategy_init_null
    };

aeron_idle_strategy_t aeron_idle_strategy_noop =
    {
        aeron_idle_strategy_noop_idle,
        aeron_idle_strategy_init_null
    };

aeron_idle_strategy_func_t aeron_idle_strategy_load(
    const char *idle_strategy_name,
    void **idle_strategy_state)
{
    char idle_func_name[AERON_MAX_PATH];
    aeron_idle_strategy_func_t idle_func = NULL;
    aeron_idle_strategy_init_func_t idle_init_func = NULL;
    void *idle_state = NULL;

    if (NULL == idle_strategy_name || NULL == idle_strategy_state)
    {
        /* TODO: EINVAL */
        return NULL;
    }

    *idle_strategy_state = NULL;

    if (strncmp(idle_strategy_name, "sleeping", sizeof("sleeping")) == 0)
{'fraction_non_alphanumeric': 0.09338612016767582, 'fraction_numerical': 0.008150908244061481, 'mean_word_length': 3.6432432432432433, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4424117', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1491, 'n_words': 370}