You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by st...@apache.org on 2002/03/06 03:47:34 UTC

cvs commit: apr/file_io/win32 open.c readwrite.c

stoddard    02/03/05 18:47:34

  Modified:    .        CHANGES
               file_io/win32 open.c readwrite.c
  Log:
  Win32: Fix APR_XTHREAD support. A thread should have its own unique
  apr_file_t structure (and its own io event and overlapped structure)
  when doing cross thread overlapped i/o. The only application using this
  support that I am aware of is the Apache 2.0 file handle cache.
  
  Revision  Changes    Path
  1.231     +6 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.230
  retrieving revision 1.231
  diff -u -r1.230 -r1.231
  --- CHANGES	28 Feb 2002 03:33:37 -0000	1.230
  +++ CHANGES	6 Mar 2002 02:47:33 -0000	1.231
  @@ -1,4 +1,10 @@
   Changes with APR b1
  +  *) Win32: Fix APR_XTHREAD problems in apr_file_read()
  +     and apr_file_write(). Multiple threads were using the
  +     same overlapped structure and io event handle created
  +     in the open call, which could cause unpredictable
  +     file i/o results. [Bill Stoddard]
  +
     *) Win32: apr_proc_mutex_trylock and apr_proc_mutex_lock were 
        incorrectly returning APR_BUSY if the lock was previously
        held by a thread that exited before releasing the lock 
  
  
  
  1.96      +0 -8      apr/file_io/win32/open.c
  
  Index: open.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/win32/open.c,v
  retrieving revision 1.95
  retrieving revision 1.96
  diff -u -r1.95 -r1.96
  --- open.c	13 Feb 2002 02:28:00 -0000	1.95
  +++ open.c	6 Mar 2002 02:47:34 -0000	1.96
  @@ -392,14 +392,6 @@
           (*new)->mutex = NULL;
       }
   
  -    if (flag & APR_XTHREAD) {
  -        /* This win32 specific feature is required to pass
  -         * the current offset for an overlaped file handle.
  -         */
  -        (*new)->pOverlapped = (OVERLAPPED*) apr_pcalloc(cont, sizeof(OVERLAPPED));
  -        (*new)->pOverlapped->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  -    }
  -
       (*new)->pipe = 0;
       (*new)->timeout = -1;
       (*new)->ungetchar = -1;
  
  
  
  1.65      +28 -0     apr/file_io/win32/readwrite.c
  
  Index: readwrite.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/win32/readwrite.c,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -r1.64 -r1.65
  --- readwrite.c	28 Dec 2001 23:50:48 -0000	1.64
  +++ readwrite.c	6 Mar 2002 02:47:34 -0000	1.65
  @@ -168,6 +168,20 @@
           return APR_SUCCESS;
       }
   
  +    /* If the file is open for xthread support, allocate and
  +     * initialize the overlapped and io completion event (hEvent). 
  +     * Threads should NOT share an apr_file_t or its hEvent.
  +     */
  +    if ((thefile->flags & APR_XTHREAD) && !thefile->pOverlapped ) {
  +        thefile->pOverlapped = (OVERLAPPED*) apr_pcalloc(thefile->cntxt, 
  +                                                         sizeof(OVERLAPPED));
  +        thefile->pOverlapped->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  +        if (!thefile->pOverlapped->hEvent) {
  +            rv = apr_get_os_error();
  +            return rv;
  +        }
  +    }
  +
       /* Handle the ungetchar if there is one */
       if (thefile->ungetchar != -1) {
           bytes_read = 1;
  @@ -238,6 +252,20 @@
   {
       apr_status_t rv;
       DWORD bwrote;
  +
  +    /* If the file is open for xthread support, allocate and
  +     * initialize the overlapped and io completion event (hEvent). 
  +     * Threads should NOT share an apr_file_t or its hEvent.
  +     */
  +    if ((thefile->flags & APR_XTHREAD) && !thefile->pOverlapped ) {
  +        thefile->pOverlapped = (OVERLAPPED*) apr_pcalloc(thefile->cntxt, 
  +                                                         sizeof(OVERLAPPED));
  +        thefile->pOverlapped->hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  +        if (!thefile->pOverlapped->hEvent) {
  +            rv = apr_get_os_error();
  +            return rv;
  +        }
  +    }
   
       if (thefile->buffered) {
           char *pos = (char *)buf;