summaryrefslogtreecommitdiff
path: root/src/modules/netlib/netlib.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-07-02 22:30:27 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-07-02 22:30:27 +0000
commit980bcaff693a86971750d6e9ffc8ba1e561b8b3a (patch)
treed8a422e9ccd2357d6e28368447bee8cfcd26123a /src/modules/netlib/netlib.cpp
parent990f961261d92fccadb16b495171bb619c0183f0 (diff)
the core without manual critical sections' control
git-svn-id: http://svn.miranda-ng.org/main/trunk@730 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules/netlib/netlib.cpp')
-rw-r--r--src/modules/netlib/netlib.cpp28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/modules/netlib/netlib.cpp b/src/modules/netlib/netlib.cpp
index 9c6f55aa11..bd72a8374b 100644
--- a/src/modules/netlib/netlib.cpp
+++ b/src/modules/netlib/netlib.cpp
@@ -130,8 +130,6 @@ static char *GetNetlibUserSettingString(const char *szUserModule, const char *sz
static INT_PTR NetlibRegisterUser(WPARAM, LPARAM lParam)
{
NETLIBUSER *nlu=(NETLIBUSER*)lParam;
- struct NetlibUser *thisUser;
-
if (nlu == NULL || nlu->cbSize != sizeof(NETLIBUSER) || nlu->szSettingsModule == NULL
|| ( !(nlu->flags&NUF_NOOPTIONS) && nlu->szDescriptiveName == NULL)
|| (nlu->flags&NUF_HTTPGATEWAY && (nlu->pfnHttpGatewayInit == NULL))) {
@@ -139,19 +137,20 @@ static INT_PTR NetlibRegisterUser(WPARAM, LPARAM lParam)
return 0;
}
- thisUser = (struct NetlibUser*)mir_calloc(sizeof(struct NetlibUser));
+ NetlibUser *thisUser = (struct NetlibUser*)mir_calloc(sizeof(struct NetlibUser));
thisUser->handleType = NLH_USER;
thisUser->user = *nlu;
- EnterCriticalSection(&csNetlibUser);
- if (netlibUser.getIndex(thisUser) >= 0)
+ int idx;
{
- LeaveCriticalSection(&csNetlibUser);
+ mir_cslock lck(csNetlibUser);
+ idx = netlibUser.getIndex(thisUser);
+ }
+ if (idx != -1) {
mir_free(thisUser);
SetLastError(ERROR_DUP_NAME);
return 0;
}
- LeaveCriticalSection(&csNetlibUser);
if (nlu->szDescriptiveName) {
thisUser->user.ptszDescriptiveName = (thisUser->user.flags&NUF_UNICODE ? mir_u2t((WCHAR*)nlu->ptszDescriptiveName) : mir_a2t(nlu->szDescriptiveName));
@@ -193,9 +192,8 @@ static INT_PTR NetlibRegisterUser(WPARAM, LPARAM lParam)
thisUser->toLog=GetNetlibUserSettingInt(thisUser->user.szSettingsModule, "NLlog", 1);
- EnterCriticalSection(&csNetlibUser);
+ mir_cslock lck(csNetlibUser);
netlibUser.insert(thisUser);
- LeaveCriticalSection(&csNetlibUser);
return (INT_PTR)thisUser;
}
@@ -247,12 +245,12 @@ INT_PTR NetlibCloseHandle(WPARAM wParam, LPARAM)
case NLH_USER:
{
struct NetlibUser *nlu=(struct NetlibUser*)wParam;
- int i;
-
- EnterCriticalSection(&csNetlibUser);
- i = netlibUser.getIndex(nlu);
- if (i >= 0) netlibUser.remove(i);
- LeaveCriticalSection(&csNetlibUser);
+ {
+ mir_cslock lck(csNetlibUser);
+ int i = netlibUser.getIndex(nlu);
+ if (i >= 0)
+ netlibUser.remove(i);
+ }
NetlibFreeUserSettingsStruct(&nlu->settings);
mir_free(nlu->user.szSettingsModule);