You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by rb...@locus.apache.org on 2000/11/27 22:32:33 UTC

cvs commit: apr/misc/unix start.c

rbb         00/11/27 13:32:25

  Modified:    misc/unix start.c
  Log:
  apr_initialize should only setup apr if this is the first call, and
  apr_terminate should only tear the locks down if this is the final call.
  This allows multiple stand-alone programs that all use APR to be combined
  cleanly without requiring a lot of if statements.  Each program just calls
  apr_initialize and apr_terminate, but only the first and last calls
  respectively do anything.
  Submitted by:	Doug MacEachern <do...@covalent.net>
  
  Revision  Changes    Path
  1.39      +16 -3     apr/misc/unix/start.c
  
  Index: start.c
  ===================================================================
  RCS file: /home/cvs/apr/misc/unix/start.c,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- start.c	2000/08/02 05:26:22	1.38
  +++ start.c	2000/11/27 21:32:14	1.39
  @@ -56,6 +56,8 @@
   #include "locks.h"
   #include "apr_strings.h"
   
  +static int initialized=0;
  +
   apr_status_t apr_create_pool(apr_pool_t **newcont, apr_pool_t *cont)
   {
       apr_pool_t *newpool;
  @@ -138,13 +140,20 @@
   apr_status_t apr_initialize(void)
   {
       apr_status_t status;
  -#if !defined(BEOS) && !defined(OS2) && !defined(WIN32)
  -    apr_unix_setup_lock();
  -#elif defined WIN32
  +#if defined WIN32
       int iVersionRequested;
       WSADATA wsaData;
       int err;
  +#endif
   
  +    if (initialized) {
  +        return APR_SUCCESS;
  +    }
  +    initialized++;
  +
  +#if !defined(BEOS) && !defined(OS2) && !defined(WIN32)
  +    apr_unix_setup_lock();
  +#elif defined WIN32
       iVersionRequested = MAKEWORD(WSAHighByte, WSALowByte);
       err = WSAStartup((WORD) iVersionRequested, &wsaData);
       if (err) {
  @@ -162,6 +171,10 @@
   
   void apr_terminate(void)
   {
  +    initialized--;
  +    if (initialized) {
  +        return;
  +    }
       apr_term_alloc();
   }
   
  
  
  

Re: cvs commit: apr/misc/unix start.c

Posted by rb...@covalent.net.
On Tue, 28 Nov 2000, Greg Ames wrote:

> 
> 
> rbb@locus.apache.org wrote:
> > 
> [...]
> > 
> >   +    if (initialized) {
> >   +        return APR_SUCCESS;
> >   +    }
> >   +    initialized++;
> >   +
> 
> Oooops...this only counts to 1.  Works OK when there's at most 2 APR
> users, but what if there are 3?  We don't want to destroy locks when the
> second user goes away.  How about:
> 
>   if (initialized++) {
>       return APR_SUCCESS;

You're right.  I wrote this section before even thinking about the
termination, and didn't check it after I did the terminating stuff.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: cvs commit: apr/misc/unix start.c

Posted by Greg Ames <gr...@raleigh.ibm.com>.

rbb@locus.apache.org wrote:
> 
[...]
> 
>   +    if (initialized) {
>   +        return APR_SUCCESS;
>   +    }
>   +    initialized++;
>   +

Oooops...this only counts to 1.  Works OK when there's at most 2 APR
users, but what if there are 3?  We don't want to destroy locks when the
second user goes away.  How about:

  if (initialized++) {
      return APR_SUCCESS;

Greg