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

Comparing ibx/trunk/runtime/winipc.inc (file contents):
Revision 33 by tony, Sat Jul 18 12:30:52 2015 UTC vs.
Revision 37 by tony, Mon Feb 15 14:44:25 2016 UTC

# Line 21 | Line 21 | type
21    private
22      function GetSa: PSecurityAttributes;
23    protected
24 <    FInitialiser: boolean;  static;
24 >    class var FInitialiser: boolean;
25      FSa : TSecurityAttributes;
26    private
27      Sd : TSecurityDescriptor;
# Line 143 | Line 143 | type
143      FOwner: TGlobalInterface;
144      FEvent: THandle;
145      FLockCount: PInteger;
146 <    function GetLockCount: integer;
146 >    FMutex: TMutex;
147 >   function GetLockCount: integer;
148    public
149      constructor Create(EventName: string; AOwner: TGlobalInterface);
150      destructor Destroy; override;
# Line 340 | Line 341 | begin
341    inherited Create;
342    FOwner := AOwner;
343    FLockCount := PInteger(FOwner.SharedMemory.Allocate(sizeof(FLockCount)));
344 +  FMutex := TMutex.Create(EventName + '.Mutex');
345    if FInitialiser then
346    begin
347      FEvent := CreateEvent(sa, true, true, PChar(EventName));
# Line 354 | Line 356 | end;
356  
357   destructor TMultilockGate.Destroy;
358   begin
359 +  if assigned(FMutex) then FMutex.Free;
360    CloseHandle(FEvent);
361    inherited Destroy;
362   end;
# Line 365 | Line 368 | end;
368  
369   procedure TMultilockGate.Lock;
370   begin
371 <  InterlockedIncrement(FLockCount^);
372 <  ResetEvent(FEvent);
371 >  FMutex.Lock;
372 >  try
373 >    Inc(FLockCount^);
374 >    ResetEvent(FEvent);
375 >  finally
376 >    FMutex.Unlock;
377 >  end;
378    //writeln('Lock '+IntToStr(FLockCount^));
379   end;
380  
381   procedure TMultilockGate.Unlock;
382   begin
383    //writeln('Start UnLock '+IntToStr(FLockCount^));
384 <  InterlockedDecrement(FLockCount^);
385 <  if FLockCount^ <= 0 then
386 <  begin
387 <     SetEvent(FEvent);
388 <     FLockCount^ := 0
384 >  FMutex.Lock;
385 >  try
386 >    Dec(FLockCount^);
387 >    if FLockCount^ <= 0 then
388 >    begin
389 >       SetEvent(FEvent);
390 >       FLockCount^ := 0
391 >    end;
392 >  finally
393 >    FMutex.Unlock;
394    end;
395    //writeln('UnLock '+IntToStr(FLockCount^));
396   end;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines