huajsj commented on a change in pull request #10234:
URL: https://github.com/apache/tvm/pull/10234#discussion_r806591088



##########
File path: src/runtime/pipeline/pipeline_struct.h
##########
@@ -42,6 +52,75 @@ using GlobalOutputPair = std::pair<int, int>;
  * The first 'int' is the module index, and the second 'int' is the module 
output index.
  */
 using ModuleOutputPair = std::pair<int, int>;
+/*!
+ *\brief The pair includes the module index and the module input index.
+ * The first 'int' is the module index, and the second 'int' is the module 
input index.
+ */
+using ModuleInputPair = std::pair<int, int>;
+/*!\brief The data notification structure.*/
+class DataNotify {
+ private:
+  /*!\brief The 'contitional variable' is used to wait for notification.*/
+  std::condition_variable condition_;
+  /*!\brief The mutex is used to protect the 'conditional variable'.*/
+  std::mutex mutex_;
+  /*!\brief Whether a data is ready or not.*/
+  volatile bool data_ready_ = false;
+  /*!\brief Whether the thread should exit or not.*/
+  volatile bool exit_state_ = false;
+  /*!\brief The index of runtime which is sending out the data notification.*/
+  int parent_idx_;
+  /*!\brief The index of runtime output interface which is sending out the 
data notification.*/
+  int parent_output_idx_;
+
+ public:
+  /*!
+   * \brief Constructing the DataNotify class.
+   * \param parent_idx The index of runtime which is sending out the data 
notification
+   * \param parent_output_idx The index of runtime output interface which is 
sending out
+   *  the data notification.
+   */
+  DataNotify(int parent_idx, int parent_output_idx) {
+    parent_idx_ = parent_idx;
+    parent_output_idx_ = parent_output_idx;
+  }
+  /*!
+   * \brief Getting the notification source.
+   * \return The first 'int' is the runtime index, and the second 'int' is the 
output index.
+   */
+  std::pair<int, int> GetNotifySource(void) {
+    return std::make_pair(parent_idx_, parent_output_idx_);
+  }
+  /*!
+   *\brief Waiting the notification.
+   *\return Returning the value 'false' when the notification is in a 'exit' 
state, else
+   * return true.
+   */
+  bool Wait(void) {
+    std::unique_lock<std::mutex> lock(mutex_);
+    condition_.wait(lock, [&] { return this->data_ready_; });
+    data_ready_ = false;
+    return !exit_state_;
+  }
+  /*!brief Sending the notification in which the related data is ready.*/
+  void Notify(void) {
+    {
+      std::lock_guard<std::mutex> lock(mutex_);
+      data_ready_ = true;

Review comment:
       std::contiditon_variable  already used a mutex to protect data_ready_,  
to cooperate with such mechanism we may need use mutex at this function too.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to