Re: [AD] spin lock in xvtable.c

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> > In all the functions in xvtable.c, the first line of code is
> > essentially a semaphore to allow for reentrant calls( i guess to
> > make it multithreaded which it cant do anyway ).
> 
> This is indeed a semaphore, but not really for reentrant calls. It is
> intended to detect when low-level drawing functions are called by
> high-level drawing functions (for example, hline() by triangle()),
> thus allowing to bypass the clipping and updating codes for the
> lower-level functions in this situation, which results in a huge
> speed-up for the X11 driver.
> 

Sorry for the incompetence, but I dont understand exactly whats going on
here. This is what it looks like to me:
When the X11 driver is loaded, it copies all the vtable functions to
_xwin_vtable, then loads all the xwin functions into the vtable passed
as a paramter. Then, when a function like putpixel is called, the
xwin_putpixel is instead called which in turn calls the
_xwin_vtable.putpixel which is the *original* putpixel in vtable passed
to _xwin_replace_vtable. Is the only point of this to add the line
_xwin_update_video_bitmap? Im not sure what this function does, but it
seems that its the only addition to the X11 functions. In that case, I
could see how if _xwin_in_gfx_call being set to 1 would enable
_xwin_vtable.func to be called twice, once right after
_xwin_in_gfx_call = 1;
_xwin_vtable.func();

and once in intial if statement such that both calls will be placed
before _xwin_update_video_bitmap is called thus saving time and energy.
What I dont get is, how could two functions be running at the same time?
It is known that allegro cant be multithreaded, so doesnt that enforce
the function to complete without having to worry about placing another
call in between _xwin_in_gfx_call=1 and _xwin_in_gfx_call=0?

Also, if the the function does get called a second time but the first
function finished the _xwin_vtable.func function right before the second
function starts the _xwin_vtable.func function, then
_xwin_update_video_bitmap would be called once after the first function
finishes, but would need to be called again after the second function
finishes. Should the functions be changed to something like this:

void _xwin_func(){

	if ( _xwin_in_gfx_call ){
		_xwin_vtable.func();
		if ( _xwin_in_gfx_call == 0 )
			_xwin_update_video_bitmap();
		return;
	}

	_xwin_in_gfx_call = 1;
	_xwin_vtable.func();
	_xwin_update_video_bitmap();
	_xwin_in_gfx_call = 0;

}

Im not exactly sure if _xwin_in_gfx_call=0 should come before or after
_xwin_update_video_bitmap. Mmm, come to think of it, what if 3 of the
same function was invoked. If two of them finish _xwin_vtable.func() and
get _xwin_update_video_bitmap called to finalize whatever it does, then
the third one would get screwed and not have _xwin_update_video_bitmap
called for it.

Am I totally off? Sorry, just trying to help!
later--,
jon




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/