Skip to content

Commit

Permalink
Remove needless template parameter from Behaviour::make. (#41)
Browse files Browse the repository at this point in the history
* Remove needless template parameter from Behaviour::make.

Signed-off-by: Alona Enraght-Moony <[email protected]>

* Always use `Be` for behaviour template param (instead of `T`).

Signed-off-by: Alona Enraght-Moony <[email protected]>

---------

Signed-off-by: Alona Enraght-Moony <[email protected]>
Co-authored-by: Matthew Parkinson <[email protected]>
  • Loading branch information
aDotInTheVoid and mjp41 authored Jun 12, 2024
1 parent 6aa23cf commit 10174c5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
30 changes: 15 additions & 15 deletions src/rt/cpp/lambdabehaviour.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@

namespace verona::rt
{
template<TransferOwnership transfer = NoTransfer, typename T>
static void schedule_lambda(Cown* c, T&& f)
template<TransferOwnership transfer = NoTransfer, typename Be>
static void schedule_lambda(Cown* c, Be&& f)
{
Behaviour::schedule<transfer>(c, std::forward<T>(f));
Behaviour::schedule<transfer>(c, std::forward<Be>(f));
}

template<TransferOwnership transfer = NoTransfer, typename T>
static void schedule_lambda(size_t count, Cown** cowns, T&& f)
template<TransferOwnership transfer = NoTransfer, typename Be>
static void schedule_lambda(size_t count, Cown** cowns, Be&& f)
{
Behaviour::schedule<transfer>(count, cowns, std::forward<T>(f));
Behaviour::schedule<transfer>(count, cowns, std::forward<Be>(f));
}

template<typename T>
static void schedule_lambda(size_t count, Request* requests, T&& f)
template<typename Be>
static void schedule_lambda(size_t count, Request* requests, Be&& f)
{
Behaviour::schedule(count, requests, std::forward<T>(f));
Behaviour::schedule(count, requests, std::forward<Be>(f));
}

template<typename T>
static void schedule_lambda(T&& f)
template<typename Be>
static void schedule_lambda(Be&& f)
{
auto w = Closure::make([f = std::forward<T>(f)](Work* w) mutable {
auto w = Closure::make([f = std::forward<Be>(f)](Work* w) mutable {
f();
return true;
});
Expand All @@ -38,11 +38,11 @@ namespace verona::rt

// TODO super minimal version initially, just to get the tests working.
// Should be expanded to cover multiple cowns.
template<typename T>
inline Notification* make_notification(Cown* cown, T&& f)
template<typename Be>
inline Notification* make_notification(Cown* cown, Be&& f)
{
Request requests[] = {Request::write(cown)};
return Notification::make<T>(1, requests, std::forward<T>(f));
return Notification::make<Be>(1, requests, std::forward<Be>(f));
}

} // namespace verona::rt
27 changes: 14 additions & 13 deletions src/rt/sched/behaviour.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ namespace verona::rt
return rerun;
}

template<typename Be, typename T>
static Behaviour* make(size_t count, T&& f)
template<typename Be>
static Behaviour* make(size_t count, Be&& f)
{
auto behaviour_core = BehaviourCore::make(count, invoke<Be>, sizeof(Be));

new (behaviour_core->get_body()) Be(std::forward<T>(f));
new (behaviour_core->get_body()) Be(std::forward<Be>(f));

// These assertions are basically checking that we won't break any
// alignment assumptions on Be. If we add some actual alignment, then
Expand All @@ -63,8 +63,8 @@ namespace verona::rt
schedule<transfer, T>(1, &cown, std::forward<T>(f));
}

template<TransferOwnership transfer = NoTransfer, class T>
static void schedule(size_t count, Cown** cowns, T&& f)
template<TransferOwnership transfer = NoTransfer, class Be>
static void schedule(size_t count, Cown** cowns, Be&& f)
{
// TODO Remove vector allocation here. This is a temporary fix to
// as we transition to using Request through the code base.
Expand All @@ -80,7 +80,7 @@ namespace verona::rt
}
}

schedule<T>(count, requests, std::forward<T>(f));
schedule<Be>(count, requests, std::forward<Be>(f));

alloc.dealloc(requests);
}
Expand All @@ -89,11 +89,11 @@ namespace verona::rt
* Prepare a multimessage
**/

template<typename T>
template<typename Be>
static Behaviour*
prepare_to_schedule(size_t count, Request* requests, T&& f)
prepare_to_schedule(size_t count, Request* requests, Be&& f)
{
auto body = Behaviour::make<T>(count, std::forward<T>(f));
auto body = Behaviour::make<Be>(count, std::forward<Be>(f));

auto* slots = body->get_slots();
for (size_t i = 0; i < count; i++)
Expand All @@ -106,13 +106,14 @@ namespace verona::rt
return body;
}

template<class T>
static void schedule(size_t count, Request* requests, T&& f)
template<class Be>
static void schedule(size_t count, Request* requests, Be&& f)
{
Logging::cout() << "Schedule behaviour of type: " << typeid(T).name()
Logging::cout() << "Schedule behaviour of type: " << typeid(Be).name()
<< Logging::endl;

auto* body = prepare_to_schedule<T>(count, requests, std::forward<T>(f));
auto* body =
prepare_to_schedule<Be>(count, requests, std::forward<Be>(f));

BehaviourCore* arr[] = {body};

Expand Down

0 comments on commit 10174c5

Please sign in to comment.