-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCacheThread.cpp
105 lines (82 loc) · 2.58 KB
/
CacheThread.cpp
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
100
101
102
103
104
105
// ---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "CacheThread.h"
#include "main.h"
#include <vector>
#include "functions.h"
#pragma package(smart_init)
#include <algorithm>
using namespace std;
extern LONGLONG totcachsize;
extern vector<CACHE>cache;
extern TEvent *cev;
extern int unsaved;
extern TCriticalSection *cchs;
extern TCriticalSection *ccs;
__fastcall CacheThread::CacheThread(bool CreateSuspended):TThread(CreateSuspended)
{
}
bool sortcachebyopid(CACHE c1, CACHE c2)
{
return c1.opid < c2.opid;
}
void __fastcall CacheThread::Do(void)
{
if(!ccs->TryEnter())
return;
sort(cache.begin(), cache.end(), sortcachebyopid);
for (vector<CACHE>::iterator it = cache.begin();it!=cache.end();it++)
{
if ((*it).unsaved && ((GetTickCount() - (*it).changed) > 3000))
{
LARGE_INTEGER li;
li.QuadPart = (*it).offset;
paintdisk(5, li, (*it).len, 0, 0);
double ms;
ms = GetTickCount();
unsaved = 0;
for (vector<CACHE>::iterator it = cache.begin();it!=cache.end();it++)
if ((*it).unsaved)
unsaved++;
char str[129];
sprintf(str, "%4d îñò.", unsaved-1);
nwrite((ULONG)(*it).buf, (*it).offset, (*it).len, 0, true, 0, str);
li.QuadPart = 0;
paintdisk(4, li, 1, 0, 0);
// HeapFree(GetProcessHeap(), 0, (*it).buf);
ms = (GetTickCount() - ms) /1000.0;
deb(" * ÊÅØ: ñîõðàíåíî %5lu @ %8lu, opid: %d çà %.2f ñåê", (*it).len, (*it).offset,
(*it).opid, ms);
// deb(" ñîõðàíåíî çà %.2f ñåê", ms);
// totcachsize-=(*it).len;
// it = cache.erase(it);
(*it).unsaved = false;
(*it).changed = GetTickCount();
// if(it == cache.end())
// if (cev->WaitFor(0) == wrSignaled)
// {
// deb("ñîõðàíåíèå êåøà ïðåðâàíî èççà çàïðîñà ê äèñêó");
break;
// }
}
}
ccs->Leave();
}
// ---------------------------------------------------------------------------
void __fastcall CacheThread::Execute()
{
NameThreadForDebugging("CacheThread");
Sleep(1000);
while (1)
{
// cev->ResetEvent();
Sleep(1);
// if (cev->WaitFor(0) == wrSignaled)
// continue;
// cev->ResetEvent();
// Synchronize(Do);
Do();
}
}
// ---------------------------------------------------------------------------