17
{
18
DWORD startTime =
0
;
19
for
(
int
j =
0
; ; j = (j +
1
) % samplingCount)
20
{
21
startTime = GetTickCount();
22
while
((GetTickCount() - startTime) < busySpan[j]);
23
Sleep(idleSpan[j]);
24
}
25
}
26
27
//如果 cpuindex < 0 则所有 cpu 都显示正弦曲线
28
//否则只有第 cpuindex 个 cpu 显示正弦曲线
29
//cpuindex 从 0 开始计数
30
void
CpuSin(
int
cpuIndex)
31
{
32
//计算 busySpan 和 idleSpan
33
double
radian =
0
;
34
int
amplitude = totalAmplitude /
2
;
35
for
(
int
i =
0
; i < samplingCount; i++)
36
{
37
busySpan[i] = (DWORD)(amplitude + sin(pi*radian)*amplitude);
38
idleSpan[i] = totalAmplitude - busySpan[i];
39
radian += delta;