-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ESI Runtime] Read ports now invoke callbacks
We've switched from a polling 'pull' method to a callback-based 'push' mechanism for read ports. Polling (via std::futures) is built on top of the push mechanism. The read-ordering problem has also been fixed by using std::futures exclusively for polling schemes. They also allow for poll-wait-notify schemes without any chances on our part.
- Loading branch information
Showing
17 changed files
with
321 additions
and
142 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
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,52 @@ | ||
//===- Utils.h - utility code for cosim -------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef COSIM_UTILS_H | ||
#define COSIM_UTILS_H | ||
|
||
#include <mutex> | ||
#include <optional> | ||
#include <queue> | ||
|
||
namespace esi { | ||
namespace cosim { | ||
|
||
/// Thread safe queue. Just wraps std::queue protected with a lock. | ||
// TODO: this is now in esiruntime proper. Remove this in the gRPC refactor | ||
// wherein cosim will have a dependency on esiruntime. | ||
template <typename T> | ||
class TSQueue { | ||
using Lock = std::lock_guard<std::mutex>; | ||
|
||
std::mutex m; | ||
std::queue<T> q; | ||
|
||
public: | ||
/// Push onto the queue. | ||
template <typename... E> | ||
void push(E... t) { | ||
Lock l(m); | ||
q.emplace(t...); | ||
} | ||
|
||
/// Pop something off the queue but return nullopt if the queue is empty. Why | ||
/// doesn't std::queue have anything like this? | ||
std::optional<T> pop() { | ||
Lock l(m); | ||
if (q.size() == 0) | ||
return std::nullopt; | ||
auto t = q.front(); | ||
q.pop(); | ||
return t; | ||
} | ||
}; | ||
|
||
} // namespace cosim | ||
} // namespace esi | ||
|
||
#endif |
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
Oops, something went wrong.