-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Runtime light: coroutine scheduler & forks (#1050)
Main changes: * stream management: now all operations with streams are performed through ComponentState. ComponentState stores all opened streams, releases unneeded streams, etc; * cancellable awaitables: awaitables that can stop waiting for some event; * forks: task_t<fork_result> is now a handle to a fork. Forks can be started, waited on, and cancelled; * coroutine scheduler: a coroutine scheduler concept and its simple implementation are added.
- Loading branch information
Showing
50 changed files
with
1,325 additions
and
627 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CompileFlags: | ||
CompilationDatabase: build/ # Search build/ directory for compile_commands.json | ||
|
||
Diagnostics: | ||
Suppress: cppcoreguidelines-avoid-do-while | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Compiler for PHP (aka KPHP) | ||
// Copyright (c) 2020 LLC «V Kontakte» | ||
// Distributed under the GPL v3 License, see LICENSE.notice.txt | ||
|
||
#pragma once | ||
|
||
#include <array> | ||
#include <cstddef> | ||
#include <type_traits> | ||
#include <utility> | ||
|
||
#include "runtime-core/runtime-core.h" | ||
|
||
template<size_t limit> | ||
union small_object_storage { | ||
std::array<std::byte, limit> storage_; | ||
void *storage_ptr; | ||
|
||
template<typename T, typename... Args> | ||
std::enable_if_t<sizeof(T) <= limit, T *> emplace(Args &&...args) noexcept { | ||
return new (storage_.data()) T(std::forward<Args>(args)...); | ||
} | ||
template<typename T> | ||
std::enable_if_t<sizeof(T) <= limit, T *> get() noexcept { | ||
return reinterpret_cast<T *>(storage_.data()); | ||
} | ||
template<typename T> | ||
std::enable_if_t<sizeof(T) <= limit> destroy() noexcept { | ||
get<T>()->~T(); | ||
} | ||
|
||
template<typename T, typename... Args> | ||
std::enable_if_t < limit<sizeof(T), T *> emplace(Args &&...args) noexcept { | ||
storage_ptr = RuntimeAllocator::current().alloc_script_memory(sizeof(T)); | ||
return new (storage_ptr) T(std::forward<Args>(args)...); | ||
} | ||
template<typename T> | ||
std::enable_if_t < limit<sizeof(T), T *> get() noexcept { | ||
return static_cast<T *>(storage_ptr); | ||
} | ||
template<typename T> | ||
std::enable_if_t < limit<sizeof(T)> destroy() noexcept { | ||
T *mem = get<T>(); | ||
mem->~T(); | ||
RuntimeAllocator::current().free_script_memory(mem, sizeof(T)); | ||
} | ||
}; |
Oops, something went wrong.