Improve sandbox internal api (#9709)

* Improve sandbox internal api

This improves the internal sandbox api for the executor implementations.
The main point is to hide the tls in the internal api and not having it
exposed to the outside.

This is especially needed for wasmtime 0.29.0

* Fmt

* Make it nicer
This commit is contained in:
Bastian Köcher
2021-09-08 12:28:23 +02:00
committed by GitHub
parent 8cf6474388
commit b382cc8f9d
6 changed files with 579 additions and 697 deletions
@@ -16,7 +16,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::host::HostState;
use crate::host::{HostContext, HostState};
scoped_tls::scoped_thread_local!(static HOST_STATE: HostState);
@@ -36,10 +36,10 @@ where
/// context will be `None`.
pub fn with_context<R, F>(f: F) -> R
where
F: FnOnce(Option<HostState>) -> R,
F: FnOnce(Option<HostContext>) -> R,
{
if !HOST_STATE.is_set() {
return f(None)
}
HOST_STATE.with(|state| f(Some(state.clone())))
HOST_STATE.with(|state| f(Some(state.materialize())))
}