<commit_before>/*
 * Copyright © 2014-2018  <NAME>
 *
 * This file is part of "apulse" project.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#define _XOPEN_SOURCE 500
#include "apulse.h"
#include "trace.h"
#include <assert.h>
#include <unistd.h>

static int
from_pa_io_event_flags(pa_io_event_flags_t flags)
{
    return ((flags & PA_IO_EVENT_INPUT) ? POLLIN : 0) |
           ((flags & PA_IO_EVENT_OUTPUT) ? POLLOUT : 0) |
           ((flags & PA_IO_EVENT_HANGUP) ? POLLHUP : 0) |
           ((flags & PA_IO_EVENT_ERROR) ? POLLERR : 0);
}

static pa_io_event_flags_t
to_pa_io_event_flags(int flags)
{
    return ((flags & POLLIN) ? PA_IO_EVENT_INPUT : 0) |
           ((flags & POLLOUT) ? PA_IO_EVENT_OUTPUT : 0) |
           ((flags & POLLHUP) ? PA_IO_EVENT_HANGUP : 0) |
           ((flags & POLLERR) ? PA_IO_EVENT_ERROR : 0);
}

static void
ml_api_defer_enable(pa_defer_event *e, int b)
{
    trace_info_f("F %s\n", __func__);

    e->enabled = b;
}

static void
ml_api_defer_free(pa_defer_event *e)
{
    trace_info_f("F %s\n", __func__);

    pa_mainloop *ml = e->mainloop;
    g_queue_remove(ml->deferred_events_queue, e);
    g_slice_free(pa_defer_event, e);
    pa_mainloop_wakeup(ml);
}

static pa_defer_event *
ml_api_defer_new(pa_mainloop_api *a, pa_defer_event_cb_t cb, void *userdata)
{
    trace_info_f("F %s\n", __func__);

    pa_mainloop *ml = a->userdata;
    pa_defer_event *de = g_slice_new0(pa_defer_event);
    de->enabled = 1;
    de->cb = cb;
    de->userdata = userdata;
    de->mainloop = ml;
    g_queue_push_tail(ml->deferred_events_queue, de);

    pa_mainloop_wakeup(ml);
    return de;
}

static void
ml_api_defer_set_destroy(pa_defer_event *e, pa_defer_event_destroy_cb_t cb)
{
    trace_info_z("Z %s\n", __func__);
}

static void
ml_api_io_enable(pa_io_event *e, pa_io_event_flags_t events)
{
    trace_info_f("F %s e=%p, events=0x%x\n", __func__, e, events);
<commit_msg>mainloop: stop waking mainloop on defer_new<commit_after>/*
 * Copyright © 2014-2018  <NAME>
 *
 * This file is part of "apulse" project.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#define _XOPEN_SOURCE 500
#include "apulse.h"
#include "trace.h"
#include <assert.h>
#include <unistd.h>

static int
from_pa_io_event_flags(pa_io_event_flags_t flags)
{
    return ((flags & PA_IO_EVENT_INPUT) ? POLLIN : 0) |
           ((flags & PA_IO_EVENT_OUTPUT) ? POLLOUT : 0) |
           ((flags & PA_IO_EVENT_HANGUP) ? POLLHUP : 0) |
           ((flags & PA_IO_EVENT_ERROR) ? POLLERR : 0);
}

static pa_io_event_flags_t
to_pa_io_event_flags(int flags)
{
    return ((flags & POLLIN) ? PA_IO_EVENT_INPUT : 0) |
           ((flags & POLLOUT) ? PA_IO_EVENT_OUTPUT : 0) |
           ((flags & POLLHUP) ? PA_IO_EVENT_HANGUP : 0) |
           ((flags & POLLERR) ? PA_IO_EVENT_ERROR : 0);
}

static void
ml_api_defer_enable(pa_defer_event *e, int b)
{
    trace_info_f("F %s\n", __func__);

    e->enabled = b;
}

static void
ml_api_defer_free(pa_defer_event *e)
{
    trace_info_f("F %s\n", __func__);

    pa_mainloop *ml = e->mainloop;
    g_queue_remove(ml->deferred_events_queue, e);
    g_slice_free(pa_defer_event, e);
    pa_mainloop_wakeup(ml);
}

static pa_defer_event *
ml_api_defer_new(pa_mainloop_api *a, pa_defer_event_cb_t cb, void *userdata)
{
    trace_info_f("F %s\n", __func__);

    pa_mainloop *ml = a->userdata;
    pa_defer_event *de = g_slice_new0(pa_defer_event);
    de->enabled = 1;
    de->cb = cb;
    de->userdata = userdata;
    de->mainloop = ml;
    g_queue_push_tail(ml->deferred_events_queue, de);

    return de;
}

static void
ml_api_defer_set_destroy(pa_defer_event *e, pa_defer_event_destroy_cb_t cb)
{
    trace_info_z("Z %s\n", __func__);
}

static void
ml_api_io_enable(pa_io_event *e, pa_io_event_flags_t events)
{
    trace_info_f("F %s e=%p, events=0x%x\n", __func__, e, events);

{'fraction_non_alphanumeric': 0.09925220938137322, 'fraction_numerical': 0.007477906186267845, 'mean_word_length': 3.983065198983912, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2719951', 'n_tokens_mistral': 2103, 'n_tokens_neox': 2021, 'n_words': 614}