New attempt to get the svn revision into the AboutAROS requester.
[cake.git] / rom / graphics / ownblitter.c
blobcd9b566655382e75c417931d10c468cd919bad7d
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Try to own the blitter for private usage
6 Lang: english
7 */
9 #include <proto/exec.h>
10 #include <graphics/gfxbase.h>
11 #include <exec/execbase.h>
12 #include <exec/tasks.h>
14 /*****************************************************************************
16 NAME */
17 #include <proto/graphics.h>
19 AROS_LH0(void, OwnBlitter,
21 /* SYNOPSIS */
24 /* LOCATION */
25 struct GfxBase *, GfxBase, 76, Graphics)
27 /* FUNCTION
28 The blitter is allocated for exclusive use by the calling task.
29 This function returns immediately if no other task is using
30 the blitter right now or if no blits are in the queues (QBlit(),
31 QBSBlit()). Otherwise the function will block until the blitter
32 can be accessed.
33 It is good practice to start the blitter immediately after calling
34 this function and then call DisownBlitter() so other tasks can
35 use the blitter.
37 INPUTS
39 RESULT
41 NOTES
43 EXAMPLE
45 BUGS
47 SEE ALSO
48 DisownBlitter()
50 INTERNALS
52 HISTORY
54 ******************************************************************************/
56 AROS_LIBFUNC_INIT
58 /* prevent other tasks from doing what I am doing */
59 struct Task * me;
61 me = FindTask(NULL);
63 Forbid();
65 /* test whether a task is using the blitter. Even if the blitter is
66 used by the queued blits now the BlitOwner entry must not be NULL!
69 if (NULL == GfxBase->BlitOwner)
71 /* nobody is using the blitter right now, so I can use it */
72 GfxBase->BlitOwner=me;
74 else
76 BOOL first = TRUE;
77 /* the blitter is used. I have to set this task asleep and queue
78 it into the BlitWaitQ.
81 /* Repeat this as long as there is somebody else using the blitter.
82 This is necessary as when the other task calls DisownBlitter() it
83 might take a while until this task gets to run again and
84 yet another taks might issue QBlit() in the meantime and the blitter
85 might be busy with that. So this task will have to wait again.
86 However at the first call this task is put to the end of the waiting
87 list and after that it is always put at the very front.
89 while (NULL != GfxBase->BlitOwner)
91 /* force this task to sleep */
93 BYTE old_TDNestCnt = SysBase->TDNestCnt;
94 SysBase->TDNestCnt=-1;
96 /*
97 Move it to the waiting list in the GfxBase structure.
98 It will be moved to the ready list by the blitterinterrupt
99 handler.
101 if (first)
103 AddTail(&GfxBase->BlitWaitQ, &me->tc_Node);
104 /* The next time I will put this task at the beginning
105 of the list, if necessary.
107 first = FALSE;
109 else
111 AddHead(&GfxBase->BlitWaitQ, &me->tc_Node);
114 /* Switch to the next ready task. */
115 Switch();
117 OK. Somebody awakened me. This means that I the task might now
118 have full control over the blitter. Checking is in the while-loop.
121 /* Restore TDNestCnt. */
122 SysBase->TDNestCnt=old_TDNestCnt;
123 } /* while () */
124 /* I am the owner now !! */
125 Disable();
126 GfxBase -> BlitOwner = me;
127 Enable();
130 Permit();
132 AROS_LIBFUNC_EXIT
133 } /* OwnBlitter */