1b7d596c1SMatthias Ringwald /* 2b7d596c1SMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH 3b7d596c1SMatthias Ringwald * 4b7d596c1SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 5b7d596c1SMatthias Ringwald * modification, are permitted provided that the following conditions 6b7d596c1SMatthias Ringwald * are met: 7b7d596c1SMatthias Ringwald * 8b7d596c1SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 9b7d596c1SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 10b7d596c1SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 11b7d596c1SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 12b7d596c1SMatthias Ringwald * documentation and/or other materials provided with the distribution. 13b7d596c1SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 14b7d596c1SMatthias Ringwald * contributors may be used to endorse or promote products derived 15b7d596c1SMatthias Ringwald * from this software without specific prior written permission. 16b7d596c1SMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 17b7d596c1SMatthias Ringwald * personal benefit and not for any commercial purpose or for 18b7d596c1SMatthias Ringwald * monetary gain. 19b7d596c1SMatthias Ringwald * 20b7d596c1SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21b7d596c1SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22b7d596c1SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23b7d596c1SMatthias Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24b7d596c1SMatthias Ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25b7d596c1SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26b7d596c1SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27b7d596c1SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28b7d596c1SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29b7d596c1SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30b7d596c1SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31b7d596c1SMatthias Ringwald * SUCH DAMAGE. 32b7d596c1SMatthias Ringwald * 33b7d596c1SMatthias Ringwald * Please inquire about commercial licensing options at 34b7d596c1SMatthias Ringwald * [email protected] 35b7d596c1SMatthias Ringwald * 36b7d596c1SMatthias Ringwald */ 37b7d596c1SMatthias Ringwald 38e501bae0SMatthias Ringwald #define BTSTACK_FILE__ "btstack_run_loop_posix.c" 39ab2c6ae4SMatthias Ringwald 40b7d596c1SMatthias Ringwald /* 414ab92137SMatthias Ringwald * btstack_run_loop.c 42b7d596c1SMatthias Ringwald * 43b7d596c1SMatthias Ringwald * Created by Matthias Ringwald on 6/6/09. 44b7d596c1SMatthias Ringwald */ 45b7d596c1SMatthias Ringwald 4692b78dd7SMatthias Ringwald // enable POSIX functions (needed for -std=c99) 4792b78dd7SMatthias Ringwald #define _POSIX_C_SOURCE 200809 4892b78dd7SMatthias Ringwald 498f2a52f4SMatthias Ringwald #include "btstack_run_loop_posix.h" 50b6fc147fSMatthias Ringwald 51b6fc147fSMatthias Ringwald #include "btstack_run_loop.h" 52b6fc147fSMatthias Ringwald #include "btstack_util.h" 53b7d596c1SMatthias Ringwald #include "btstack_linked_list.h" 54b7d596c1SMatthias Ringwald #include "btstack_debug.h" 55b7d596c1SMatthias Ringwald 56b7d596c1SMatthias Ringwald #include <stdio.h> 57b7d596c1SMatthias Ringwald #include <stdlib.h> 58b6fc147fSMatthias Ringwald #include <sys/select.h> 59f316a845SMatthias Ringwald #include <sys/time.h> 6092b78dd7SMatthias Ringwald #include <time.h> 6192b78dd7SMatthias Ringwald #include <unistd.h> 62*41158b74SMatthias Ringwald #include <pthread.h> 63b7d596c1SMatthias Ringwald 64b7d596c1SMatthias Ringwald // the run loop 65b7d596c1SMatthias Ringwald static int data_sources_modified; 6692b78dd7SMatthias Ringwald 672e357f7aSMatthias Ringwald static bool run_loop_exit_requested; 682e357f7aSMatthias Ringwald 69*41158b74SMatthias Ringwald // to trigger run loop from other thread 70*41158b74SMatthias Ringwald static int run_loop_pipe_fd; 71*41158b74SMatthias Ringwald static btstack_data_source_t run_loop_pipe_ds; 72*41158b74SMatthias Ringwald static pthread_mutex_t run_loop_callback_mutex = PTHREAD_MUTEX_INITIALIZER; 73*41158b74SMatthias Ringwald 7492b78dd7SMatthias Ringwald // start time. tv_usec/tv_nsec = 0 7592b78dd7SMatthias Ringwald #ifdef _POSIX_MONOTONIC_CLOCK 7692b78dd7SMatthias Ringwald // use monotonic clock if available 7792b78dd7SMatthias Ringwald static struct timespec init_ts; 7892b78dd7SMatthias Ringwald #else 7992b78dd7SMatthias Ringwald // fallback to gettimeofday 80b7d596c1SMatthias Ringwald static struct timeval init_tv; 8192b78dd7SMatthias Ringwald #endif 82b7d596c1SMatthias Ringwald 83b7d596c1SMatthias Ringwald /** 84b7d596c1SMatthias Ringwald * Add data_source to run_loop 85b7d596c1SMatthias Ringwald */ 86ec820d77SMatthias Ringwald static void btstack_run_loop_posix_add_data_source(btstack_data_source_t *ds){ 87b7d596c1SMatthias Ringwald data_sources_modified = 1; 88075edf12SMatthias Ringwald btstack_run_loop_base_add_data_source(ds); 89b7d596c1SMatthias Ringwald } 90b7d596c1SMatthias Ringwald 91b7d596c1SMatthias Ringwald /** 92b7d596c1SMatthias Ringwald * Remove data_source from run loop 93b7d596c1SMatthias Ringwald */ 94d58a1b5fSMatthias Ringwald static bool btstack_run_loop_posix_remove_data_source(btstack_data_source_t *ds){ 95b7d596c1SMatthias Ringwald data_sources_modified = 1; 96075edf12SMatthias Ringwald return btstack_run_loop_base_remove_data_source(ds); 979120e843SMatthias Ringwald } 989120e843SMatthias Ringwald 9992b78dd7SMatthias Ringwald #ifdef _POSIX_MONOTONIC_CLOCK 10092b78dd7SMatthias Ringwald /** 10192b78dd7SMatthias Ringwald * @brief Returns the timespec which represents the time(stop - start). It might be negative 10292b78dd7SMatthias Ringwald */ 10392b78dd7SMatthias Ringwald static void timespec_diff(struct timespec *start, struct timespec *stop, struct timespec *result){ 10492b78dd7SMatthias Ringwald result->tv_sec = stop->tv_sec - start->tv_sec; 10592b78dd7SMatthias Ringwald if ((stop->tv_nsec - start->tv_nsec) < 0) { 10692b78dd7SMatthias Ringwald result->tv_sec = stop->tv_sec - start->tv_sec - 1; 10792b78dd7SMatthias Ringwald result->tv_nsec = stop->tv_nsec - start->tv_nsec + 1000000000; 10892b78dd7SMatthias Ringwald } else { 10992b78dd7SMatthias Ringwald result->tv_sec = stop->tv_sec - start->tv_sec; 11092b78dd7SMatthias Ringwald result->tv_nsec = stop->tv_nsec - start->tv_nsec; 11192b78dd7SMatthias Ringwald } 11292b78dd7SMatthias Ringwald } 11392b78dd7SMatthias Ringwald 11492b78dd7SMatthias Ringwald /** 11592b78dd7SMatthias Ringwald * @brief Convert timespec to miliseconds, might overflow 11692b78dd7SMatthias Ringwald */ 11792b78dd7SMatthias Ringwald static uint64_t timespec_to_milliseconds(struct timespec *a){ 11892b78dd7SMatthias Ringwald uint64_t ret = 0; 11992b78dd7SMatthias Ringwald uint64_t sec_val = (uint64_t)(a->tv_sec); 12092b78dd7SMatthias Ringwald uint64_t nsec_val = (uint64_t)(a->tv_nsec); 12192b78dd7SMatthias Ringwald ret = (sec_val*1000) + (nsec_val/1000000); 12292b78dd7SMatthias Ringwald return ret; 12392b78dd7SMatthias Ringwald } 12492b78dd7SMatthias Ringwald 12592b78dd7SMatthias Ringwald /** 12692b78dd7SMatthias Ringwald * @brief Returns the milisecond value of (stop - start). Might overflow 12792b78dd7SMatthias Ringwald */ 12892b78dd7SMatthias Ringwald static uint64_t timespec_diff_milis(struct timespec* start, struct timespec* stop){ 12992b78dd7SMatthias Ringwald struct timespec diff_ts; 13092b78dd7SMatthias Ringwald timespec_diff(start, stop, &diff_ts); 13192b78dd7SMatthias Ringwald return timespec_to_milliseconds(&diff_ts); 13292b78dd7SMatthias Ringwald } 13392b78dd7SMatthias Ringwald #endif 13492b78dd7SMatthias Ringwald 135b7d596c1SMatthias Ringwald /** 136f316a845SMatthias Ringwald * @brief Queries the current time in ms since start 137f316a845SMatthias Ringwald */ 138f316a845SMatthias Ringwald static uint32_t btstack_run_loop_posix_get_time_ms(void){ 13992b78dd7SMatthias Ringwald uint32_t time_ms; 14092b78dd7SMatthias Ringwald #ifdef _POSIX_MONOTONIC_CLOCK 14192b78dd7SMatthias Ringwald struct timespec now_ts; 14292b78dd7SMatthias Ringwald clock_gettime(CLOCK_MONOTONIC, &now_ts); 14392b78dd7SMatthias Ringwald time_ms = (uint32_t) timespec_diff_milis(&init_ts, &now_ts); 14492b78dd7SMatthias Ringwald #else 145f316a845SMatthias Ringwald struct timeval tv; 146f316a845SMatthias Ringwald gettimeofday(&tv, NULL); 14792b78dd7SMatthias Ringwald time_ms = (uint32_t) ((tv.tv_sec - init_tv.tv_sec) * 1000) + (tv.tv_usec / 1000); 14892b78dd7SMatthias Ringwald #endif 149f316a845SMatthias Ringwald return time_ms; 150f316a845SMatthias Ringwald } 151f316a845SMatthias Ringwald 152f316a845SMatthias Ringwald /** 153b7d596c1SMatthias Ringwald * Execute run_loop 154b7d596c1SMatthias Ringwald */ 155528a4a3bSMatthias Ringwald static void btstack_run_loop_posix_execute(void) { 1569120e843SMatthias Ringwald fd_set descriptors_read; 1579120e843SMatthias Ringwald fd_set descriptors_write; 158b7d596c1SMatthias Ringwald 159b7d596c1SMatthias Ringwald btstack_linked_list_iterator_t it; 160f316a845SMatthias Ringwald struct timeval * timeout; 161f316a845SMatthias Ringwald struct timeval tv; 162f316a845SMatthias Ringwald uint32_t now_ms; 163b7d596c1SMatthias Ringwald 16492b78dd7SMatthias Ringwald #ifdef _POSIX_MONOTONIC_CLOCK 16592b78dd7SMatthias Ringwald log_info("POSIX run loop with monotonic clock"); 16692b78dd7SMatthias Ringwald #else 16792b78dd7SMatthias Ringwald log_info("POSIX run loop using ettimeofday fallback."); 16892b78dd7SMatthias Ringwald #endif 16992b78dd7SMatthias Ringwald 1702e357f7aSMatthias Ringwald while (run_loop_exit_requested == false) { 171b7d596c1SMatthias Ringwald // collect FDs 1729120e843SMatthias Ringwald FD_ZERO(&descriptors_read); 1739120e843SMatthias Ringwald FD_ZERO(&descriptors_write); 174f316a845SMatthias Ringwald int highest_fd = -1; 175075edf12SMatthias Ringwald btstack_linked_list_iterator_init(&it, &btstack_run_loop_base_data_sources); 176b7d596c1SMatthias Ringwald while (btstack_linked_list_iterator_has_next(&it)){ 177ec820d77SMatthias Ringwald btstack_data_source_t *ds = (btstack_data_source_t*) btstack_linked_list_iterator_next(&it); 178398a95ecSMatthias Ringwald if (ds->source.fd < 0) continue; 1799120e843SMatthias Ringwald if (ds->flags & DATA_SOURCE_CALLBACK_READ){ 180398a95ecSMatthias Ringwald FD_SET(ds->source.fd, &descriptors_read); 181398a95ecSMatthias Ringwald if (ds->source.fd > highest_fd) { 182398a95ecSMatthias Ringwald highest_fd = ds->source.fd; 1839120e843SMatthias Ringwald } 184398a95ecSMatthias Ringwald log_debug("btstack_run_loop_execute adding fd %u for read", ds->source.fd); 1859120e843SMatthias Ringwald } 1869120e843SMatthias Ringwald if (ds->flags & DATA_SOURCE_CALLBACK_WRITE){ 187398a95ecSMatthias Ringwald FD_SET(ds->source.fd, &descriptors_write); 188398a95ecSMatthias Ringwald if (ds->source.fd > highest_fd) { 189398a95ecSMatthias Ringwald highest_fd = ds->source.fd; 190b7d596c1SMatthias Ringwald } 191398a95ecSMatthias Ringwald log_debug("btstack_run_loop_execute adding fd %u for write", ds->source.fd); 192b7d596c1SMatthias Ringwald } 193b7d596c1SMatthias Ringwald } 194b7d596c1SMatthias Ringwald 195b7d596c1SMatthias Ringwald // get next timeout 196b7d596c1SMatthias Ringwald timeout = NULL; 197f316a845SMatthias Ringwald now_ms = btstack_run_loop_posix_get_time_ms(); 198075edf12SMatthias Ringwald int32_t delta_ms = btstack_run_loop_base_get_time_until_timeout(now_ms); 199075edf12SMatthias Ringwald if (delta_ms >= 0) { 200075edf12SMatthias Ringwald timeout = &tv; 201075edf12SMatthias Ringwald tv.tv_sec = delta_ms / 1000; 202075edf12SMatthias Ringwald tv.tv_usec = (int) (delta_ms - (tv.tv_sec * 1000)) * 1000; 203075edf12SMatthias Ringwald log_debug("btstack_run_loop_execute next timeout in %u ms", delta_ms); 204b7d596c1SMatthias Ringwald } 205b7d596c1SMatthias Ringwald 206b7d596c1SMatthias Ringwald // wait for ready FDs 2079120e843SMatthias Ringwald select( highest_fd+1 , &descriptors_read, &descriptors_write, NULL, timeout); 208b7d596c1SMatthias Ringwald 209b7d596c1SMatthias Ringwald data_sources_modified = 0; 210075edf12SMatthias Ringwald btstack_linked_list_iterator_init(&it, &btstack_run_loop_base_data_sources); 211b7d596c1SMatthias Ringwald while (btstack_linked_list_iterator_has_next(&it) && !data_sources_modified){ 212ec820d77SMatthias Ringwald btstack_data_source_t *ds = (btstack_data_source_t*) btstack_linked_list_iterator_next(&it); 213398a95ecSMatthias Ringwald log_debug("btstack_run_loop_posix_execute: check ds %p with fd %u\n", ds, ds->source.fd); 214398a95ecSMatthias Ringwald if (FD_ISSET(ds->source.fd, &descriptors_read)) { 215398a95ecSMatthias Ringwald log_debug("btstack_run_loop_posix_execute: process read ds %p with fd %u\n", ds, ds->source.fd); 2167cd5ef95SMatthias Ringwald ds->process(ds, DATA_SOURCE_CALLBACK_READ); 217b7d596c1SMatthias Ringwald } 2184b7565a2SMatthias Ringwald if (data_sources_modified) break; 219398a95ecSMatthias Ringwald if (FD_ISSET(ds->source.fd, &descriptors_write)) { 220398a95ecSMatthias Ringwald log_debug("btstack_run_loop_posix_execute: process write ds %p with fd %u\n", ds, ds->source.fd); 2219120e843SMatthias Ringwald ds->process(ds, DATA_SOURCE_CALLBACK_WRITE); 2229120e843SMatthias Ringwald } 223b7d596c1SMatthias Ringwald } 224f316a845SMatthias Ringwald log_debug("btstack_run_loop_posix_execute: after ds check\n"); 225b7d596c1SMatthias Ringwald 226b7d596c1SMatthias Ringwald // process timers 22788e0b3b2SMatthias Ringwald now_ms = btstack_run_loop_posix_get_time_ms(); 228075edf12SMatthias Ringwald btstack_run_loop_base_process_timers(now_ms); 229b7d596c1SMatthias Ringwald } 230b7d596c1SMatthias Ringwald } 231b7d596c1SMatthias Ringwald 2322e357f7aSMatthias Ringwald static void btstack_run_loop_posix_trigger_exit(void){ 2332e357f7aSMatthias Ringwald run_loop_exit_requested = true; 2342e357f7aSMatthias Ringwald } 2352e357f7aSMatthias Ringwald 236b7d596c1SMatthias Ringwald // set timer 237ec820d77SMatthias Ringwald static void btstack_run_loop_posix_set_timer(btstack_timer_source_t *a, uint32_t timeout_in_ms){ 238f316a845SMatthias Ringwald uint32_t time_ms = btstack_run_loop_posix_get_time_ms(); 239f316a845SMatthias Ringwald a->timeout = time_ms + timeout_in_ms; 240615ae444SMatthias Ringwald log_debug("btstack_run_loop_posix_set_timer to %u ms (now %u, timeout %u)", a->timeout, time_ms, timeout_in_ms); 241b7d596c1SMatthias Ringwald } 242b7d596c1SMatthias Ringwald 243*41158b74SMatthias Ringwald static void btstack_run_loop_posix_pipe_process(btstack_data_source_t * ds, btstack_data_source_callback_type_t callback_type){ 244*41158b74SMatthias Ringwald UNUSED(callback_type); 245*41158b74SMatthias Ringwald log_info("btstack_run_loop_posix_pipe_process"); 246*41158b74SMatthias Ringwald uint8_t buffer[1]; 247*41158b74SMatthias Ringwald (void) read(ds->source.fd, buffer, 1); 248*41158b74SMatthias Ringwald // execute callbacks - protect list with mutex 249*41158b74SMatthias Ringwald while (1){ 250*41158b74SMatthias Ringwald pthread_mutex_lock(&run_loop_callback_mutex); 251*41158b74SMatthias Ringwald btstack_context_callback_registration_t * callback_registration = (btstack_context_callback_registration_t *) btstack_linked_list_pop(&btstack_run_loop_base_callbacks); 252*41158b74SMatthias Ringwald pthread_mutex_unlock(&run_loop_callback_mutex); 253*41158b74SMatthias Ringwald if (callback_registration == NULL){ 254*41158b74SMatthias Ringwald break; 255*41158b74SMatthias Ringwald } 256*41158b74SMatthias Ringwald (*callback_registration->callback)(callback_registration->context); 257*41158b74SMatthias Ringwald } 258*41158b74SMatthias Ringwald } 259*41158b74SMatthias Ringwald 260*41158b74SMatthias Ringwald static void btstack_run_loop_posix_execute_on_main_thread(btstack_context_callback_registration_t * callback_registration){ 261*41158b74SMatthias Ringwald // protect list with mutex 262*41158b74SMatthias Ringwald pthread_mutex_lock(&run_loop_callback_mutex); 263*41158b74SMatthias Ringwald btstack_run_loop_base_add_callback(callback_registration); 264*41158b74SMatthias Ringwald pthread_mutex_unlock(&run_loop_callback_mutex); 265*41158b74SMatthias Ringwald // trigger run loop 266*41158b74SMatthias Ringwald if (run_loop_pipe_fd >= 0){ 267*41158b74SMatthias Ringwald const uint8_t x = (uint8_t) 'x'; 268*41158b74SMatthias Ringwald (void) write(run_loop_pipe_fd, &x, 1); 269*41158b74SMatthias Ringwald } 270*41158b74SMatthias Ringwald } 271*41158b74SMatthias Ringwald 272528a4a3bSMatthias Ringwald static void btstack_run_loop_posix_init(void){ 273075edf12SMatthias Ringwald btstack_run_loop_base_init(); 274075edf12SMatthias Ringwald 27592b78dd7SMatthias Ringwald #ifdef _POSIX_MONOTONIC_CLOCK 27692b78dd7SMatthias Ringwald clock_gettime(CLOCK_MONOTONIC, &init_ts); 27792b78dd7SMatthias Ringwald init_ts.tv_nsec = 0; 27892b78dd7SMatthias Ringwald #else 279f316a845SMatthias Ringwald // just assume that we started at tv_usec == 0 280b7d596c1SMatthias Ringwald gettimeofday(&init_tv, NULL); 281f316a845SMatthias Ringwald init_tv.tv_usec = 0; 28292b78dd7SMatthias Ringwald #endif 283b7d596c1SMatthias Ringwald 284*41158b74SMatthias Ringwald // create pipe and register as data source 285*41158b74SMatthias Ringwald int fildes[2]; 286*41158b74SMatthias Ringwald int status = pipe(fildes); 287*41158b74SMatthias Ringwald if (status == 0 ) { 288*41158b74SMatthias Ringwald run_loop_pipe_fd = fildes[1]; 289*41158b74SMatthias Ringwald run_loop_pipe_ds.source.fd = fildes[0]; 290*41158b74SMatthias Ringwald run_loop_pipe_ds.flags = DATA_SOURCE_CALLBACK_READ; 291*41158b74SMatthias Ringwald run_loop_pipe_ds.process = &btstack_run_loop_posix_pipe_process; 292*41158b74SMatthias Ringwald btstack_run_loop_base_add_data_source(&run_loop_pipe_ds); 293*41158b74SMatthias Ringwald log_info("Pipe in %u, out %u", run_loop_pipe_fd, fildes[0]); 294*41158b74SMatthias Ringwald } else { 295*41158b74SMatthias Ringwald run_loop_pipe_fd = -1; 296*41158b74SMatthias Ringwald log_error("pipe() failed"); 297*41158b74SMatthias Ringwald } 298*41158b74SMatthias Ringwald } 299b7d596c1SMatthias Ringwald 300528a4a3bSMatthias Ringwald static const btstack_run_loop_t btstack_run_loop_posix = { 301528a4a3bSMatthias Ringwald &btstack_run_loop_posix_init, 302528a4a3bSMatthias Ringwald &btstack_run_loop_posix_add_data_source, 303528a4a3bSMatthias Ringwald &btstack_run_loop_posix_remove_data_source, 304075edf12SMatthias Ringwald &btstack_run_loop_base_enable_data_source_callbacks, 305075edf12SMatthias Ringwald &btstack_run_loop_base_disable_data_source_callbacks, 306528a4a3bSMatthias Ringwald &btstack_run_loop_posix_set_timer, 307075edf12SMatthias Ringwald &btstack_run_loop_base_add_timer, 308075edf12SMatthias Ringwald &btstack_run_loop_base_remove_timer, 309528a4a3bSMatthias Ringwald &btstack_run_loop_posix_execute, 310075edf12SMatthias Ringwald &btstack_run_loop_base_dump_timer, 311528a4a3bSMatthias Ringwald &btstack_run_loop_posix_get_time_ms, 3122e357f7aSMatthias Ringwald NULL, /* poll data sources from irq */ 313*41158b74SMatthias Ringwald btstack_run_loop_posix_execute_on_main_thread, 3142e357f7aSMatthias Ringwald &btstack_run_loop_posix_trigger_exit, 315b7d596c1SMatthias Ringwald }; 316b7d596c1SMatthias Ringwald 317b7d596c1SMatthias Ringwald /** 318528a4a3bSMatthias Ringwald * Provide btstack_run_loop_posix instance 319b7d596c1SMatthias Ringwald */ 320528a4a3bSMatthias Ringwald const btstack_run_loop_t * btstack_run_loop_posix_get_instance(void){ 321528a4a3bSMatthias Ringwald return &btstack_run_loop_posix; 322b7d596c1SMatthias Ringwald } 323b7d596c1SMatthias Ringwald 324