Skip to content

Commit

Permalink
Merge branch 'microsoft:main' into read-only-cown
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalgupta97 authored Jul 15, 2024
2 parents 22ba896 + 10174c5 commit 420d63d
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 @@ -108,13 +108,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 420d63d

Please sign in to comment.