List:Commits« Previous MessageNext Message »
From:vvaintroub Date:January 26 2008 1:43am
Subject:bk commit into 6.0 tree (vlad:1.2781)
View as plain text  
Below is the list of changes that have just been committed into a local
6.0 repository of vlad.  When vlad does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-01-25 20:43:31-05:00, vlad@stripped +3 -0
  Windows: Remove mutex synchronization from my_pread()/my_pwrite().
  - implement pread/pwrite with native Windows ReadFile/WriteFile
  - define HAVE_PREAD
  - implement my_lock() with LockFileEx/UnlockFileEx

  include/config-win.h@stripped, 2008-01-25 20:41:42-05:00, vlad@stripped +1 -0
    define HAVE_PREAD on Windows.

  mysys/my_lock.c@stripped, 2008-01-25 20:41:46-05:00, vlad@stripped +39 -20
    Implement my_lock() with native Win32 functions LockFileEx and UnlockFile
    to remove mutex from my_file_info.

  mysys/my_pread.c@stripped, 2008-01-25 20:41:49-05:00, vlad@stripped +71 -1
    Implement pread() and pwrite() with native Windows functions, remove
    thread serialization from my_pread/my_pwrite.

diff -Nrup a/include/config-win.h b/include/config-win.h
--- a/include/config-win.h	2007-10-30 09:18:42 -04:00
+++ b/include/config-win.h	2008-01-25 20:41:42 -05:00
@@ -325,6 +325,7 @@ inline double ulonglong2double(ulonglong
 #endif /* _WIN64 */
 
 #define HAVE_PERROR
+#define HAVE_PREAD
 #define HAVE_VFPRINT
 #define HAVE_RENAME		/* Have rename() as function */
 #define HAVE_BINARY_STREAMS	/* Have "b" flag in streams */
diff -Nrup a/mysys/my_lock.c b/mysys/my_lock.c
--- a/mysys/my_lock.c	2006-12-23 14:19:46 -05:00
+++ b/mysys/my_lock.c	2008-01-25 20:41:46 -05:00
@@ -48,6 +48,10 @@ int my_lock(File fd, int locktype, my_of
 #ifdef __NETWARE__
   int nxErrno;
 #endif
+#ifdef __WIN__
+  DWORD lastError;
+#endif
+
   DBUG_ENTER("my_lock");
   DBUG_PRINT("my",("Fd: %d  Op: %d  start: %ld  Length: %ld  MyFlags: %d",
 		   fd,locktype,(long) start,(long) length,MyFlags));
@@ -97,29 +101,42 @@ int my_lock(File fd, int locktype, my_of
         DBUG_RETURN(0);
     }
   }
-#elif defined(HAVE_LOCKING)
-  /* Windows */
+#elif defined(__WIN__)
   {
-    my_bool error= FALSE;
-    pthread_mutex_lock(&my_file_info[fd].mutex);
-    if (MyFlags & MY_SEEK_NOT_DONE) 
+    
+    LARGE_INTEGER liOffset,liLength;
+    DWORD dwFlags;
+    OVERLAPPED ov= {0};
+    HANDLE hFile= (HANDLE)_get_osfhandle(fd);
+
+    lastError= 0;
+
+    liOffset.QuadPart= start;
+    liLength.QuadPart= length;
+
+    ov.Offset=      liOffset.LowPart;
+    ov.OffsetHigh=  liOffset.HighPart;
+
+    if (locktype == F_UNLCK)
     {
-      if( my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags & ~MY_SEEK_NOT_DONE))
-           == MY_FILEPOS_ERROR )
-      {
-        /*
-          If my_seek fails my_errno will already contain an error code;
-          just unlock and return error code.
-         */
-        DBUG_PRINT("error",("my_errno: %d (%d)",my_errno,errno));
-        pthread_mutex_unlock(&my_file_info[fd].mutex);
-        DBUG_RETURN(-1);
-      }
+      /* The lock flags are currently ignored by Windows */
+      if(UnlockFileEx(hFile, 0, liLength.LowPart, liLength.HighPart, &ov))
+        DBUG_RETURN(0);
+      else
+        lastError= GetLastError();
     }
-    error= locking(fd,locktype,(ulong) length) && errno != EINVAL;
-    pthread_mutex_unlock(&my_file_info[fd].mutex);
-    if (!error)
-      DBUG_RETURN(0);
+    else if (locktype == F_RDLCK)
+        /* read lock is mapped to a shared lock. */
+        dwFlags= 0;
+    else
+        /* write lock is mapped to an exclusive lock. */
+        dwFlags= LOCKFILE_EXCLUSIVE_LOCK;
+
+    if (MyFlags & MY_DONT_WAIT)
+       dwFlags|= LOCKFILE_FAIL_IMMEDIATELY;
+
+    if (LockFileEx(hFile, dwFlags, 0, liLength.LowPart, liLength.HighPart, &ov))
+        DBUG_RETURN(0);
   }
 #else
 #if defined(HAVE_FCNTL)
@@ -171,6 +188,8 @@ int my_lock(File fd, int locktype, my_of
 
 #ifdef __NETWARE__
   my_errno = nxErrno;
+#elif defined(__WIN__)
+  my_errno = (lastError == ERROR_IO_PENDING)? EAGAIN:lastError?lastError : -1;
 #else
 	/* We got an error. We don't want EACCES errors */
   my_errno=(errno == EACCES) ? EAGAIN : errno ? errno : -1;
diff -Nrup a/mysys/my_pread.c b/mysys/my_pread.c
--- a/mysys/my_pread.c	2007-05-31 10:45:16 -04:00
+++ b/mysys/my_pread.c	2008-01-25 20:41:49 -05:00
@@ -16,8 +16,78 @@
 #include "mysys_priv.h"
 #include "mysys_err.h"
 #include <errno.h>
-#ifdef HAVE_PREAD
+#if defined (HAVE_PREAD) && !defined(__WIN__)
 #include <unistd.h>
+#endif
+
+#ifdef __WIN__
+extern void  _dosmaperr(DWORD);
+
+/*
+  Positional read and write on Windows.
+
+  NOTE: this functions require NT-based kernel and can read/write at most
+  4GB at once.
+*/
+size_t pread(File Filedes, uchar *Buffer, size_t Count, my_off_t offset)
+{
+  DWORD         nBytesRead;
+  HANDLE        hFile;
+  OVERLAPPED    ov={0};
+  LARGE_INTEGER li;
+
+  if(!Count)
+    return 0;
+#ifdef _WIN64
+  if(Count > UINT_MAX)
+    Count = UINT_MAX;
+#endif
+
+  hFile=         (HANDLE)_get_osfhandle(Filedes);
+  li.QuadPart=   offset;
+  ov.Offset=     li.LowPart;
+  ov.OffsetHigh= li.HighPart;
+
+  if(!ReadFile(hFile, Buffer, (DWORD)Count, &nBytesRead, &ov))
+  {
+    DWORD lastError = GetLastError();
+    if(lastError == ERROR_HANDLE_EOF)
+       return 0; /*return 0 at EOF*/
+    _dosmaperr(lastError);
+    return -1;
+  }
+  else
+    return nBytesRead;
+}
+
+size_t pwrite(File Filedes, const uchar *Buffer, size_t Count, my_off_t offset)
+{
+  DWORD         nBytesWritten;
+  HANDLE        hFile;
+  OVERLAPPED    ov={0};
+  LARGE_INTEGER li;
+
+  if(!Count)
+    return 0;
+
+#ifdef _WIN64
+  if(Count > UINT_MAX)
+    Count = UINT_MAX;
+#endif
+
+  hFile=         (HANDLE)_get_osfhandle(Filedes);
+  li.QuadPart=   offset;
+  ov.Offset=     li.LowPart;
+  ov.OffsetHigh= li.HighPart;
+
+  if(!WriteFile(hFile, Buffer, (DWORD)Count, &nBytesWritten, &ov))
+  {
+    _dosmaperr(GetLastError());
+    return -1;
+  }
+  else
+    return nBytesWritten;
+}
 #endif
 
 /*
Thread
bk commit into 6.0 tree (vlad:1.2781)vvaintroub26 Jan