Browse Source

+ Implemented Win32 of syncobjs

michael 22 years ago
parent
commit
37fd308ddb
2 changed files with 71 additions and 45 deletions
  1. 6 1
      fcl/inc/syncobh.inc
  2. 65 44
      fcl/win32/syncobjs.pp

+ 6 - 1
fcl/inc/syncobh.inc

@@ -53,6 +53,8 @@ type
       procedure SetEvent;
       procedure SetEvent;
       function WaitFor(Timeout : Cardinal) : TWaitResult;
       function WaitFor(Timeout : Cardinal) : TWaitResult;
    end;
    end;
+   
+   TEvent = TEventObject;
 
 
    TSimpleEvent = class(TEventObject)
    TSimpleEvent = class(TEventObject)
       constructor Create;
       constructor Create;
@@ -60,7 +62,10 @@ type
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.4  2002-09-07 15:15:26  peter
+  Revision 1.5  2003-06-11 12:00:09  michael
+  + Implemented Win32 of syncobjs
+
+  Revision 1.4  2002/09/07 15:15:26  peter
     * old logs removed and tabs fixed
     * old logs removed and tabs fixed
 
 
 }
 }

+ 65 - 44
fcl/win32/syncobjs.pp

@@ -12,6 +12,8 @@
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 
  **********************************************************************}
  **********************************************************************}
+{$mode objfpc} 
+{$h+}
 unit syncobjs;
 unit syncobjs;
 
 
   interface
   interface
@@ -24,76 +26,95 @@ unit syncobjs;
       TSecurityAttributes = Windows.TSecurityAttributes;
       TSecurityAttributes = Windows.TSecurityAttributes;
       TEventHandle = THandle;
       TEventHandle = THandle;
 
 
-    {$I syncobh.inc}
+{$I syncobh.inc}
 
 
-  implementation
+implementation
 
 
-    {$I syncob.inc}
+{$I syncob.inc}
 
 
-    procedure TCriticalSection.Acquire;
+procedure TCriticalSection.Acquire;
 
 
-      begin
-         EnterCriticalSection(CriticalSection);
-      end;
+begin
+   EnterCriticalSection(CriticalSection);
+end;
 
 
-    procedure TCriticalSection.Release;
+procedure TCriticalSection.Release;
 
 
-      begin
-         LeaveCriticalSection(CriticalSection);
-      end;
+begin
+   LeaveCriticalSection(CriticalSection);
+end;
 
 
-    constructor TCriticalSection.Create;
+constructor TCriticalSection.Create;
 
 
-      begin
-         inherited Create;
-         InitializeCriticalSection(CriticalSection);
-      end;
+begin
+  inherited Create;
+  InitializeCriticalSection(CriticalSection);
+end;
 
 
-    destructor TCriticalSection.Destroy;
+destructor TCriticalSection.Destroy;
 
 
-      begin
-         DeleteCriticalSection(CriticalSection);
-         inherited Destroy;
-      end;
+begin
+  DeleteCriticalSection(CriticalSection);
+  inherited Destroy;
+end;
 
 
-    destructor THandleObject.destroy;
+destructor THandleObject.destroy;
 
 
-      begin
-         CloseHandle(FHandle);
-         inherited Destroy;
-      end;
+begin
+  CloseHandle(FHandle);
+  inherited Destroy;
+end;
 
 
-    constructor TEvent.Create(EventAttributes : PSecurityAttributes;
-      ManualReset,InitialState : Boolean;const Name : string);
+constructor TEventObject.Create(EventAttributes : PSecurityAttributes;
+  ManualReset,InitialState : Boolean;const Name : string);
 
 
-      begin
-      end;
+begin
+  FHandle := CreateEvent(EventAttributes, ManualReset, InitialState, PChar(Name));
+end;
 
 
-    procedure TEvent.ResetEvent;
+procedure TEventObject.ResetEvent;
 
 
-      begin
-      end;
+begin
+  Windows.ResetEvent(FHandle)
+end;
 
 
-    procedure TEvent.SetEvent;
+procedure TEventObject.SetEvent;
 
 
-      begin
-      end;
+begin
+  Windows.SetEvent(FHandle);
+end;
 
 
-    function TEvent.WaitFor(Timeout : Cardinal) : TWaitResult;
+function TEventObject.WaitFor(Timeout : Cardinal) : TWaitResult;
 
 
-      begin
-      end;
+begin
+  case WaitForSingleObject(Handle, Timeout) of
+    WAIT_ABANDONED: Result := wrAbandoned;
+    WAIT_OBJECT_0: Result := wrSignaled;
+    WAIT_TIMEOUT: Result := wrTimeout;
+    WAIT_FAILED:
+        begin
+        Result := wrError;
+        FLastError := GetLastError;
+       end;
+  else
+    Result := wrError;    
+  end;
+end;
 
 
-    constructor TSimpleEvent.Create;
+constructor TSimpleEvent.Create;
 
 
-      begin
-      end;
+begin
+  FHandle := CreateEvent(nil, True, False, nil);
+end;
 
 
 end.
 end.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.3  2002-09-07 15:15:29  peter
+  Revision 1.4  2003-06-11 11:59:52  michael
+  + Implemented Win32 of syncobjs
+
+  Revision 1.3  2002/09/07 15:15:29  peter
     * old logs removed and tabs fixed
     * old logs removed and tabs fixed
 
 
-}
+}