| @@ -46,13 +46,10 @@ type | |||
| TutlSynchronousMessage = class(TutlMessage) | |||
| private | |||
| fEvent: TEvent; | |||
| fFreeOnFinish: Boolean; | |||
| fLock: Integer; | |||
| procedure Lock; | |||
| procedure Unlock; | |||
| public | |||
| procedure Finish; | |||
| function WaitFor(const aTimeout: Cardinal): TWaitResult; | |||
| constructor Create(const aID: Cardinal; const aWParam, aLParam: PtrInt); overload; | |||
| constructor Create(const {%H-}aID: Cardinal; const aArgs: TObject; const aOwnsObjects: Boolean = true); overload; | |||
| destructor Destroy; override; | |||
| @@ -108,57 +105,30 @@ end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| //TutlSynchronousMessage////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| procedure TutlSynchronousMessage.Lock; | |||
| begin | |||
| repeat until (InterLockedExchange(fLock, 1) = 0); | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| procedure TutlSynchronousMessage.Unlock; | |||
| begin | |||
| InterLockedExchange(fLock, 0); | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| procedure TutlSynchronousMessage.Finish; | |||
| begin | |||
| fEvent.SetEvent; | |||
| Lock; | |||
| if fFreeOnFinish then | |||
| Free | |||
| else | |||
| Unlock; | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| function TutlSynchronousMessage.WaitFor(const aTimeout: Cardinal): TWaitResult; | |||
| begin | |||
| Lock; | |||
| try | |||
| result := fEvent.WaitFor(aTimeout); | |||
| fFreeOnFinish := (result <> wrSignaled); | |||
| finally | |||
| Unlock; | |||
| end; | |||
| result := fEvent.WaitFor(aTimeout); | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| constructor TutlSynchronousMessage.Create(const aID: Cardinal; const aWParam, aLParam: PtrInt); | |||
| begin | |||
| inherited Create(aID, aWParam, aLParam); | |||
| fEvent := TEvent.Create(nil, true, false, ''); | |||
| fFreeOnFinish := false; | |||
| fLock := 0; | |||
| fEvent := TEvent.Create(nil, true, false, ''); | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| constructor TutlSynchronousMessage.Create(const aID: Cardinal; const aArgs: TObject; const aOwnsObjects: Boolean); | |||
| begin | |||
| inherited Create(ID, aArgs, aOwnsObjects); | |||
| fEvent := TEvent.Create(nil, true, false, ''); | |||
| fFreeOnFinish := false; | |||
| fLock := 0; | |||
| fEvent := TEvent.Create(nil, true, false, ''); | |||
| end; | |||
| //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||