Re: [AD] replace xlock/xunlock with synchronized{}

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



Peter Wang wrote:

On 2006-04-05, Jon Rafkind <workmin@xxxxxxxxxx> wrote:
Would anyone be opposed to replacing all the XLOCK()/XUNLOCK() blocks in the x11 code of Allegro with a #define'd syntax that does the same thing, with preferably the same name as java's sychnronization keyword 'synchronized' ?

Basically do this

#define synchronized for ( XLOCK(); XUNLOCK(); /**/ )

Clever.
Actually the a real working define needs a temporary variable so that the body of the loop gets run once. Im not sure how compliant this is, but it works with gcc 3.4.3:

#define synchronized for( int __l( ! XLOCK() ); __l; __l = 0, XUNLOCK() ) )

All that would be required is if XLOCK() returned a value, 0 for success and 1 for failure.

and then instead of

int _xwin_create_window(void)
{
 int result;
 XLOCK();
 result = (*_xwin_window_creator)();
 XUNLOCK();
 return result;
}

would be

int _xwin_create_window(void)
{
 int result;
 synchronized{
     result = (*_xwin_window_creator)();
  }
 return result;
}

Yes I use Java a lot these days and I find this very clean. Plus it would prevent the mistake of forgetting to use XUNLOCK() occasionally.

Unfortunately there is the risk of incorrect but seemingly correct code
like this:

   synchronized {
	if (foo) {
	    return 1;
	}
   }

Well.. yea I suppose that could happen. Im willing to let it slide if other people can too.




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