📄 threadsectionut.pas
字号:
unit ThreadSectionUt;
interface
uses
Windows,SysUtils,Classes,SyncObjs;
type
TThreadCallBackProc = procedure ;
type
TTSU_CriticalSection = class(TObject)
private
t_threadCun:integer;
cs,cs1:TCriticalSection;
t_Proc: Pointer;
t_Msg:string;
public
procedure Enter;
procedure Leave;
procedure Reset;
procedure SetCallBackPoint(FProc:Pointer);
procedure SetThreadMsg(tMsg:string);
function GetThreadCun:integer;
function GetThreadMsg:string;
constructor Create;
{ Public declarations }
end;
implementation
{ TSIU_CriticalSection }
constructor TTSU_CriticalSection.Create;
begin
inherited Create;
self.cs1:=TCriticalSection.Create;
self.cs:=TCriticalSection.Create;
self.t_threadCun:=0;
self.t_Msg:='';
self.t_Proc:=nil;
end;
procedure TTSU_CriticalSection.SetThreadMsg(tMsg:string);
begin
self.t_Msg:=tMsg;
end;
function TTSU_CriticalSection.GetThreadMsg:string;
begin
Result:=self.t_Msg;
end;
procedure TTSU_CriticalSection.Reset;
begin
self.cs1.Leave;
self.cs.Leave;
self.cs1.Free;
self.cs.Free;
self.cs1:=TCriticalSection.Create;
self.cs:=TCriticalSection.Create;
self.t_threadCun:=0;
self.t_Msg:='';
self.t_Proc:=nil;
end;
procedure TTSU_CriticalSection.Enter;
begin
self.cs1.Enter;
try
self.t_threadCun:=self.t_threadCun+1;
if self.t_Proc<>nil then
TThreadCallBackProc(t_Proc);
except
end;
self.cs1.Leave;
self.cs.Enter;
end;
procedure TTSU_CriticalSection.Leave;
begin
self.cs.Leave;
self.cs1.Enter;
self.t_threadCun:=self.t_threadCun-1;
if self.t_Proc<>nil then
TThreadCallBackProc(t_Proc);
self.cs1.Leave;
end;
function TTSU_CriticalSection.GetThreadCun: integer;
begin
Result:=self.t_threadCun;
end;
procedure TTSU_CriticalSection.SetCallBackPoint(FProc:Pointer);
begin
self.t_Proc:=FProc;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -