home *** CD-ROM | disk | FTP | other *** search
- {
- Turbo Pascal Unit of Semaphore APIs for NetWare
-
- by Richard S. Sadowsky
-
- Please address questions and comments about this unit to ALL in section 6 of
- the PCVENB forum on Compuserve.
- }
- Unit NetSema;
- interface
-
- uses
- Dos;
-
- type
- SemaphoreName = String[127];
-
- function OpenSemaphore(Name : SemaphoreName; InitialValue : ShortInt;
- var OpenNumber : Byte;
- var SemaHandle : LongInt) : Boolean;
-
- function ExamineSemaphore(Handle : LongInt; var Value : ShortInt;
- var OpenNumber : Byte) : Boolean;
-
- function WaitOnSemaphore(Handle : LongInt; TimeOutValue : Word;
- var TimeOut : Boolean) : Boolean;
-
- function SignalSemaphore(Handle : LongInt; var OverFlow : Boolean) : Boolean;
-
- function CloseSemaphore(Handle : LongInt) : Boolean;
-
- implementation
- type
- DoubleWord = record
- LoWord : Word;
- HiWord : Word;
- end;
-
- function MakeLong(HiWord,LoWord : Word) : LongInt;
- {takes hi and lo words and makes a longint }
- Inline(
- $58/ { pop ax ; pop low word into AX }
- $5A); { pop dx ; pop high word into DX }
-
- function OpenSemaphore(Name : SemaphoreName; InitialValue : ShortInt;
- var OpenNumber : Byte;
- var SemaHandle : LongInt) : Boolean;
- var
- Regs : Registers;
-
- begin
- with Regs do begin
- AX := $C500;
- DS := Seg(Name);
- DX := Ofs(Name);
- CL := InitialValue;
- MsDos(Regs);
- if AL = 0 then begin
- OpenNumber := BL;
- SemaHandle := MakeLong(DX, CX);
- OpenSemaphore := True;
- end
- else
- OpenSemaphore := False
- end;
- end;
-
- function ExamineSemaphore(Handle : LongInt; var Value : ShortInt;
- var OpenNumber : Byte) : Boolean;
-
- var
- Regs : Registers;
- begin
- with Regs do begin
- AX := $C501;
- CX := DoubleWord(Handle).LoWord;
- DX := DoubleWord(Handle).HiWord;
- MsDos(Regs);
- if AL = 0 then begin
- OpenNumber := DL;
- Value := CX;
- ExamineSemaphore := True;
- end
- else
- ExamineSemaphore := False;
- end;
- end;
-
- function WaitOnSemaphore(Handle : LongInt; TimeOutValue : Word;
- var TimeOut : Boolean) : Boolean;
- var
- Regs : Registers;
-
- begin
- with Regs do begin
- AX := $C502;
- CX := DoubleWord(Handle).LoWord;
- DX := DoubleWord(Handle).HiWord;
- BP := TimeOutValue;
- MsDos(Regs);
- TimeOut := False;
- if AL <> 0 then begin
- if AL = $FF then begin
- WaitOnSemaphore := False;
- Exit;
- end
- else
- TimeOut := True;
- end;
- WaitOnSemaphore := True;
- end;
- end;
-
- function SignalSemaphore(Handle : LongInt; var OverFlow : Boolean) : Boolean;
- var
- Regs : Registers;
-
- begin
- with Regs do begin
- AX := $C503;
- CX := DoubleWord(Handle).LoWord;
- DX := DoubleWord(Handle).HiWord;
- MsDos(Regs);
- Overflow := False;
- if AL <> 0 then begin
- if AL = $FF then begin
- SignalSemaphore := False;
- Exit;
- end
- else
- Overflow := True;
- end;
- end;
- SignalSemaphore := True;
- end;
-
- function CloseSemaphore(Handle : LongInt) : Boolean;
- var
- Regs : Registers;
-
- begin
- with Regs do begin
- AX := $C504;
- CX := DoubleWord(Handle).LoWord;
- DX := DoubleWord(Handle).HiWord;
- MsDos(Regs);
- CloseSemaphore := AL = 0;
- end;
- end;
-
- end.