process_types.hh revision 13092:a4995c783157
12817Sksewell@umich.edu/* 27763SAli.Saidi@ARM.com * Copyright 2018 Google, Inc. 37763SAli.Saidi@ARM.com * 47763SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without 57763SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are 67763SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright 77763SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer; 87763SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright 97763SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the 107763SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution; 117763SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its 127763SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from 137763SAli.Saidi@ARM.com * this software without specific prior written permission. 142817Sksewell@umich.edu * 152817Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162817Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172817Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182817Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192817Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202817Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212817Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222817Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232817Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242817Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252817Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262817Sksewell@umich.edu * 272817Sksewell@umich.edu * Authors: Gabe Black 282817Sksewell@umich.edu */ 292817Sksewell@umich.edu 302817Sksewell@umich.edu#ifndef __SYSTEMC_CORE_PROCESS_TYPES_HH__ 312817Sksewell@umich.edu#define __SYSTEMC_CORE_PROCESS_TYPES_HH__ 322817Sksewell@umich.edu 332817Sksewell@umich.edu#include "systemc/core/process.hh" 342817Sksewell@umich.edu#include "systemc/core/scheduler.hh" 352817Sksewell@umich.edu 362817Sksewell@umich.edunamespace sc_gem5 372817Sksewell@umich.edu{ 382817Sksewell@umich.edu 392817Sksewell@umich.educlass Method : public Process 402817Sksewell@umich.edu{ 412817Sksewell@umich.edu public: 422817Sksewell@umich.edu Method(const char *name, ProcessFuncWrapper *func, bool _dynamic=false) : 432817Sksewell@umich.edu Process(name, func, _dynamic) 446329Sgblack@eecs.umich.edu {} 456658Snate@binkert.org 462817Sksewell@umich.edu const char *kind() const override { return "sc_method_process"; } 472834Sksewell@umich.edu 482817Sksewell@umich.edu sc_core::sc_curr_proc_kind 492817Sksewell@umich.edu procKind() const override 502817Sksewell@umich.edu { 512817Sksewell@umich.edu return sc_core::SC_METHOD_PROC_; 525499Ssaidi@eecs.umich.edu } 532817Sksewell@umich.edu}; 545499Ssaidi@eecs.umich.edu 552817Sksewell@umich.educlass Thread : public Process 562817Sksewell@umich.edu{ 572817Sksewell@umich.edu public: 582817Sksewell@umich.edu Thread(const char *name, ProcessFuncWrapper *func, bool _dynamic=false) : 592817Sksewell@umich.edu Process(name, func, _dynamic), ctx(nullptr) 602817Sksewell@umich.edu {} 613126Sktlim@umich.edu 622817Sksewell@umich.edu ~Thread() { delete ctx; } 632817Sksewell@umich.edu 642817Sksewell@umich.edu const char *kind() const override { return "sc_thread_process"; } 652817Sksewell@umich.edu 662817Sksewell@umich.edu void throw_it(ExceptionWrapperBase &exc, bool inc_kids) override; 672817Sksewell@umich.edu 682817Sksewell@umich.edu sc_core::sc_curr_proc_kind 692817Sksewell@umich.edu procKind() const override 707467Stjones1@inf.ed.ac.uk { 712817Sksewell@umich.edu return sc_core::SC_THREAD_PROC_; 727467Stjones1@inf.ed.ac.uk } 732817Sksewell@umich.edu 742817Sksewell@umich.edu Fiber * 752817Sksewell@umich.edu fiber() override 762817Sksewell@umich.edu { 772817Sksewell@umich.edu if (!ctx) 782817Sksewell@umich.edu ctx = new Context(this, stackSize); 795714Shsul@eecs.umich.edu return ctx; 805715Shsul@eecs.umich.edu } 812817Sksewell@umich.edu 822817Sksewell@umich.edu private: 832817Sksewell@umich.edu class Context : public Fiber 842817Sksewell@umich.edu { 852817Sksewell@umich.edu public: 862817Sksewell@umich.edu Context(Thread *thread, size_t size) : Fiber(size), thread(thread) {} 872817Sksewell@umich.edu 882817Sksewell@umich.edu private: 892817Sksewell@umich.edu Thread *thread; 902817Sksewell@umich.edu 912817Sksewell@umich.edu void 922817Sksewell@umich.edu main() override 932817Sksewell@umich.edu { 942817Sksewell@umich.edu thread->_needsStart = false; 952817Sksewell@umich.edu thread->run(); 962817Sksewell@umich.edu thread->terminate(); 972817Sksewell@umich.edu scheduler.yield(); 982817Sksewell@umich.edu } 992817Sksewell@umich.edu }; 1002817Sksewell@umich.edu friend class Context; 1016029Ssteve.reinhardt@amd.com 1022817Sksewell@umich.edu Context *ctx; 1032817Sksewell@umich.edu}; 1042817Sksewell@umich.edu 1052817Sksewell@umich.educlass CThread : public Thread 1062817Sksewell@umich.edu{ 1072817Sksewell@umich.edu public: 1082817Sksewell@umich.edu CThread(const char *name, ProcessFuncWrapper *func, bool _dynamic=false) : 1092817Sksewell@umich.edu Thread(name, func, _dynamic) 1102817Sksewell@umich.edu { 1112875Sksewell@umich.edu // We'll be in the initialization list now, but we shouldn't be. 1125715Shsul@eecs.umich.edu popListNode(); 1132817Sksewell@umich.edu } 1142817Sksewell@umich.edu 1152817Sksewell@umich.edu const char *kind() const override { return "sc_cthread_process"; } 1162817Sksewell@umich.edu 1172817Sksewell@umich.edu sc_core::sc_curr_proc_kind 1187823Ssteve.reinhardt@amd.com procKind() const override 1192817Sksewell@umich.edu { 1202817Sksewell@umich.edu return sc_core::SC_CTHREAD_PROC_; 1212817Sksewell@umich.edu } 1222817Sksewell@umich.edu}; 1232817Sksewell@umich.edu 1245715Shsul@eecs.umich.edu} // namespace sc_gem5 1252817Sksewell@umich.edu 1262817Sksewell@umich.edu#endif //__SYSTEMC_CORE_PROCESS_TYPES_HH__ 1272817Sksewell@umich.edu