psithreadmgrdefault.pas

来自「一个delphi的p2p控件的源代码」· PAS 代码 · 共 54 行

PAS
54
字号
unit PsiThreadMgrDefault;

//******************************************************************************
// The original software is under
// Copyright (c) 1993 - 2000, Chad Z. Hower (Kudzu)
//   and the Indy Pit Crew - http://www.nevrona.com/Indy/
//
// Amended : November 2000, by Michael M. Michalak MACS for use with
// MorphTek.com Inc Peer to Peer Open Source Components - http://www.morphtek.com
//
//******************************************************************************

interface

uses
  PsiThread, PsiThreadMgr;

type
  TPsiThreadMgrDefault = class(TPsiThreadMgr)
  public
    function GetThread: TPsiThread; override;
    procedure ReleaseThread(AThread: TPsiThread); override;
  end;

implementation

uses
  PsiGlobal;

{ TPsiThreadMgrDefault }

function TPsiThreadMgrDefault.GetThread: TPsiThread;
begin
  result := CreateNewThread;
  Lock.Enter; try
    ActiveThreads.Add(result);
  finally Lock.Leave; end;
end;

procedure TPsiThreadMgrDefault.ReleaseThread(AThread: TPsiThread);
begin
  if not IsCurrentThread(AThread) then begin
    AThread.TerminateAndWaitFor;
    AThread.Free;
  end else begin
    AThread.FreeOnTerminate := True;
  end;
  Lock.Enter; try
    ActiveThreads.Remove(AThread);
  finally Lock.Leave; end;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?