Пример #1
0
int
TEST_MAINLOOP_MAIN_FN(int argc, char *argv[])
{
    int err, i;
    struct sol_timeout *timeout_to_del;
    struct sol_idle *idler_to_del;

    err = sol_init();
    ASSERT(!err);

    timeout_to_del = sol_timeout_add(100, timeout_never_called, NULL);
    sol_timeout_add(20, on_timeout_del_and_new, timeout_to_del);

    sol_timeout_add(1, on_timeout_renew_twice, NULL);
    sol_idle_add(on_idler_renew_twice, NULL);

    for (i = 0; i < 5; i++)
        sol_idle_add(on_idler, (void *)(intptr_t)i);

    sol_idle_add(on_idler_del_another, &idler_to_del);
    idler_to_del = sol_idle_add(on_idler_never_called, NULL);

    sol_run();
    ASSERT_INT_EQ(timeout_called, 3);
    ASSERT_INT_EQ(timeout_renewed, 2);
    ASSERT_INT_EQ(idler_renewed, 2);

    for (i = 0; i < 10; i++)
        ASSERT_INT_EQ(idler_sequence[i], i);

    sol_shutdown();

    return 0;
}
static void *
sol_worker_thread_do(void *data)
{
    struct sol_worker_thread_posix *thread = data;
    struct sol_worker_thread_config *config = &thread->config;

    SOL_DBG("worker thread %p started", thread);

    if (config->setup) {
        if (!config->setup((void *)config->data))
            goto end;
    }

    while (!sol_worker_thread_impl_cancel_check(thread)) {
        if (!config->iterate((void *)config->data))
            break;
    }

    if (config->cleanup)
        config->cleanup((void *)config->data);

end:
    if (sol_worker_thread_lock(thread)) {
        if (thread->idler)
            sol_idle_del(thread->idler);
        thread->idler = sol_idle_add(sol_worker_thread_finished, thread);
        sol_worker_thread_unlock(thread);
    }

    SOL_DBG("worker thread %p stopped", thread);

    return thread;
}
static gpointer
sol_worker_thread_do(gpointer data)
{
    struct sol_worker_thread_glib *thread = data;
    struct sol_worker_thread_config *config = &thread->config;

    SOL_DBG("worker thread %p started", thread);

    if (config->setup) {
        if (!config->setup((void *)config->data))
            goto end;
    }

    while (!sol_worker_thread_impl_cancel_check(thread)) {
        if (!config->iterate((void *)config->data))
            break;
    }

    if (config->cleanup)
        config->cleanup((void *)config->data);

end:
    g_mutex_lock(&thread->lock);
    if (thread->idler)
        sol_idle_del(thread->idler);
    thread->idler = sol_idle_add(sol_worker_thread_finished, thread);
    g_mutex_unlock(&thread->lock);

    SOL_DBG("worker thread %p stopped", thread);

    return thread;
}
Пример #4
0
static bool
on_idler(void *data)
{
    int i = (intptr_t)data;

    idler_sequence[i] = i;

    if (i < 5)
        sol_idle_add(on_idler, (void *)(intptr_t)(i + 5));

    return false;
}
int
main(int argc, char *argv[])
{
    int err;

    err = sol_init();
    ASSERT(!err);

    sol_idle_add(perform_tests, NULL);

    sol_run();

    sol_shutdown();

    return 0;
}
Пример #6
0
static int
file_reader_open(struct sol_flow_node *node, void *data, const struct sol_flow_node_options *options)
{
    const struct sol_flow_node_type_file_reader_options *opts = (const struct sol_flow_node_type_file_reader_options *)options;
    struct file_reader_data *mdata = data;

    mdata->node = node;

    SOL_FLOW_NODE_OPTIONS_SUB_API_CHECK(options, SOL_FLOW_NODE_TYPE_FILE_READER_OPTIONS_API_VERSION, -EINVAL);

    if (opts->path) {
        mdata->path = strdup(opts->path);
        SOL_NULL_CHECK(mdata->path, -ENOMEM);
    }

    mdata->idler = sol_idle_add(file_reader_open_delayed, mdata);
    return 0;
}
void
sol_worker_thread_impl_feedback(void *handle)
{
    struct sol_worker_thread_posix *thread = handle;

    SOL_NULL_CHECK(thread);
    SOL_NULL_CHECK(thread->config.feedback);

    if (sol_worker_thread_impl_cancel_check(thread)) {
        SOL_WRN("worker thread %p is not running.", thread);
        return;
    }
    if (thread->thread != pthread_self()) {
        SOL_WRN("trying to feedback from different worker thread %p.", thread);
        return;
    }
    if (sol_worker_thread_lock(thread)) {
        if (!thread->idler)
            thread->idler = sol_idle_add(sol_worker_thread_feedback_dispatch, thread);
        sol_worker_thread_unlock(thread);
    }
}
Пример #8
0
int
main(int argc, char *argv[])
{
    int r;

    if (!parse_args(argc, argv)) {
        usage(argv[0]);
        return EXIT_FAILURE;
    }

    if (sol_init() < 0) {
        SOL_CRI("Cannot initialize soletta.");
        return EXIT_FAILURE;
    }

    sol_idle_add(startup, NULL);

    r = sol_run();

    shutdown();
    sol_shutdown();

    return r;
}