quic/qbox
Loading...
Searching...
No Matches
onmethod.h
1/*
2 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 * Author: GreenSocs 2022
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#ifndef ONMETHODHELPER_H
9#define ONMETHODHELPER_H
10
11#include <systemc>
12
13class onMethodHelper : public sc_core::sc_module
14{
15 std::function<void()> entry;
16 sc_core::sc_event start;
17 sc_core::sc_event done;
18 void start_entry()
19 {
20 entry();
21 done.notify();
22 }
23
24public:
25 onMethodHelper(): sc_core::sc_module(sc_core::sc_module_name("onMethodHelper"))
26 {
27 SC_METHOD(start_entry);
28 sensitive << start;
30 }
31 void run(std::function<void()> fn)
32 {
33 entry = fn;
34 auto kind = sc_core::sc_get_current_process_handle().proc_kind();
35 if (kind == sc_core::SC_THREAD_PROC_) {
36 start.notify();
37 wait(done);
38 } else {
39 entry();
40 }
41 }
42};
43
44#endif // ONMETHODHELPER_H
Definition target.h:160
Definition onmethod.h:14