[cairo] cairo_matrix_t

Owen Taylor otaylor at redhat.com
Thu Nov 4 11:39:13 PST 2004


On Thu, 2004-11-04 at 14:02 -0500, Carl Worth wrote:
> On Tue, 7 Sep 2004 09:25:31 -0700, Bill Spitzak wrote:
> > The only good reason for the current implementation is for thread safety. But  
> > really, if another thread is going to change the matrix in your cairo 
> > context, you still can't guarantee that the one you copied is in fact the 
> > current one, so I don't see what this possibly buys you.
> 
> There's a bit more to it than that though. The current cairo
> implementation makes it very easy to write a thread-safe program, but it
> doesn't mean that multiple threads can call into the same cairo_t object
> willy-nilly. See below.
> 
> >                                                          In fact I would 
> > prefer if cairo contexts (or any other objects, such as surfaces or windows) 
> > had no guarantee of thread safety except that using seperate objects is 
> > thread-safe. Multiple threaded programs must either use different objects per
> > thread, or do their own locking. I would think this would be a much more 
> > efficient implementation.
> 
> What you prefer is actually what we have right now. In order to get a
> thread-safe program you have to use independent cairo_t objects in each
> thread or else do your own locking.
> 
> The benefit of the current implementation is that locking is only needed
> on a per-object basis, (ie. two threads calling in through the same
> cairo_t* or the same cairo_matrix_t*, etc.). But, if we were to make
> cairo_current_matrix return a non-copied pointer to the CTM inside the
> cairo_t, then we've changed that model. Then, locking would be necessary
> between one thread with that cairo_matrix_t* and another with the
> original cairo_t*.

I'm not sure this is a problem. The rule is basically that if
you call a function that returns a pointer to a non-copied object,
string, etc, that pointer can't be saved, just used immediately.

 old_matrix = cairo_current_matrix (cr);
 cairo_set_matrix (cr, new_matrix);
 do_something_with (old_matrix);

Is just as much a problem, and much more likely than passing off that
matrix to a different thread or using it after unlocking a lock that
was protecting cr.

As long as the rules are consistent, I think people won't have a problem
with them.

(Language bindings with GC probably want to make copies of returned
objects, because they can liberate the caller from the need to manually
free.)

Regards,
					Owen

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/cairo/attachments/20041104/08a39c7b/attachment.pgp


More information about the cairo mailing list