/*
    (C) 1995-96 AROS - The Amiga Replacement OS
    $Id: permit.s,v 1.5 1996/12/11 10:07:50 aros Exp $

    Desc: Exec function Permit
    Lang: english
*/

/******************************************************************************

    NAME
        AROS_LH0(void, Permit,

    LOCATION
        struct ExecBase *, SysBase, 23, Exec)

    FUNCTION
	This function activates the dispatcher again after a call to Permit().

    INPUTS

    RESULT

    NOTES
	This function preserves all registers.
    EXAMPLE

    BUGS

    SEE ALSO
	Forbid(), Disable(), Enable()
	
    INTERNALS

    HISTORY

******************************************************************************/

	#include "machine.i"

	.text
	.balign 16
	.globl	AROS_SLIB_ENTRY(Permit,Exec)
	.type	AROS_SLIB_ENTRY(Permit,Exec),@function
AROS_SLIB_ENTRY(Permit,Exec):
	/* Preserve used registers */
	move.l	%a6,-(%sp)

	/* Get SysBase */
	move.l	8(%sp),%a6

	/* Decrement and test TDNestCnt */
	subq.b	#1,TDNestCnt(%a6)
	jpl	.noswch

	/* return if there are no delayed switches pending. */
	btst	#7,AttnResched+1(%a6)
	jeq	.noswch

	/* if IDNestCnt is not -1 taskswitches are still forbidden */
	tst.b	IDNestCnt(%a6)
	jpl	.noswch

	/* Unset delayed switch bit and do the delayed switch */
	bclr	#7,AttnResched+1(%a6)
	move.l	%a6,-(%sp)
	jsr	Switch(%a6)
	addq	#4,%sp
	
	/* all done. */
.noswch:
	move.l	(%sp)+,%a6
	rts

