process_types.hh revision 13180
12623SN/A/* 22623SN/A * Copyright 2018 Google, Inc. 32623SN/A * 42623SN/A * Redistribution and use in source and binary forms, with or without 52623SN/A * modification, are permitted provided that the following conditions are 62623SN/A * met: redistributions of source code must retain the above copyright 72623SN/A * notice, this list of conditions and the following disclaimer; 82623SN/A * redistributions in binary form must reproduce the above copyright 92623SN/A * notice, this list of conditions and the following disclaimer in the 102623SN/A * documentation and/or other materials provided with the distribution; 112623SN/A * neither the name of the copyright holders nor the names of its 122623SN/A * contributors may be used to endorse or promote products derived from 132623SN/A * this software without specific prior written permission. 142623SN/A * 152623SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162623SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172623SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182623SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192623SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202623SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212623SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222623SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232623SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242623SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252623SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262623SN/A * 272665Ssaidi@eecs.umich.edu * Authors: Gabe Black 282665Ssaidi@eecs.umich.edu */ 292623SN/A 302623SN/A#ifndef __SYSTEMC_CORE_PROCESS_TYPES_HH__ 313170Sstever@eecs.umich.edu#define __SYSTEMC_CORE_PROCESS_TYPES_HH__ 325103Ssaidi@eecs.umich.edu 332623SN/A#include "systemc/core/process.hh" 344040Ssaidi@eecs.umich.edu#include "systemc/core/scheduler.hh" 352623SN/A 362623SN/Anamespace sc_gem5 373348Sbinkertn@umich.edu{ 383348Sbinkertn@umich.edu 394762Snate@binkert.orgclass Method : public Process 402901Ssaidi@eecs.umich.edu{ 412623SN/A public: 422623SN/A Method(const char *name, ProcessFuncWrapper *func, bool internal=false) : 432623SN/A Process(name, func, internal) 442623SN/A {} 452856Srdreslin@umich.edu 462856Srdreslin@umich.edu const char *kind() const override { return "sc_method_process"; } 472856Srdreslin@umich.edu 482856Srdreslin@umich.edu sc_core::sc_curr_proc_kind 492856Srdreslin@umich.edu procKind() const override 502856Srdreslin@umich.edu { 512856Srdreslin@umich.edu return sc_core::SC_METHOD_PROC_; 522856Srdreslin@umich.edu } 532856Srdreslin@umich.edu}; 542856Srdreslin@umich.edu 552623SN/Aclass Thread : public Process 562623SN/A{ 572623SN/A public: 582623SN/A Thread(const char *name, ProcessFuncWrapper *func, bool internal=false) : 592623SN/A Process(name, func, internal), ctx(nullptr) 602623SN/A {} 612680Sktlim@umich.edu 622680Sktlim@umich.edu ~Thread() { delete ctx; } 632623SN/A 642623SN/A const char *kind() const override { return "sc_thread_process"; } 655712Shsul@eecs.umich.edu 662623SN/A void throw_it(ExceptionWrapperBase &exc, bool inc_kids) override; 672623SN/A 682623SN/A sc_core::sc_curr_proc_kind 692623SN/A procKind() const override 702623SN/A { 713349Sbinkertn@umich.edu return sc_core::SC_THREAD_PROC_; 722623SN/A } 732623SN/A 742623SN/A Fiber * 752623SN/A fiber() override 762623SN/A { 772623SN/A if (!ctx) 783349Sbinkertn@umich.edu ctx = new Context(this, stackSize); 792623SN/A return ctx; 803184Srdreslin@umich.edu } 813184Srdreslin@umich.edu 822623SN/A private: 832623SN/A class Context : public Fiber 842623SN/A { 852623SN/A public: 862623SN/A Context(Thread *thread, size_t size) : Fiber(size), thread(thread) {} 873647Srdreslin@umich.edu 883647Srdreslin@umich.edu private: 893647Srdreslin@umich.edu Thread *thread; 903647Srdreslin@umich.edu 913647Srdreslin@umich.edu void 922631SN/A main() override 933647Srdreslin@umich.edu { 942631SN/A thread->_needsStart = false; 952623SN/A thread->run(); 962623SN/A thread->terminate(); 972623SN/A scheduler.yield(); 982948Ssaidi@eecs.umich.edu } 992948Ssaidi@eecs.umich.edu }; 1003349Sbinkertn@umich.edu friend class Context; 1012948Ssaidi@eecs.umich.edu 1022948Ssaidi@eecs.umich.edu Context *ctx; 1035606Snate@binkert.org}; 1042948Ssaidi@eecs.umich.edu 1052948Ssaidi@eecs.umich.educlass CThread : public Thread 1065529Snate@binkert.org{ 1075894Sgblack@eecs.umich.edu public: 1085894Sgblack@eecs.umich.edu CThread(const char *name, ProcessFuncWrapper *func, bool internal=false) : 1092623SN/A Thread(name, func, internal) 1102623SN/A { 1113647Srdreslin@umich.edu // We'll be in the initialization list now, but we shouldn't be. 1123647Srdreslin@umich.edu popListNode(); 1133647Srdreslin@umich.edu } 1143647Srdreslin@umich.edu 1152623SN/A const char *kind() const override { return "sc_cthread_process"; } 1162839Sktlim@umich.edu 1173222Sktlim@umich.edu sc_core::sc_curr_proc_kind 1182901Ssaidi@eecs.umich.edu procKind() const override 1192623SN/A { 1202623SN/A return sc_core::SC_CTHREAD_PROC_; 1212623SN/A } 1222623SN/A}; 1232623SN/A 1242623SN/A} // namespace sc_gem5 1252623SN/A 1262623SN/A#endif //__SYSTEMC_CORE_PROCESS_TYPES_HH__ 1272623SN/A