diff options
author | George Hazan <george.hazan@gmail.com> | 2013-03-18 08:18:13 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-03-18 08:18:13 +0000 |
commit | e63908912809cd6aeeeb2d068da562c227cbd3a9 (patch) | |
tree | db3d95b3fc111d31d1a4dc23d8e094990105014f /plugins/ShlExt | |
parent | d90a9d04b3b6e2beaa31b311fd38b886a46bab72 (diff) |
clutch for pascal plugins not to eat memory on thread creation
git-svn-id: http://svn.miranda-ng.org/main/trunk@4085 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/ShlExt')
-rw-r--r-- | plugins/ShlExt/shlcom.pas | 39 | ||||
-rw-r--r-- | plugins/ShlExt/shlext.dpr | 9 |
2 files changed, 13 insertions, 35 deletions
diff --git a/plugins/ShlExt/shlcom.pas b/plugins/ShlExt/shlcom.pas index fb9b4fa780..8aeb14c62b 100644 --- a/plugins/ShlExt/shlcom.pas +++ b/plugins/ShlExt/shlcom.pas @@ -1737,7 +1737,7 @@ begin SetEvent(p^.hEvent);
end;
-function IssueTransferThread(pipch: PHeaderIPC): Cardinal; stdcall;
+procedure IssueTransferThread(pipch: PHeaderIPC); cdecl;
var
szBuf: array [0 .. MAX_PATH] of Char;
pct: PSlotIPC;
@@ -1747,8 +1747,6 @@ var p: Pointer;
hMainThread: THandle;
begin
- result:=0;
- Thread_Push(0,nil);
hMainThread := THandle(pipch^.Param);
GetCurrentDirectory(sizeof(szBuf), szBuf);
args.count := 0;
@@ -1795,8 +1793,6 @@ begin SetCurrentDirectory(szBuf);
FreeMem(pipch);
CloseHandle(hMainThread);
- Thread_Pop();
- ExitThread(0);
end;
type
@@ -2071,7 +2067,7 @@ begin end;
// worker thread to clear MRU, called by the IPC bridge
-function ClearMRUThread(notused: Pointer): Cardinal; stdcall;
+procedure ClearMRUThread(notused: Pointer); cdecl;
{$DEFINE SHL_IDC}
{$DEFINE SHL_KEYS}
{$INCLUDE shlc.inc}
@@ -2080,9 +2076,6 @@ function ClearMRUThread(notused: Pointer): Cardinal; stdcall; var
hContact: THandle;
begin
- result:=0;
- Thread_Push(0,nil);
-
begin
hContact := CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
while hContact <> 0 do
@@ -2094,8 +2087,6 @@ begin hContact := CallService(MS_DB_CONTACT_FINDNEXT, hContact, 0);
end;
end;
- Thread_Pop();
- ExitThread(0);
end;
// this function is called from an APC into the main thread
@@ -2141,13 +2132,13 @@ begin ipcFixupAddresses(True, cloned);
DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(),
@cloned^.Param, THREAD_SET_CONTEXT, False, 0);
- CloseHandle(CreateThread(nil, 0, @IssueTransferThread, cloned, 0, tid));
+ mir_forkThread(@IssueTransferThread, cloned);
goto Reply;
end;
// the request was to clear the MRU entries, we have no return data
if (bits^ and REQUEST_CLEARMRU) = REQUEST_CLEARMRU then
begin
- CloseHandle(CreateThread(nil, 0, @ClearMRUThread, nil, 0, tid));
+ mir_forkThread(@ClearMRUThread, nil);
goto Reply;
end;
// the IPC header may have pointers that need to be translated
@@ -2266,20 +2257,16 @@ begin //
end;
-function ThreadServer(hMainThread: Pointer): Cardinal;
-{$IFDEF FPC}
-stdcall;
-{$ENDIF}
+procedure ThreadServer(hMainThread: Pointer); cdecl;
var
hEvent: THandle;
+ retVal: Cardinal;
begin
- result:=0;
- Thread_Push(0,nil);
hEvent := CreateEvent(nil, False, False, PChar(CreateProcessUID(GetCurrentProcessId())));
while True do
begin
- Result := WaitForSingleObjectEx(hEvent, INFINITE, True);
- if Result = WAIT_OBJECT_0 then
+ retVal := WaitForSingleObjectEx(hEvent, INFINITE, True);
+ if retVal = WAIT_OBJECT_0 then
begin
QueueUserAPC(@ipcService, THandle(hMainThread), 0);
end; // if
@@ -2288,8 +2275,6 @@ begin end; // while
CloseHandle(hEvent);
CloseHandle(THandle(hMainThread));
- Thread_Pop();
- ExitThread(0);
end;
procedure InvokeThreadServer;
@@ -2306,13 +2291,7 @@ begin DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), @hMainThread,
THREAD_SET_CONTEXT, False, 0);
if hMainThread <> 0 then
- begin
-{$IFDEF FPC}
- CloseHandle(CreateThread(nil, 0, @ThreadServer, Pointer(hMainThread), 0, tid));
-{$ELSE}
- CloseHandle(BeginThread(nil, 0, @ThreadServer, Pointer(hMainThread), 0, tid));
-{$ENDIF}
- end; // if
+ mir_forkThread(@ThreadServer, Pointer(hMainThread));
end;
{ exported functions }
diff --git a/plugins/ShlExt/shlext.dpr b/plugins/ShlExt/shlext.dpr index f8a9cb0420..32d1eab0c7 100644 --- a/plugins/ShlExt/shlext.dpr +++ b/plugins/ShlExt/shlext.dpr @@ -1,4 +1,4 @@ -{$IFDEF FPC} +{$IFDEF FPC}
{$PACKRECORDS 4}
{$MODE Delphi}
{$ASMMODE intel}
@@ -384,13 +384,12 @@ end; {$R shldlgs.res}
exports
-
MirandaPluginInfoEx, Load, Unload;
exports
-
DllGetClassObject, DllCanUnloadNow, DllRegisterServer, DllUnregisterServer;
-begin
+initialization
+ DisableThreadLibraryCalls(hInstance);
-end. +end.
|