apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr/locks/win32 proc_mutex.c
Date Thu, 27 Mar 2003 19:51:12 GMT
wrowe       2003/03/27 11:51:12

  Modified:    locks/win32 proc_mutex.c
  Log:
    Win32 needs to do nothing if the file handle is already open in a child
    process, and we are using anonymous proc_mutex or global_mutex methods,
    so win32 should return APR_SUCCESS for proc_mutex_child_init.
  
    We also introduced the kernel 'object' 
folding function for shared memory
    section names, so reuse that folding function here to provide reliable
    Win2K/XP names (prefixed with \global\) and fold away any slashes or
    backslashes from that path.
  
    Based on issues observed by "Andre Schild" <A.Schild@aarboard.ch> with
    the httpd mod_ssl implementation for Win32, with input from Andre and
    JimJ.
  
  Revision  Changes    Path
  1.13      +51 -18    apr/locks/win32/proc_mutex.c
  
  Index: proc_mutex.c
  ===================================================================
  RCS file: /home/cvs/apr/locks/win32/proc_mutex.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- proc_mutex.c	6 Jan 2003 23:44:31 -0000	1.12
  +++ proc_mutex.c	27 Mar 2003 19:51:12 -0000	1.13
  @@ -57,6 +57,7 @@
   #include "apr_general.h"
   #include "apr_strings.h"
   #include "apr_portable.h"
  +#include "apr_arch_file_io.h"
   #include "apr_arch_proc_mutex.h"
   #include "apr_arch_misc.h"
   
  @@ -64,8 +65,10 @@
   {
       apr_proc_mutex_t *mutex = mutex_;
   
  -    if (CloseHandle(mutex->handle) == 0) {
  -        return apr_get_os_error();
  +    if (mutex->handle) {
  +        if (CloseHandle(mutex->handle) == 0) {
  +            return apr_get_os_error();
  +        }
       }
       return APR_SUCCESS;
   }
  @@ -76,21 +79,32 @@
                                                   apr_pool_t *pool)
   {
       HANDLE hMutex;
  +    void *mutexkey;
   
  -    /* With Win2000 Terminal Services, the Mutex name can have a 
  -     * "Global\" or "Local\" prefix to explicitly create the object 
  -     * in the global or session name space.  Without Terminal Service
  -     * running on Win2000, Global\ and Local\ are ignored.  These
  -     * prefixes are only valid on Win2000+
  +    /* res_name_from_filename turns fname into a pseduo-name
  +     * without slashes or backslashes, and prepends the \global
  +     * prefix on Win2K and later
        */
       if (fname) {
  -        if (apr_os_level >= APR_WIN_2000)
  -            fname = apr_pstrcat(pool, "Global\\", fname, NULL);
  -        else
  -            fname = apr_pstrdup(pool, fname);
  +        mutexkey = res_name_from_filename(fname, 1, pool);
  +    }
  +    else {
  +        mutexkey = NULL;
  +    }
  +
  +#if APR_HAS_UNICODE_FS
  +    IF_WIN_OS_IS_UNICODE
  +    {
  +        hMutex = CreateMutexW(NULL, FALSE, mutexkey);
  +    }
  +#endif
  +#if APR_HAS_ANSI_FS
  +    ELSE_WIN_OS_IS_ANSI
  +    {
  +        hMutex = CreateMutexA(NULL, FALSE, mutexkey);
       }
  +#endif
   
  -    hMutex = CreateMutex(NULL, FALSE, fname);
       if (!hMutex) {
   	return apr_get_os_error();
       }
  @@ -109,13 +123,32 @@
                                                       apr_pool_t *pool)
   {
       HANDLE hMutex;
  +    void *mutexkey;
   
  -    if (apr_os_level >= APR_WIN_2000)
  -        fname = apr_pstrcat(pool, "Global\\", fname, NULL);
  -    else
  -        fname = apr_pstrdup(pool, fname);
  +    if (!fname) {
  +        /* Reinitializing unnamed mutexes is a noop in the Unix code. */
  +        return APR_SUCCESS;
  +    }
  +
  +    /* res_name_from_filename turns file into a pseudo-name
  +     * without slashes or backslashes, and prepends the \global
  +     * prefix on Win2K and later
  +     */
  +    mutexkey = res_name_from_filename(fname, 1, pool);
  +
  +#if APR_HAS_UNICODE_FS
  +    IF_WIN_OS_IS_UNICODE
  +    {
  +        hMutex = OpenMutexW(MUTEX_ALL_ACCESS, FALSE, mutexkey);
  +    }
  +#endif
  +#if APR_HAS_ANSI_FS
  +    ELSE_WIN_OS_IS_ANSI
  +    {
  +        hMutex = OpenMutexA(MUTEX_ALL_ACCESS, FALSE, mutexkey);
  +    }
  +#endif
   
  -    hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, fname);
       if (!hMutex) {
   	return apr_get_os_error();
       }
  @@ -174,7 +207,7 @@
   
   APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex)
   {
  -    return "win32mutex";
  +    return mutex->fname;
   }
   
   APR_DECLARE(const char *) apr_proc_mutex_defname(void)
  
  
  

Mime
View raw message