source: 2.19_branch/Sibyl/Addon/SYNCCOMP.PAS@ 376

Last change on this file since 376 was 7, checked in by RBRi, 19 years ago

+ sibyl staff

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1Unit SyncComp;
2
3{ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
4 º º
5 º Sibyl Portable Component Classes º
6 º º
7 º Delphi 3 compatible synchronisation components º º
8 º Copyright (C) 1995,97 SpeedSoft Germany, All rights reserved. º
9 º Portions Copyright (C) 1997 Borland Inc. º
10 º º
11 ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍŒ}
12
13
14Interface
15
16Uses Classes;
17
18{$IFDEF OS2}
19Uses BseDos,BseErr;
20{$ENDIF}
21{$IFDEF WIN32}
22Uses WinNT,WinBase;
23{$ENDIF}
24
25Type
26 TSynchroObject = class(TObject)
27 Public
28 Procedure Acquire; virtual;
29 Procedure Release; virtual;
30 End;
31
32 TWaitResult = (wrSignaled, wrTimeout, wrAbandoned, wrError);
33
34 TEvent = class(TObject)
35 Private
36 FHandle: LongWord;
37 FLastError: LongInt;
38 Public
39 Constructor Create(ManualReset,InitialState: Boolean;Const Name: String);
40 Function WaitFor(Timeout: Longint): TWaitResult;
41 Procedure SetEvent;
42 Procedure ResetEvent;
43 Destructor Destroy; Override;
44 Property LastError: LongInt read FLastError;
45 Property Handle: LongWord read FHandle;
46 End;
47
48 TSimpleEvent = class(TEvent)
49 Public
50 Constructor Create;
51 End;
52
53 TCriticalSection = class(TSynchroObject)
54 {$IFDEF WIN32}
55 Private
56 FSection:CRITICAL_SECTION;
57 {$ENDIF}
58 Public
59 Procedure Acquire; Override;
60 Procedure Release; Override;
61 Procedure Enter;
62 Procedure Leave;
63 Constructor Create;Virtual;
64 Destructor Destroy;Override;
65 End;
66
67
68Implementation
69
70Procedure TSynchroObject.Acquire;
71Begin
72End;
73
74Procedure TSynchroObject.Release;
75Begin
76End;
77
78Constructor TEvent.Create(ManualReset,InitialState: Boolean; Const Name: String);
79Var c:CString;
80Begin
81 c:=Name;
82 {$IFDEF OS2}
83 DosCreateEventSem(c,FHandle,0,InitialState);
84 {$ENDIF}
85 {$IFDEF WIN32}
86 FHandle:=CreateEvent(Nil,ManualReset,InitialState,c);
87 {$ENDIF}
88End;
89
90Destructor TEvent.Destroy;
91Begin
92 {$IFDEF OS2}
93 If FHandle<>0 Then DosCloseEventSem(FHandle);
94 {$ENDIF}
95 {$IFDEF WIN32}
96 If FHandle<>0 Then CloseHandle(FHandle);
97 {$ENDIF}
98 Inherited Destroy;
99End;
100
101Function TEvent.WaitFor(Timeout: Longint): TWaitResult;
102Var Err:LongInt;
103Begin
104 {$IFDEF OS2}
105 Err:= DosWaitEventSem(Handle, Timeout);
106 Case Err of
107 ERROR_INTERRUPT: Result := wrAbandoned;
108 0: Result := wrSignaled;
109 ERROR_TIMEOUT: Result := wrTimeout;
110 Else
111 Begin
112 Result := wrError;
113 FLastError := Err;
114 End;
115 End;
116 {$ENDIF}
117 {$IFDEF WIN32}
118 Case WaitForSingleObject(Handle,Timeout) Of
119 WAIT_ABANDONED: Result := wrAbandoned;
120 WAIT_OBJECT_0: Result := wrSignaled;
121 WAIT_TIMEOUT: Result := wrTimeout;
122 Else
123 Begin
124 Result := wrError;
125 FLastError := GetLastError;
126 End;
127 End;
128 {$ENDIF}
129End;
130
131Procedure TEvent.SetEvent;
132Begin
133 {$IFDEF OS2}
134 DosPostEventSem(Handle);
135 {$ENDIF}
136 {$IFDEF WIN32}
137 WinBase.SetEvent(FHandle);
138 {$ENDIF}
139End;
140
141Procedure TEvent.ResetEvent;
142Var PostCount:LongWord;
143Begin
144 {$IFDEF OS2}
145 DosResetEventSem(Handle,PostCount);
146 {$ENDIF}
147 {$IFDEF WIN32}
148 WinBase.ResetEvent(FHandle);
149 {$ENDIF}
150End;
151
152Constructor TSimpleEvent.Create;
153Begin
154 {$IFDEF OS2}
155 FHandle := DosCreateEventSem(Nil,FHandle,0,False);
156 {$ENDIF}
157 {$IFDEF WIN32}
158 FHandle:=CreateEvent(Nil,True,False,Nil);
159 {$ENDIF}
160End;
161
162Constructor TCriticalSection.Create;
163Begin
164 Inherited Create;
165
166 {$IFDEF WIN32}
167 InitializeCriticalSection(FSection);
168 {$ENDIF}
169End;
170
171Procedure TCriticalSection.Acquire;
172Begin
173 {$IFDEF OS2}
174 DosEnterCritSec;
175 {$ENDIF}
176 {$IFDEF WIN32}
177 EnterCriticalSection(FSection);
178 {$ENDIF}
179End;
180
181Procedure TCriticalSection.Release;
182Begin
183 {$IFDEF OS2}
184 DosExitCritSec;
185 {$ENDIF}
186 {$IFDEF WIN32}
187 LeaveCriticalSection(FSection);
188 {$ENDIF}
189End;
190
191Destructor TCriticalSection.Destroy;
192Begin
193 {$IFDEF WIN32}
194 DeleteCriticalSection(FSection);
195 {$ENDIF}
196 Inherited Destroy;
197End;
198
199Procedure TCriticalSection.Enter;
200Begin
201 Acquire;
202End;
203
204Procedure TCriticalSection.Leave;
205Begin
206 Release;
207End;
208
209
210Initialization
211End.
Note: See TracBrowser for help on using the repository browser.