ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/runtime/nongui/winipc.inc
(Generate patch)

Comparing ibx/trunk/runtime/nongui/winipc.inc (file contents):
Revision 319 by tony, Thu Feb 25 12:05:40 2021 UTC vs.
Revision 321 by tony, Thu Feb 25 12:10:07 2021 UTC

# Line 11 | Line 11 | const
11      'FB.SQL.MONITOR.ReadEvent1_0',
12      'FB.SQL.MONITOR.ReadFinishedEvent1_0'
13    );
14 <  cDefaultTimeout = 1000; {seconds }
14 >  cDefaultTimeout = 10000; {milli seconds }
15  
16   type
17    {Interprocess Communication Objects. All platform dependent IPC is abstracted
# Line 21 | Line 21 | type
21  
22    TIpcCommon = class(TInterfacedObject)
23    protected
24    class var FInitialiser: boolean;
24      FSa : TSecurityAttributes;
25    private
26      Sd : TSecurityDescriptor;
# Line 49 | Line 48 | type
48  
49    }
50  
51 +  ISharedMemory = interface
52 +  ['{db77bdd4-233a-4c9c-9212-dd7945e2e57c}']
53 +  function IsInitialiser: boolean;
54 +  function Allocate(Size: integer): PByte;
55 +  function GetLastAllocationSize: integer;
56 +  property LastAllocationSize: integer read GetLastAllocationSize;
57 +  end;
58 +
59 +
60    TSharedMemory = class(TIpcCommon,ISharedMemory)
61    private
62      FBuffer: PByte;
# Line 56 | Line 64 | type
64      FUnused: integer;
65      FBufptr: PByte;
66      FSharedBuffer: THandle;
67 +    FInitialiser: boolean;
68      procedure GetSharedMemory(MemSize: integer);
69    public
70      constructor Create(MemSize: integer);
71      destructor Destroy; override;
72      function Allocate(Size: integer): PByte;
73      function GetLastAllocationSize: integer;
74 +    function IsInitialiser: boolean;
75      property LastAllocationSize: integer read GetLastAllocationSize;
76    end;
77  
# Line 71 | Line 81 | type
81    private
82      FMutex: THandle;
83    public
84 <    constructor Create(MutexName: string);
84 >    constructor Create(MutexName: string; IsInitialiser: boolean);
85      destructor Destroy; override;
86      procedure Lock;
87      procedure Unlock;
# Line 102 | Line 112 | type
112    private
113      FEvent: THandle;
114    public
115 <    constructor Create(EventName: string);
115 >    constructor Create(EventName: string; IsInitialiser: boolean);
116      destructor Destroy; override;
117      procedure PassthroughGate;
118      procedure Unlock;
# Line 188 | Line 198 | type
198      function GetReadFinishedEvent: IMultiLockGate;
199      function GetWriteLock: IMutex;
200      function GetMonitorCount: integer;
191    function GetSharedMemory: ISharedMemory;
201      function GetMaxBufferSize: integer;
202      property DataAvailableEvent: ISingleLockGate read GetDataAvailableEvent;
203      property WriterBusyEvent: ISingleLockGate read GetWriterBusyEvent;
# Line 196 | Line 205 | type
205      property ReadFinishedEvent: IMultiLockGate read GetReadFinishedEvent;
206      property WriteLock: IMutex read GetWriteLock;
207      property MonitorCount: integer read GetMonitorCount;
199    property SharedMemory: ISharedMemory read GetSharedMemory;
208      property MaxBufferSize: integer read GetMaxBufferSize;
209    end;
210  
# Line 259 | Line 267 | begin
267    Result := FLastAllocationSize;
268   end;
269  
270 + function TSharedMemory.IsInitialiser: boolean;
271 + begin
272 +  Result := FInitialiser;
273 + end;
274 +
275   { TIpcCommon }
276  
277   function TIpcCommon.GetSa: PSecurityAttributes;
# Line 281 | Line 294 | end;
294  
295    { TMutex }
296  
297 < constructor TMutex.Create(MutexName: string);
297 > constructor TMutex.Create(MutexName: string; IsInitialiser: boolean);
298   begin
299    inherited Create;
300 <  if FInitialiser then
300 >  if IsInitialiser then
301      FMutex := CreateMutex(sa, False, PChar(MutexName))
302    else
303      FMutex := OpenMutex(MUTEX_ALL_ACCESS, False, PChar(MutexName));
# Line 314 | Line 327 | begin
327   end;
328  
329   { TSingleLockGate }
330 < constructor TSingleLockGate.Create(EventName: string);
330 > constructor TSingleLockGate.Create(EventName: string; IsInitialiser: boolean);
331   begin
332    inherited Create;
333 <  if FInitialiser then
333 >  if IsInitialiser then
334      FEvent := CreateEvent(sa, true, true, PAnsiChar(EventName))
335    else
336      FEvent := OpenEvent(EVENT_ALL_ACCESS, true, PAnsiChar(EventName));
# Line 355 | Line 368 | begin
368    inherited Create;
369    FSharedMemory := sm;
370    FLockCount := PInteger(FSharedMemory.Allocate(sizeof(FLockCount)));
371 <  FMutex := TMutex.Create(EventName + '.Mutex');
372 <  if FInitialiser then
371 >  FMutex := TMutex.Create(EventName + '.Mutex',FSharedMemory.IsInitialiser);
372 >  if FSharedMemory.IsInitialiser then
373    begin
374      FEvent := CreateEvent(sa, true, true, PChar(EventName));
375      FLockCount^ := 0;
# Line 385 | Line 398 | begin
398    Result := FOnGateTimeout;
399   end;
400  
401 < procedure TMultilockGate.SetOnGateTimeout(AValue: TNotifyEvent);
401 > procedure TMultilockGate.SetOnGateTimeout(aValue: TNotifyEvent);
402   begin
403    FOnGateTimeout := AValue;
404   end;
# Line 443 | Line 456 | begin
456    Result := FMonitorCount^
457   end;
458  
446 function TIPCInterface.GetSharedMemory: ISharedMemory;
447 begin
448  Result := FSharedMemory;
449 end;
450
459   function TIPCInterface.GetMaxBufferSize: integer;
460   begin
461    Result := FMaxBufferSize;
# Line 464 | Line 472 | begin
472    inherited Create;
473    FSharedMemory := TSharedMemory.Create(cMonitorHookSize);
474  
475 <  FWriteLock := TMutex.Create(PChar(MonitorHookNames[0]));
476 <  FDataAvailableEvent := TSingleLockGate.Create(MonitorHookNames[2]);
477 <  FWriterBusyEvent := TSingleLockGate.Create(MonitorHookNames[3]);
475 >  FWriteLock := TMutex.Create(PChar(MonitorHookNames[0]),FSharedMemory.IsInitialiser);
476 >  FDataAvailableEvent := TSingleLockGate.Create(MonitorHookNames[2],FSharedMemory.IsInitialiser);
477 >  FWriterBusyEvent := TSingleLockGate.Create(MonitorHookNames[3],FSharedMemory.IsInitialiser);
478    FReadReadyEvent := TMultiLockGate.Create(MonitorHookNames[4],FSharedMemory);
479    FReadReadyEvent.OnGateTimeout  := HandleGateTimeout;
480    FReadFinishedEvent := TMultiLockGate.Create(MonitorHookNames[5],FSharedMemory);
# Line 474 | Line 482 | begin
482  
483    FMonitorCount := PInteger(FSharedMemory.Allocate(sizeof(FMonitorCount)));
484  
485 <  if FInitialiser then
485 >  if FSharedMemory.IsInitialiser then
486      FMonitorCount^ := 0;
487    FTraceDataType := PInteger(FSharedMemory.Allocate(sizeof(Integer)));
488    FTimeStamp := PDateTime(FSharedMemory.Allocate(sizeof(TDateTime)));
# Line 483 | Line 491 | begin
491    FBuffer := FSharedMemory.Allocate(0); //All remaining
492    FMaxBufferSize := FSharedMemory.LastAllocationSize;
493  
494 <  if FInitialiser then
494 >  if FSharedMemory.IsInitialiser then
495    begin
496      FBufferSize^ := 0;
497      FDataAvailableEvent.Lock;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines