File: CPU_MT.h

package info (click to toggle)
pose 3.0a3-3
  • links: PTS
  • area: contrib
  • in suites: potato
  • size: 15,500 kB
  • ctags: 20,548
  • sloc: ansic: 72,579; cpp: 50,198; perl: 1,336; python: 1,242; sh: 363; makefile: 290
file content (99 lines) | stat: -rw-r--r-- 3,144 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* -*- mode: C++; tab-width: 4 -*- */
/* ================================================================================== */
/* Copyright (c) 1998-1999 3Com Corporation or its subsidiaries. All rights reserved. */
/* ================================================================================== */

#ifndef __CPU_MT_H__
#define __CPU_MT_H__

#include "ErrorHandling.h"		// ErrCode
#include "omnithread.h" 		// omni_thread
#include "Platform_Files.h" 	// FileReference
#include "Skins.h"				// SkinElement

enum { kStopManually = 1, kStopOnADime, kStopOnATrap };
enum { kStateStopped, kStateWaitingToStart, kStateRunning, kStateStopRequested };

class CPU : public omni_thread
{
	public:
  
	// -----------------------------------------------------------------------------
	// constructor / destructor
	// -----------------------------------------------------------------------------

								CPU 			(void);
		virtual 				~CPU			(void);

	// -----------------------------------------------------------------------------
	// public methods
	// -----------------------------------------------------------------------------

		void					CreateThread	(void);
		void					DestroyThread	(void);

		void					StartThread 	(void);
		void					StopThread		(Bool& wasStopped, Bool& isStopped, int how);

		void					Sleep			(long timeout);

	private:

		// -----------------------------------------------------------------------------
		// private methods
		// -----------------------------------------------------------------------------

		void					MSecsToSecsNSecs(long msecs, unsigned long& secs, unsigned long& nsecs);

		// -----------------------------------------------------------------------------
		// omni_thread overrides
		// -----------------------------------------------------------------------------

		virtual void*			run_undetached	(void* arg);

		// -----------------------------------------------------------------------------
		// private data members
		// -----------------------------------------------------------------------------

		omni_mutex				fRunMutex;
		omni_condition			fRunCondition;

		omni_mutex				fStopMutex;
		omni_condition			fStopCondition;

		omni_mutex				fSleepMutex;
		omni_condition			fSleepCondition;

		Bool					fRunning;		// Protected by fStopMutex.  Note that having fRunMutex
												// acquired will also protect fRunning, as that implies
												// the CPU thread is stopped.
		Bool					fStopRequest;	// Protected by fRunMutex (except for end of CPU::Stop).
		Bool					fQuitRequest;	// Protected by fRunMutex.
};


// -----------------------------------------------------------------------------
// Stack object which is used to briefly stop the emulator:
// -----------------------------------------------------------------------------

class CPUStopper
{
	public:
								CPUStopper		(int how);
								~CPUStopper 	(void);

		Bool					Stop			(int how);
		void					Start			(void);

		Bool					Stopped 		(void)	{ return fNowStopped; }

		void					ShowError		(const char*);

		static Bool				fgInstantiated;

	private:
		CPU*					fCPU;
		Bool					fNowStopped;
};

#endif /* __CPU_MT_H__ */