cpuevent.hh (2651:76db2c628241) cpuevent.hh (2680:246e7104f744)
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 20 unchanged lines hidden (view full) ---

29 */
30
31#ifndef __CPU_CPUEVENT_HH__
32#define __CPU_CPUEVENT_HH__
33
34#include <vector>
35#include "sim/eventq.hh"
36
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 20 unchanged lines hidden (view full) ---

29 */
30
31#ifndef __CPU_CPUEVENT_HH__
32#define __CPU_CPUEVENT_HH__
33
34#include <vector>
35#include "sim/eventq.hh"
36
37class ExecContext;
37class ThreadContext;
38
39/** This class creates a global list of events than need a pointer to an
38
39/** This class creates a global list of events than need a pointer to an
40 * execution context. When a switchover takes place the events can be migrated
41 * to the new execution context, otherwise you could have a wake timer interrupt
40 * thread context. When a switchover takes place the events can be migrated
41 * to the new thread context, otherwise you could have a wake timer interrupt
42 * go off on a switched out cpu or other unfortunate events. This object MUST be
43 * dynamically allocated to avoid it being deleted after a cpu switch happens.
44 * */
45class CpuEvent : public Event
46{
47 private:
48 /** type of global list of cpu events. */
49 typedef std::vector<CpuEvent *> CpuEventList;
50
51 /** Static list of cpu events that is searched every time a cpu switch
52 * happens. */
53 static CpuEventList cpuEventList;
54
42 * go off on a switched out cpu or other unfortunate events. This object MUST be
43 * dynamically allocated to avoid it being deleted after a cpu switch happens.
44 * */
45class CpuEvent : public Event
46{
47 private:
48 /** type of global list of cpu events. */
49 typedef std::vector<CpuEvent *> CpuEventList;
50
51 /** Static list of cpu events that is searched every time a cpu switch
52 * happens. */
53 static CpuEventList cpuEventList;
54
55 /** The execution context that is switched to the new cpus. */
56 ExecContext *xc;
55 /** The thread context that is switched to the new cpus. */
56 ThreadContext *tc;
57
58 public:
57
58 public:
59 CpuEvent(EventQueue *q, ExecContext *_xc, Priority p = Default_Pri)
60 : Event(q, p), xc(_xc)
59 CpuEvent(EventQueue *q, ThreadContext *_tc, Priority p = Default_Pri)
60 : Event(q, p), tc(_tc)
61 { cpuEventList.push_back(this); }
62
63 /** delete the cpu event from the global list. */
64 ~CpuEvent();
65
61 { cpuEventList.push_back(this); }
62
63 /** delete the cpu event from the global list. */
64 ~CpuEvent();
65
66 /** Update all events switching old xc to new xc.
67 * @param oldXc the old exeuction context we are switching from
68 * @param newXc the new execution context we are switching to.
66 /** Update all events switching old tc to new tc.
67 * @param oldTc the old thread context we are switching from
68 * @param newTc the new thread context we are switching to.
69 */
69 */
70 static void replaceExecContext(ExecContext *oldXc, ExecContext *newXc);
70 static void replaceThreadContext(ThreadContext *oldTc,
71 ThreadContext *newTc);
71};
72
72};
73
73template <class T, void (T::* F)(ExecContext *xc)>
74template <class T, void (T::* F)(ThreadContext *tc)>
74class CpuEventWrapper : public CpuEvent
75{
76 private:
77 T *object;
78
79 public:
75class CpuEventWrapper : public CpuEvent
76{
77 private:
78 T *object;
79
80 public:
80 CpuEventWrapper(T *obj, ExecContext *_xc, EventQueue *q = &mainEventQueue,
81 CpuEventWrapper(T *obj, ThreadContext *_tc, EventQueue *q = &mainEventQueue,
81 Priority p = Default_Pri)
82 Priority p = Default_Pri)
82 : CpuEvent(q, _xc, p), object(obj)
83 : CpuEvent(q, _tc, p), object(obj)
83 { }
84 { }
84 void process() { (object->*F)(xc); }
85 void process() { (object->*F)(tc); }
85};
86
87#endif // __CPU_CPUEVENT_HH__
88
86};
87
88#endif // __CPU_CPUEVENT_HH__
89