|
OpenTTD Source 20260324-master-gd9c35037d4
|
Converts a HTTPCallback to a Thread-Safe variant. More...
#include <http_shared.h>
Data Structures | |
| class | Callback |
| Entries on the queue for later handling. More... | |
Public Member Functions | |
| void | OnFailure () |
| Similar to HTTPCallback::OnFailure, but thread-safe. | |
| void | OnReceiveData (std::unique_ptr< char[]> data, size_t length) |
| Similar to HTTPCallback::OnReceiveData, but thread-safe. | |
| void | HandleQueue () |
| Process everything on the queue. | |
| template<typename T> | |
| void | WaitTillEmptyOrCondition (T condition) |
| Wait till the queue is dequeued, or a condition is met. | |
| bool | IsQueueEmpty () |
| Check if the queue is empty. | |
| HTTPThreadSafeCallback (HTTPCallback *callback) | |
| Create the thread safe callback. | |
| ~HTTPThreadSafeCallback () | |
| Ensure our queues are emptied while holding a lock. | |
Data Fields | |
| std::atomic< bool > | cancelled = false |
| Whether this callback has been cancelled, or not. | |
Private Attributes | |
| HTTPCallback * | callback |
| The callback to send data back on. | |
| std::mutex | mutex |
| Mutex to protect the queue. | |
| std::vector< Callback > | queue |
| Queue of data to send back. | |
| std::condition_variable | queue_cv |
| Condition variable to wait for the queue to be empty. | |
Converts a HTTPCallback to a Thread-Safe variant.
Definition at line 20 of file http_shared.h.
|
inline |
Create the thread safe callback.
| callback | The underlying callback to call. |
Definition at line 110 of file http_shared.h.
References callback.
|
inline |
|
inline |
|
inline |
Check if the queue is empty.
true iff the queue is empty. Definition at line 100 of file http_shared.h.
|
inline |
Similar to HTTPCallback::OnFailure, but thread-safe.
Definition at line 43 of file http_shared.h.
|
inline |
Similar to HTTPCallback::OnReceiveData, but thread-safe.
We're receiving data.
| data | the received data, nullptr when all data has been received. |
| length | the amount of received data, 0 when all data has been received. |
Definition at line 53 of file http_shared.h.
References lock, mutex, and queue.
Referenced by HttpThread().
|
private |
The callback to send data back on.
Definition at line 125 of file http_shared.h.
Referenced by HandleQueue(), and HTTPThreadSafeCallback().
| std::atomic<bool> HTTPThreadSafeCallback::cancelled = false |
Whether this callback has been cancelled, or not.
Definition at line 122 of file http_shared.h.
Referenced by HandleQueue(), and HttpThread().
|
private |
Mutex to protect the queue.
Definition at line 126 of file http_shared.h.
Referenced by HandleQueue(), IsQueueEmpty(), OnFailure(), OnReceiveData(), WaitTillEmptyOrCondition(), and ~HTTPThreadSafeCallback().
|
private |
Queue of data to send back.
Definition at line 127 of file http_shared.h.
Referenced by HandleQueue(), IsQueueEmpty(), OnFailure(), OnReceiveData(), WaitTillEmptyOrCondition(), and ~HTTPThreadSafeCallback().
|
private |
Condition variable to wait for the queue to be empty.
Definition at line 128 of file http_shared.h.
Referenced by HandleQueue(), WaitTillEmptyOrCondition(), and ~HTTPThreadSafeCallback().