-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added
TInterfacedThread
and tests
Also renamed all classes to `TInterfaced*`
- Loading branch information
Showing
13 changed files
with
302 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
unit PolyKerma.Dispatcher.Common; | ||
|
||
{$mode objfpc}{$H+} | ||
|
||
interface | ||
|
||
uses | ||
Classes | ||
; | ||
|
||
const | ||
cDispatcherChannelControllerOut = 'controller.out'; | ||
cDispatcherChannelControllerIn = 'controller.in'; | ||
cDispatcherChannelCommsOut = 'comms.out'; | ||
cDispatcherChannelCommsIn = 'comms.in'; | ||
cDispatcherChannelModelOut = 'model.out'; | ||
cDispatcherChannelModelIn = 'model.in'; | ||
|
||
implementation | ||
|
||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
unit PolyKerma.Threads.Interfaces; | ||
|
||
{$mode ObjFPC}{$H+} | ||
|
||
interface | ||
|
||
uses | ||
Classes | ||
; | ||
|
||
type | ||
{ IThread } | ||
IThread = interface | ||
['{5D340B25-31E7-40C3-A5AB-8AFE68AA31C0}'] | ||
|
||
procedure Start; | ||
procedure Resume; | ||
procedure Terminate; | ||
function WaitFor: Integer; | ||
|
||
end; | ||
|
||
implementation | ||
|
||
end. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
unit PolyKerma.Threads.Thread; | ||
|
||
{$mode ObjFPC}{$H+} | ||
|
||
interface | ||
|
||
uses | ||
Classes | ||
, PolyKerma.Threads.Interfaces | ||
; | ||
|
||
type | ||
|
||
{ TInterfacedThread } | ||
TInterfacedThread = class(TThread, IThread) | ||
protected | ||
FRefCount : longint; | ||
FDestroyCount : longint; | ||
|
||
function QueryInterface( | ||
{$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} iid : tguid;out obj | ||
) : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; | ||
function _AddRef : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; | ||
function _Release : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; | ||
|
||
public | ||
constructor Create(const CreateSuspended: Boolean); reintroduce; | ||
destructor Destroy; override; | ||
|
||
end; | ||
TInterfacedThreadClass = class of TInterfacedThread; | ||
|
||
implementation | ||
|
||
{ TInterfacedThread } | ||
|
||
function TInterfacedThread.QueryInterface( | ||
{$IFDEF FPC_HAS_CONSTREF}constref{$ELSE}const{$ENDIF} iid : tguid;out obj | ||
) : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; | ||
begin | ||
if getinterface(iid,obj) then | ||
Result:= S_OK | ||
else | ||
Result:= longint(E_NOINTERFACE); | ||
end; | ||
|
||
function TInterfacedThread._AddRef: longint; | ||
{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; | ||
begin | ||
Result:= interlockedincrement(FRefCount); | ||
end; | ||
|
||
function TInterfacedThread._Release: longint; | ||
{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF}; | ||
begin | ||
Result:=interlockeddecrement(FRefCount); | ||
if Result = 0 then | ||
begin | ||
if interlockedincrement(FDestroyCount)=1 then | ||
Self.destroy; | ||
end; | ||
end; | ||
|
||
constructor TInterfacedThread.Create(const CreateSuspended: Boolean); | ||
begin | ||
inherited Create(CreateSuspended); | ||
end; | ||
|
||
destructor TInterfacedThread.Destroy; | ||
begin | ||
inherited Destroy; | ||
end; | ||
|
||
end. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.