You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Garrett Rooney <ro...@electricjellyfish.net> on 2002/07/05 21:23:22 UTC

problem with apr_atomic_init on freebsd

so for the first time in like forever, i reinstalled my development
machine and thus had to download fresh copies of subversion and apr.

it seems that apr's configure script is now disabling threads by
default on FreeBSD, which is fine, since i'm not actually using
threads, but there appears to be a few kinks with the atomics code.

if i don't pass '--enable-threads' to configure, when i get around to
compiling subversion it fails to link because it's looking for
apr_atomic_init. 

here's the error i get:

cd subversion/clients/cmdline && /usr/local/bin/bash /home/rooneg/svn/libtool --silent --mode=link  gcc -D_REENTRANT -D_THREAD_SAFE  -g -Wall -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -DNEON_SSL -Wpointer-arith -Wwrite-strings -Wshadow -DSVN_DEBUG -DAP_DEBUG   -I./subversion/include -I.  -I/usr/home/rooneg/svn/apr/include -I/usr/home/rooneg/svn/apr-util/include -I/home/rooneg/svn/apr-util/include -I/usr/local/include/db4 -I/usr/local/include -I/usr/local/include/neon -I/usr/local/include/db4 -L/usr/local/lib  -rpath /usr/local/lib -o svn  add-cmd.o checkout-cmd.o cleanup-cmd.o commit-cmd.o copy-cmd.o delete-cmd.o diff-cmd.o export-cmd.o feedback.o help-cmd.o import-cmd.o info-cmd.o log-cmd.o main.o merge-cmd.o mkdir-cmd.o move-cmd.o prompt.o propdel-cmd.o propedit-cmd.o propget-cmd.o proplist-cmd.o props.o propset-cmd.o resolve-cmd.o revert-cmd.o status-cmd.o status.o switch-cmd.o update-cmd.o util.o ../../../subversion/libsvn_client/libsvn_client-1.la ../../../subversion/libsvn_wc/libsvn_wc-1.la ../../../subversion/libsvn_ra/libsvn_ra-1.la ../../../subversion/libsvn_delta/libsvn_delta-1.la ../../../subversion/libsvn_subr/libsvn_subr-1.la /usr/home/rooneg/svn/apr-util/libaprutil.la -lexpat /usr/home/rooneg/svn/apr/libapr.la -L/usr/local/lib -lneon -lssl -lcrypto -L/usr/local/lib -lexpat -lm -lcrypt
/usr/home/rooneg/svn/apr/.libs/libapr.a(start.o): In function `apr_initialize':
/usr/home/rooneg/svn/apr/misc/unix/start.c(.text+0x6f): undefined reference to `apr_atomic_init'
*** Error code 1

Stop in /usr/home/rooneg/svn.

it seems like apr_atomic_init should be #defined to APR_SUCCESS in the 
non-threads case or something like that, but after tracing through header 
files for far too long trying to figure out what the hell was going wrong, 
i've got too much of a headache to figure out what the appropriate fix is.

if someone who's a little more familiar with this code could give it a
look, i'd be quite appreciative.

thanks,

-garrett

-- 
garrett rooney                    Remember, any design flaw you're 
rooneg@electricjellyfish.net      sufficiently snide about becomes  
http://electricjellyfish.net/     a feature.       -- Dan Sugalski

Re: problem with apr_atomic_init on freebsd

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On Fri, Jul 05, 2002 at 02:25:45PM -0700, Brian Pane wrote:

> This design would let us handle each atomic API function
> independently of the rest: if a platform has native versions
> of atomic_set and atomic_read, for example, we can use those
> and fall back on the mutex-based C functions for all the other
> operations in the atomic API.

that sounds perfect.  it'll be a LOT easier to read/understand than
the current code ;-)

-garrett 

-- 
garrett rooney                    Remember, any design flaw you're 
rooneg@electricjellyfish.net      sufficiently snide about becomes  
http://electricjellyfish.net/     a feature.       -- Dan Sugalski

Re: problem with apr_atomic_init on freebsd

Posted by Justin Erenkrantz <je...@apache.org>.
On Fri, Jul 05, 2002 at 02:25:45PM -0700, Brian Pane wrote:
> To fix the configuration of atomics more generally, what I'm
> thinking of is a restructuring of apr_atomic.h to look like
> this:

+1.  -- justin

Re: problem with apr_atomic_init on freebsd

Posted by Brian Pane <bp...@pacbell.net>.
On Fri, 2002-07-05 at 14:09, Garrett Rooney wrote:
> On Fri, Jul 05, 2002 at 02:05:41PM -0700, Brian Pane wrote:
> 
> > Here's what I have so far. It's basically the same as what
> > you've described, except that I have an additional check to
> > make sure the apr_atomic_init() isn't already defined as a
> > macro.
> > 
> > Does this work on FreeBSD?
> 
> this works fine here.  while it would be nice if someone could get the
> ifdefs in apr_atomic.h figured out so that we don't need to do this,
> it's not a big deal, and this fixes the build, so i'd say commit it.

Thanks, I just commited the change.

To fix the configuration of atomics more generally, what I'm
thinking of is a restructuring of apr_atomic.h to look like
this:

/* First, platform specific overrides */
#if platform1
  /* #define any atomic functions that have native implementations
   * on platform1
   */
#define apr_atomic_cas(mem, with, cmp) Platform1_CAS(mem, with, cmp)
#define apr_atomic_set(mem, val)       (*mem) = (val)

#elif platform2
  /* #define any atomic functions that have native implementations
   * on platform2
   */
#define apr_atomic_cas(mem, with, cmp) asm(...inline assembly...)
#elif /* etc... */
#endif /* end of platform-specific overrides */

/* Now declare all the functions that haven't 
#if !defined(apr_atomic_add)
void apr_atomic_add(volatile apr_atomic_t *mem, apr_uint32_t val);
#define NEED_ATOMIC_INIT 1
#endif

#if !defined(apr_atomic_inc)
void apr_atomic_inc(volatile apr_atomic_t *mem);
#define NEED_ATOMIC_INIT 1
#endif

/* ...declarations for the rest of the atomic functions... */

/* Finally, decide whether we need a de apr_atomic_init() */
#if NEED_ATOMIC_INIT
apr_status_t apr_atomic_init(apr_pool_t *p);
#else
#define apr_atomic_init(p)   APR_SUCCESS
#endif


This design would let us handle each atomic API function
independently of the rest: if a platform has native versions
of atomic_set and atomic_read, for example, we can use those
and fall back on the mutex-based C functions for all the other
operations in the atomic API.

--Brian



Re: problem with apr_atomic_init on freebsd

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On Fri, Jul 05, 2002 at 02:05:41PM -0700, Brian Pane wrote:

> Here's what I have so far. It's basically the same as what
> you've described, except that I have an additional check to
> make sure the apr_atomic_init() isn't already defined as a
> macro.
> 
> Does this work on FreeBSD?

this works fine here.  while it would be nice if someone could get the
ifdefs in apr_atomic.h figured out so that we don't need to do this,
it's not a big deal, and this fixes the build, so i'd say commit it.

thanks,

-garrett

-- 
garrett rooney                    Remember, any design flaw you're 
rooneg@electricjellyfish.net      sufficiently snide about becomes  
http://electricjellyfish.net/     a feature.       -- Dan Sugalski

Re: problem with apr_atomic_init on freebsd

Posted by Brian Pane <bp...@pacbell.net>.
On Fri, 2002-07-05 at 14:00, Garrett Rooney wrote:
> On Fri, Jul 05, 2002 at 01:49:04PM -0700, Brian Pane wrote:
>  
> > > it's dying because we both #define away apr_atomic_init and declare it
> > > (because freebsd defines APR_ATOMIC_NEED_CAS_DEFAULT).
> > 
> > How about changing atomic/unix/apr_atomic.c so that it defines
> > a no-op apr_atomic_init() if threads are disabled?
> 
> that works, but you'll have to go get rid of all the places that do a
> #define apr_atomic_init APR_SUCCESS, and move the declaration outside
> of the #if defined(APR_ATOMIC_NEED_CAS_DEFAULT).
> 
> then just add:
> 
> #else
> 
> apr_status_t apr_atomic_init(apr_pool_t *p)
> {
>     return APR_SUCCESS;
> }
>  
> right above the #endif /* APR_HAS_THREADS */ in apr_atomic.c.
> 
> it means we always get the function call overhead, but really, it's
> not like apr_atomic_init is going to be called more than once per
> program, so who really cares...
> 
> you'll have to be really careful though, since the platform specific
> #ifdefs are tricky and i don't think i could get them all right without
> having the machines available to test on...

Here's what I have so far. It's basically the same as what
you've described, except that I have an additional check to
make sure the apr_atomic_init() isn't already defined as a
macro.

Does this work on FreeBSD?

--Brian



Re: problem with apr_atomic_init on freebsd

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On Fri, Jul 05, 2002 at 01:49:04PM -0700, Brian Pane wrote:
 
> > it's dying because we both #define away apr_atomic_init and declare it
> > (because freebsd defines APR_ATOMIC_NEED_CAS_DEFAULT).
> 
> How about changing atomic/unix/apr_atomic.c so that it defines
> a no-op apr_atomic_init() if threads are disabled?

that works, but you'll have to go get rid of all the places that do a
#define apr_atomic_init APR_SUCCESS, and move the declaration outside
of the #if defined(APR_ATOMIC_NEED_CAS_DEFAULT).

then just add:

#else

apr_status_t apr_atomic_init(apr_pool_t *p)
{
    return APR_SUCCESS;
}
 
right above the #endif /* APR_HAS_THREADS */ in apr_atomic.c.

it means we always get the function call overhead, but really, it's
not like apr_atomic_init is going to be called more than once per
program, so who really cares...

you'll have to be really careful though, since the platform specific
#ifdefs are tricky and i don't think i could get them all right without
having the machines available to test on...

-garrett

-- 
garrett rooney                    Remember, any design flaw you're 
rooneg@electricjellyfish.net      sufficiently snide about becomes  
http://electricjellyfish.net/     a feature.       -- Dan Sugalski

Re: problem with apr_atomic_init on freebsd

Posted by Brian Pane <bp...@pacbell.net>.
On Fri, 2002-07-05 at 13:44, Garrett Rooney wrote:
> On Fri, Jul 05, 2002 at 01:34:18PM -0700, Brian Pane wrote:
> > On Fri, 2002-07-05 at 12:23, Garrett Rooney wrote:
> > > so for the first time in like forever, i reinstalled my development
> > > machine and thus had to download fresh copies of subversion and apr.
> > > 
> > > it seems that apr's configure script is now disabling threads by
> > > default on FreeBSD, which is fine, since i'm not actually using
> > > threads, but there appears to be a few kinks with the atomics code.
> > 
> > I just added the missing definition of apr_atomic_init() for
> > FreeBSD, so it should be working now.
> 
> unfortunately, that doesn't fix it...  that was the first thing i
> tried ;-)  with that change we don't even compile...
> 
> here's the error message i get now:
> 
> /usr/local/bin/bash /usr/home/rooneg/svn/apr/libtool --silent --mode=compile gcc -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations   -DHAVE_CONFIG_H -D_REENTRANT -D_THREAD_SAFE   -I../../include -I../../include/arch/unix -I../../include/arch/unix  -c start.c && touch start.lo
> In file included from start.c:59:
> ../../include/apr_atomic.h:257: syntax error before `0'
> *** Error code 1
> 
> Stop in /usr/home/rooneg/svn/apr/misc/unix.
> *** Error code 1
> 
> Stop in /usr/home/rooneg/svn/apr/misc/unix.
> *** Error code 1
> 
> Stop in /usr/home/rooneg/svn/apr.
> *** Error code 1
> 
> Stop in /usr/home/rooneg/svn.
> 
> it's dying because we both #define away apr_atomic_init and declare it
> (because freebsd defines APR_ATOMIC_NEED_CAS_DEFAULT).

How about changing atomic/unix/apr_atomic.c so that it defines
a no-op apr_atomic_init() if threads are disabled?

--Brian



Re: problem with apr_atomic_init on freebsd

Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On Fri, Jul 05, 2002 at 01:34:18PM -0700, Brian Pane wrote:
> On Fri, 2002-07-05 at 12:23, Garrett Rooney wrote:
> > so for the first time in like forever, i reinstalled my development
> > machine and thus had to download fresh copies of subversion and apr.
> > 
> > it seems that apr's configure script is now disabling threads by
> > default on FreeBSD, which is fine, since i'm not actually using
> > threads, but there appears to be a few kinks with the atomics code.
> 
> I just added the missing definition of apr_atomic_init() for
> FreeBSD, so it should be working now.

unfortunately, that doesn't fix it...  that was the first thing i
tried ;-)  with that change we don't even compile...

here's the error message i get now:

/usr/local/bin/bash /usr/home/rooneg/svn/apr/libtool --silent --mode=compile gcc -g -O2 -Wall -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations   -DHAVE_CONFIG_H -D_REENTRANT -D_THREAD_SAFE   -I../../include -I../../include/arch/unix -I../../include/arch/unix  -c start.c && touch start.lo
In file included from start.c:59:
../../include/apr_atomic.h:257: syntax error before `0'
*** Error code 1

Stop in /usr/home/rooneg/svn/apr/misc/unix.
*** Error code 1

Stop in /usr/home/rooneg/svn/apr/misc/unix.
*** Error code 1

Stop in /usr/home/rooneg/svn/apr.
*** Error code 1

Stop in /usr/home/rooneg/svn.

it's dying because we both #define away apr_atomic_init and declare it
(because freebsd defines APR_ATOMIC_NEED_CAS_DEFAULT).

still not sure of the correct fix though.  perhaps inside the #if
defined (APR_ATOMIC_NEED_CAS_DEFAULT) case at the bottom of
apr_atomic.h we need to check if we have threads and if not just 
#define apr_atomic_init to APR_SUCCESS?

-garrett 

-- 
garrett rooney                    Remember, any design flaw you're 
rooneg@electricjellyfish.net      sufficiently snide about becomes  
http://electricjellyfish.net/     a feature.       -- Dan Sugalski

Re: problem with apr_atomic_init on freebsd

Posted by Brian Pane <bp...@pacbell.net>.
On Fri, 2002-07-05 at 12:23, Garrett Rooney wrote:
> so for the first time in like forever, i reinstalled my development
> machine and thus had to download fresh copies of subversion and apr.
> 
> it seems that apr's configure script is now disabling threads by
> default on FreeBSD, which is fine, since i'm not actually using
> threads, but there appears to be a few kinks with the atomics code.

I just added the missing definition of apr_atomic_init() for
FreeBSD, so it should be working now.

--Brian



Re: problem with apr_atomic_init on freebsd

Posted by Brian Pane <bp...@pacbell.net>.
On Fri, 2002-07-05 at 12:23, Garrett Rooney wrote:
> so for the first time in like forever, i reinstalled my development
> machine and thus had to download fresh copies of subversion and apr.
> 
> it seems that apr's configure script is now disabling threads by
> default on FreeBSD, which is fine, since i'm not actually using
> threads, but there appears to be a few kinks with the atomics code.
> 
> if i don't pass '--enable-threads' to configure, when i get around to
> compiling subversion it fails to link because it's looking for
> apr_atomic_init. 

That's probably due to my change yesterday to add the atomic_init
to apr_initialize (which keeps us from segfaulting on Linux when
the mutex-based atomics are used).

I'll work on a fix today.

--Brian