Commit of the code which was suggested by Georg as a fix for:
[cake.git] / rom / exec / permit.c
blob8d4452a165f080d965d11607d89fb7396a2146e9
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Permit() - Allow tasks switches to occur.
6 Lang: english
7 */
9 #include <exec/types.h>
10 #include <exec/execbase.h>
11 #include <aros/libcall.h>
12 #include <aros/atomic.h>
13 #include <proto/exec.h>
15 /*****************************************************************************/
16 #undef Exec
17 #ifdef UseExecstubs
18 # define Exec _Exec
19 #endif
21 /* NAME */
23 AROS_LH0(void, Permit,
25 /* LOCATION */
26 struct ExecBase *, SysBase, 23, Exec)
28 /* FUNCTION
29 This function will reactivate the task dispatcher after a call
30 to Forbid(). Note that calls to Forbid() nest, and for every
31 call to Forbid() you need a matching call to Permit().
33 INPUTS
34 None.
36 RESULT
37 Multitasking will be re-enabled.
39 NOTES
40 This function preserves all registers.
42 To prevent deadlocks calling Wait() in forbidden state breaks
43 the forbid - thus taskswitches may happen again.
45 EXAMPLE
46 No you really don't want to use this function.
48 BUGS
49 The only architecture that you can rely on the registers being
50 saved is on the Motorola mc68000 family.
52 SEE ALSO
53 Forbid(), Disable(), Enable(), Wait()
55 INTERNALS
56 If you want to preserve all the registers, replace this function
57 in your $(KERNEL) directory. Otherwise this function is
58 satisfactory.
60 ******************************************************************************/
62 #undef Exec
64 AROS_LIBFUNC_INIT
67 Task switches are allowed again, if a switch is pending, we
68 should allow it.
70 #if 1
71 AROS_ATOMIC_DEC(SysBase->TDNestCnt);
72 #else
73 AROS_ATOMIC_DEC(SysBase->TDNestCnt);
75 if( ( SysBase->TDNestCnt < 0 )
76 && ( SysBase->IDNestCnt < 0 )
77 && ( SysBase->AttnResched & 0x80 ) )
79 /* Haha, you re-enabled multitasking, only to have the rug
80 pulled out from under you feet :)
82 Clear the Switch() pending flag.
85 Disable();
86 SysBase->AttnResched &= ~0x80;
87 Switch();
88 Enable();
90 #endif
92 AROS_LIBFUNC_EXIT
93 } /* Permit() */