You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Philip Martin <ph...@codematters.co.uk> on 2006/08/09 21:33:33 UTC

Re: svn commit: r21016 - in trunk: . subversion/include/private subversion/libsvn_fs_base/bdb subversion/libsvn_subr

rooneg@tigris.org writes:

> Author: rooneg
> Date: Tue Aug  8 08:34:59 2006
> New Revision: 21016

> + * Call an initialization function in a thread-safe manner.
> + *
> + * @a global_status must be a pointer to a global, zero-initialized 
> + * #svn_atomic_t. @a init_func is a pointer to the function that performs
> + * the actual initialization.
> + *
> + * @since New in 1.5.
> + */
> +svn_error_t *
> +svn_atomic_init_once(volatile svn_atomic_t *global_status,
> +                     svn_error_t *(*init_func)(void));

Will this always be used in places where no parameters need to be
passed?  How about:

   svn_error_t *
   svn_atomic_init_once(volatile svn_atomic_t *global_status,
                        svn_error_t *(*init_func)(void *baton),
                        void *baton);

-- 
Philip Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: svn commit: r21016 - in trunk: . subversion/include/private subversion/libsvn_fs_base/bdb subversion/libsvn_subr

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 8/9/06, Daniel Rall <dl...@collab.net> wrote:
> On Wed, 09 Aug 2006, Philip Martin wrote:
>
> > rooneg@tigris.org writes:
> >
> > > Author: rooneg
> > > Date: Tue Aug  8 08:34:59 2006
> > > New Revision: 21016
> >
> > > + * Call an initialization function in a thread-safe manner.
> > > + *
> > > + * @a global_status must be a pointer to a global, zero-initialized
> > > + * #svn_atomic_t. @a init_func is a pointer to the function that performs
> > > + * the actual initialization.
> > > + *
> > > + * @since New in 1.5.
> > > + */
> > > +svn_error_t *
> > > +svn_atomic_init_once(volatile svn_atomic_t *global_status,
> > > +                     svn_error_t *(*init_func)(void));
> >
> > Will this always be used in places where no parameters need to be
> > passed?  How about:
> >
> >    svn_error_t *
> >    svn_atomic_init_once(volatile svn_atomic_t *global_status,
> >                         svn_error_t *(*init_func)(void *baton),
> >                         void *baton);
>
> I like Philip's suggestion -- it's a more forward-looking API.

Generally, if it's something that only has to occur once it's a global
initialization, which means you're initializing globals, so a baton is
unnecessary, but I suppose someone might come up with a reason to pass
one in, so sure, why not.  Will look at adding one.

-garrett

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: svn commit: r21016 - in trunk: . subversion/include/private subversion/libsvn_fs_base/bdb subversion/libsvn_subr

Posted by Daniel Rall <dl...@collab.net>.
On Wed, 09 Aug 2006, Philip Martin wrote:

> rooneg@tigris.org writes:
> 
> > Author: rooneg
> > Date: Tue Aug  8 08:34:59 2006
> > New Revision: 21016
> 
> > + * Call an initialization function in a thread-safe manner.
> > + *
> > + * @a global_status must be a pointer to a global, zero-initialized 
> > + * #svn_atomic_t. @a init_func is a pointer to the function that performs
> > + * the actual initialization.
> > + *
> > + * @since New in 1.5.
> > + */
> > +svn_error_t *
> > +svn_atomic_init_once(volatile svn_atomic_t *global_status,
> > +                     svn_error_t *(*init_func)(void));
> 
> Will this always be used in places where no parameters need to be
> passed?  How about:
> 
>    svn_error_t *
>    svn_atomic_init_once(volatile svn_atomic_t *global_status,
>                         svn_error_t *(*init_func)(void *baton),
>                         void *baton);

I like Philip's suggestion -- it's a more forward-looking API.

Re: svn commit: r21016 - in trunk: . subversion/include/private subversion/libsvn_fs_base/bdb subversion/libsvn_subr

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 8/9/06, Philip Martin <ph...@codematters.co.uk> wrote:
> Greg Hudson <gh...@MIT.EDU> writes:
>
> > On Aug 9, 2006, at 5:33 PM, Philip Martin wrote:
> >>
> >> Will this always be used in places where no parameters need to be
> >> passed?  How about:
> >>
> >>    svn_error_t *
> >>    svn_atomic_init_once(volatile svn_atomic_t *global_status,
> >>                         svn_error_t *(*init_func)(void *baton),
> >>                         void *baton);
> >
> > Huh.  Can you think of a case where it makes sense to pass parameters
> > to an atomic initialization function?  My intuition is that if you
> > want to do that, your designed is subtly wrong.
>
> I suppose that's possible, but I think of the code:
>
> svn_error_t *foo(....)
> {
>   ...
>   SVN_ERR(svn_atomic_init_once(&once, some_func));
>   ...
> }
>
> as more-or-less equivalent to:
>
> svn_error_t *foo(....)
> {
>   ...
>   SVN_ERR(some_func());
>   ...
> }
>
> and it doesn't seem unreasonable to pass arguments to some_func.
> Suppose we wanted to use the application's apr_allocator_t when
> creating top-level pools in some_func?  Using a global variable might
> work, but in that case we probably wouldn't need svn_atomic_init_once
> in the first place.

Realistically, I don't think this is a likely use case, but
fortunately, it doesn't matter.  This is not a public interface, we
are not installing the header that describes it, so we can change it
later if it ever becomes necessary.

-garrett

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: svn commit: r21016 - in trunk: . subversion/include/private subversion/libsvn_fs_base/bdb subversion/libsvn_subr

Posted by Philip Martin <ph...@codematters.co.uk>.
Greg Hudson <gh...@MIT.EDU> writes:

> On Aug 9, 2006, at 5:33 PM, Philip Martin wrote:
>>
>> Will this always be used in places where no parameters need to be
>> passed?  How about:
>>
>>    svn_error_t *
>>    svn_atomic_init_once(volatile svn_atomic_t *global_status,
>>                         svn_error_t *(*init_func)(void *baton),
>>                         void *baton);
>
> Huh.  Can you think of a case where it makes sense to pass parameters
> to an atomic initialization function?  My intuition is that if you
> want to do that, your designed is subtly wrong.

I suppose that's possible, but I think of the code:

svn_error_t *foo(....)
{
  ...
  SVN_ERR(svn_atomic_init_once(&once, some_func));
  ...
}

as more-or-less equivalent to:

svn_error_t *foo(....)
{
  ...
  SVN_ERR(some_func());
  ...
}

and it doesn't seem unreasonable to pass arguments to some_func.
Suppose we wanted to use the application's apr_allocator_t when
creating top-level pools in some_func?  Using a global variable might
work, but in that case we probably wouldn't need svn_atomic_init_once
in the first place.

-- 
Philip Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: svn commit: r21016 - in trunk: . subversion/include/private subversion/libsvn_fs_base/bdb subversion/libsvn_subr

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On 8/9/06, Daniel Rall <dl...@collab.net> wrote:
> On Wed, 09 Aug 2006, Greg Hudson wrote:
>
> > On Aug 9, 2006, at 5:33 PM, Philip Martin wrote:
> > >
> > >Will this always be used in places where no parameters need to be
> > >passed?  How about:
> > >
> > >   svn_error_t *
> > >   svn_atomic_init_once(volatile svn_atomic_t *global_status,
> > >                        svn_error_t *(*init_func)(void *baton),
> > >                        void *baton);
> >
> > Huh.  Can you think of a case where it makes sense to pass parameters
> > to an atomic initialization function?  My intuition is that if you
> > want to do that, your designed is subtly wrong.
>
> Garrett also wrote:
>
> > Generally, if it's something that only has to occur once it's a
> > global initialization, which means you're initializing globals, so a
> > baton is unnecessary, but I suppose someone might come up with a
> > reason to pass one in, so sure, why not.  Will look at adding one.
>
> What if you needed to pass in some state (e.g. pool-like thing,
> context, whatever) to determine how to initialize the globals?

Any pool used to initialize globals is probably also global.  I mean
it doesn't have to be, but you'd have to be careful to make sure that
when the pool was destroyed you NULL out the globals that allocated
memory in them, and there'd be nasty thread safety isses, and so on...

-garrett

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: svn commit: r21016 - in trunk: . subversion/include/private subversion/libsvn_fs_base/bdb subversion/libsvn_subr

Posted by Daniel Rall <dl...@collab.net>.
On Wed, 09 Aug 2006, Greg Hudson wrote:

> On Aug 9, 2006, at 5:33 PM, Philip Martin wrote:
> >
> >Will this always be used in places where no parameters need to be
> >passed?  How about:
> >
> >   svn_error_t *
> >   svn_atomic_init_once(volatile svn_atomic_t *global_status,
> >                        svn_error_t *(*init_func)(void *baton),
> >                        void *baton);
> 
> Huh.  Can you think of a case where it makes sense to pass parameters  
> to an atomic initialization function?  My intuition is that if you  
> want to do that, your designed is subtly wrong.

Garrett also wrote:

> Generally, if it's something that only has to occur once it's a
> global initialization, which means you're initializing globals, so a
> baton is unnecessary, but I suppose someone might come up with a
> reason to pass one in, so sure, why not.  Will look at adding one.

What if you needed to pass in some state (e.g. pool-like thing,
context, whatever) to determine how to initialize the globals?

Re: svn commit: r21016 - in trunk: . subversion/include/private subversion/libsvn_fs_base/bdb subversion/libsvn_subr

Posted by Greg Hudson <gh...@MIT.EDU>.
On Aug 9, 2006, at 5:33 PM, Philip Martin wrote:
>
> Will this always be used in places where no parameters need to be
> passed?  How about:
>
>    svn_error_t *
>    svn_atomic_init_once(volatile svn_atomic_t *global_status,
>                         svn_error_t *(*init_func)(void *baton),
>                         void *baton);

Huh.  Can you think of a case where it makes sense to pass parameters  
to an atomic initialization function?  My intuition is that if you  
want to do that, your designed is subtly wrong.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org