Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
internal.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
20// $File: //depot/GeneralsMD/Staging/code/Libraries/Source/profile/internal.h $
21// $Author: mhoffe $
22// $Revision: #3 $
23// $DateTime: 2003/07/09 10:57:23 $
24//
25// ©2003 Electronic Arts
26//
27// Internal header
29#ifdef _MSC_VER
30# pragma once
31#endif
32#ifndef INTERNAL_H // Include guard
33#define INTERNAL_H
34
35#include "../debug/debug.h"
36#include "internal_funclevel.h"
37#include "internal_highlevel.h"
38#include "internal_cmd.h"
39#include "internal_result.h"
40
41class ProfileFastCS
42{
43 ProfileFastCS(const ProfileFastCS&);
44 ProfileFastCS& operator=(const ProfileFastCS&);
45
46 volatile unsigned m_Flag;
47 static HANDLE testEvent;
48
49 void ThreadSafeSetFlag()
50 {
51 volatile unsigned& nFlag=m_Flag;
52
53 #define ts_lock _emit 0xF0
54 DASSERT(((unsigned)&nFlag % 4) == 0);
55
56 __asm mov ebx, [nFlag]
57 __asm ts_lock
58 __asm bts dword ptr [ebx], 0
59 __asm jc The_Bit_Was_Previously_Set_So_Try_Again
60 return;
61
62 The_Bit_Was_Previously_Set_So_Try_Again:
63 // can't use SwitchToThread() here because Win9X doesn't have it!
64 if (testEvent)
65 ::WaitForSingleObject(testEvent,1);
66 __asm mov ebx, [nFlag]
67 __asm ts_lock
68 __asm bts dword ptr [ebx], 0
69 __asm jc The_Bit_Was_Previously_Set_So_Try_Again
70 }
71
72 void ThreadSafeClearFlag()
73 {
74 m_Flag=0;
75 }
76
77public:
79 m_Flag(0)
80 {
81 }
82
83 class Lock
84 {
85 Lock(const Lock&);
86 Lock& operator=(const Lock&);
87
88 ProfileFastCS& CriticalSection;
89
90 public:
91 Lock(ProfileFastCS& cs):
92 CriticalSection(cs)
93 {
94 CriticalSection.ThreadSafeSetFlag();
95 }
96
98 {
99 CriticalSection.ThreadSafeClearFlag();
100 }
101 };
102
103 friend class Lock;
104};
105
106void *ProfileAllocMemory(unsigned numBytes);
107void *ProfileReAllocMemory(void *oldPtr, unsigned newSize);
108void ProfileFreeMemory(void *ptr);
109
110__forceinline void ProfileGetTime(__int64 &t)
111{
112 _asm
113 {
114 mov ecx,[t]
115 push eax
116 push edx
117 rdtsc
118 mov [ecx],eax
119 mov [ecx+4],edx
120 pop edx
121 pop eax
122 };
123}
124
125#endif // INTERNAL_H
Lock(ProfileFastCS &cs)
Definition internal.h:91
ProfileFastCS(void)
Definition internal.h:78
friend class Lock
Definition internal.h:103
#define DASSERT(expr)
__forceinline void ProfileGetTime(__int64 &t)
Definition internal.h:110
void ProfileFreeMemory(void *ptr)
Definition profile.cpp:82
#define ts_lock
void * ProfileReAllocMemory(void *oldPtr, unsigned newSize)
Definition profile.cpp:52
void * ProfileAllocMemory(unsigned numBytes)
Definition profile.cpp:44