;       SCCSID = @(#)fshare.asm 6.1 90/11/17
;      SCCSID = @(#)fshare.asm  13.9 90/02/10
TITLE   SHARING ROUTINES - Routines for file Sharing
NAME    SHARE

;***    fshare
;
;
;       Global
;
;       Share_Violation
;       Violation_Delay_Retry
;
;   MODIFICATION HISTORY:
;    - 11/27/95 - MLM defect 72417
;                 moved from PTDA to TCB:
;                 RetryCount, ShareRetriesLeft
;
.xlist
include dosseg.inc
include basemaca.inc
include osmaca.inc
.xcref
include dossymc.inc
include buffer.inc
include sft.inc
include harderr.inc
include error.inc
include sigdef.inc
include except.inc
include vpb.inc
include mi.inc
include proc.inc
include infoseg.inc
include osconst.inc
include pgexport.inc
include tkexport.inc
.cref
.list
        CpuMode 386

        ReferTask       ptda_ForcedActions,DWORD
                                                ;72417 removed PTDA entries now
                                                ;      in TCB
        ReferTask       CurrTCB,WORD
        ReferTask       ExtErr,WORD
        EXTRNFAR        HardError

        FARCODE HIGH2
HIGH2CODE SEGMENT
    ASSUME  SS:TASKAREA

;***    Share_Violation - Handle Sharing errors
;***    Violation_Delay_Retry - process a hard error with retry postponed
;
;       If the retry count is exhausted, call the hard error handler
;       to process a sharing violation.  Retries are made to look like
;       a Fail after indicating that the system call should be restarted.
;
;       ENTRY   AX has error code: sharing-violation or no-sharing-space
;               ShareRetriesLeft - number of retries left to do before we
;                                  call the hard error handler
;
;               ES:DI -> Offending SFT
;
;       EXIT    ptda_ForcedActions = TK_FF_RTRY if we are to retry the operation
;
;       USES    Share_Violation: AX, SI.
;
;               Violation_Delay_Retry: AX, SI, flags
;
;       WARNING  ** Neither Share_Violation nor Violation_Delay_Retry     **
;                ** should ever be called for a protected mode process!!! **
;

Procedure   Share_Violation
    ASSUME  DS:NOTHING, ES:NOTHING, SS:TASKAREA
        push    bp
        mov     bp,[CurrTCB]
        mov     [bp].TCBAllowed,ALLOWED_FAIL + ALLOWED_RETRY
        pop     bp
        mov     [ExtErr],ax             ; set the extended error for HardError
        mov     ax,HEShare

Entry   Violation_Delay_Retry
                                   ;72417 moved from PTDA to TCB
        SetBP_CurrTCB
        dec     [bp].TCBShareRetriesLeft ; decrement retry count
        UnSetBP_CurrTCB
        jg      short vdr3              ; still some left
        SetBP_CurrTCB
        push    [bp].TCBRetryCount
        pop     [bp].TCBShareRetriesLeft
        UnSetBP_CurrTCB
                                   ;72417 end
        SaveReg <ds>
        push    es                      ; (ds:si) -> SFT
        pop     ds
        mov     si,di
        CALLFAR HardError               ; (ax=type,ds:si=SFT,ExtErr,TCBAllowed)
        RestoreReg <ds>
        jc      short vdr4

;       Retry - turn it into Fail and retry later

vdr3:   or      [ptda_ForcedActions],TK_FF_RTRY
        mov     si,[CurrTCB]
        push    [ExtErr]
        pop     ss:[si].TCBFailErr
vdr4:   stc
        ret
EndProc   Share_Violation

HIGH2CODE ENDS
        END
