1 /*
2  * Copyright (c) 2022 Raspberry Pi (Trading) Ltd.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef _PICO_ASYNC_CONTEXT_POLL_H
8 #define _PICO_ASYNC_CONTEXT_POLL_H
9 
10 /** \file pico/async_context.h
11  *  \defgroup async_context_poll async_context_poll
12  *  \ingroup pico_async_context
13  *
14  * \brief async_context_poll provides an implementation of \ref async_context that is intended for use with a simple
15  * polling loop on one core. It is not thread safe.
16  *
17  * The \ref async_context_poll() method must be called periodically to handle asynchronous work that may now be
18  * pending. \ref async_context_wait_for_work_until() may be used to block a polling loop until there is work to do,
19  * and prevent tight spinning.
20  */
21 #include "pico/async_context.h"
22 #include "pico/sem.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 typedef struct async_context_poll {
29     async_context_t core;
30     semaphore_t sem;
31 } async_context_poll_t;
32 
33 /*!
34  * \brief Initialize an async_context_poll instance with default values
35  * \ingroup async_context_poll
36  *
37  * If this method succeeds (returns true), then the async_context is available for use
38  * and can be de-initialized by calling async_context_deinit().
39  *
40  * \param self a pointer to async_context_poll structure to initialize
41  * \return true if initialization is successful, false otherwise
42  */
43 bool async_context_poll_init_with_defaults(async_context_poll_t *self);
44 
45 #ifdef __cplusplus
46 }
47 #endif
48 
49 #endif