gstthreadshare/runtime/executor/mod.rs
1// Copyright (C) 2018-2020 Sebastian Dröge <sebastian@centricular.com>
2// Copyright (C) 2019-2021 François Laignel <fengalin@free.fr>
3//
4// This Source Code Form is subject to the terms of the Mozilla Public License, v2.0.
5// If a copy of the MPL was not distributed with this file, You can obtain one at
6// <https://mozilla.org/MPL/2.0/>.
7//
8// SPDX-License-Identifier: MPL-2.0
9
10//! The `Executor` for the `threadshare` GStreamer plugins framework.
11//!
12//! The [`threadshare`]'s `Executor` consists in a set of [`Context`]s. Each [`Context`] is
13//! identified by a `name` and runs a loop in a dedicated `thread`. Users can use the [`Context`]
14//! to spawn `Future`s. `Future`s are asynchronous processings which allow waiting for resources
15//! in a non-blocking way. Examples of non-blocking operations are:
16//!
17//! * Waiting for an incoming packet on a Socket.
18//! * Waiting for an asynchronous `Mutex` `lock` to succeed.
19//! * Waiting for a time related `Future`.
20//!
21//! `Element` implementations should use [`PadSrc`] & [`PadSink`] which provides high-level features.
22//!
23//! [`threadshare`]: ../../index.html
24//! [`PadSrc`]: ../pad/struct.PadSrc.html
25//! [`PadSink`]: ../pad/struct.PadSink.html
26
27pub mod async_wrapper;
28pub use async_wrapper::Async;
29
30mod context;
31pub use context::{Context, block_on, block_on_or_add_subtask, yield_now};
32
33mod join;
34pub use join::JoinHandle;
35
36pub mod reactor;
37use reactor::{Reactor, Readable, ReadableOwned, Registration, Source, Writable, WritableOwned};
38
39// We need the `Mutex<bool>` to work in pair with `Condvar`.
40#[allow(clippy::mutex_atomic)]
41mod scheduler;
42
43mod task;
44pub use task::{SubTaskOutput, TaskId};
45
46pub mod timer;
47
48struct CallOnDrop<F: FnOnce()>(Option<F>);
49
50impl<F: FnOnce()> CallOnDrop<F> {
51 fn new(f: F) -> Self {
52 CallOnDrop(Some(f))
53 }
54}
55
56impl<F: FnOnce()> Drop for CallOnDrop<F> {
57 fn drop(&mut self) {
58 self.0.take().unwrap()()
59 }
60}