-
Notifications
You must be signed in to change notification settings - Fork 0
/
countc.c
58 lines (45 loc) · 1.19 KB
/
countc.c
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
//
// CountC.c -- アクティブなクライアントスレッド数の追跡
//
#include "httpMT.h"
DWORD gdwClientCount = 0;
CRITICAL_SECTION gcriticalClients;
HANDLE ghNoClients;
////////////////////////////////////////////////////////////
HANDLE InitClientCount(void)
{
gdwClientCount = 0;
InitializeCriticalSection(&gcriticalClients);
//
// Create the "no clients" signal event object
//
ghNoClients = CreateEvent(NULL, // Security
TRUE, // Manual reset
TRUE, // Initial State
NULL); // Name
return ghNoClients;
}
////////////////////////////////////////////////////////////
void IncrementClientCount(void)
{
EnterCriticalSection(&gcriticalClients);
gdwClientCount++;
LeaveCriticalSection(&gcriticalClients);
ResetEvent(ghNoClients);
}
////////////////////////////////////////////////////////////
void DecrementClientCount(void)
{
EnterCriticalSection(&gcriticalClients);
if (gdwClientCount > 0)
gdwClientCount--;
LeaveCriticalSection(&gcriticalClients);
if (gdwClientCount < 1)
SetEvent(ghNoClients);
}
////////////////////////////////////////////////////////////
void DeleteClientCount(void)
{
DeleteCriticalSection(&gcriticalClients);
CloseHandle(ghNoClients);
}