summaryrefslogtreecommitdiff
path: root/ndb/src/common/portlib/win32
diff options
context:
space:
mode:
Diffstat (limited to 'ndb/src/common/portlib/win32')
-rw-r--r--ndb/src/common/portlib/win32/Makefile30
-rw-r--r--ndb/src/common/portlib/win32/NdbCondition.c184
-rw-r--r--ndb/src/common/portlib/win32/NdbDaemon.c44
-rw-r--r--ndb/src/common/portlib/win32/NdbEnv.c33
-rw-r--r--ndb/src/common/portlib/win32/NdbHost.c53
-rw-r--r--ndb/src/common/portlib/win32/NdbMem.c237
-rw-r--r--ndb/src/common/portlib/win32/NdbMutex.c78
-rw-r--r--ndb/src/common/portlib/win32/NdbSleep.c35
-rw-r--r--ndb/src/common/portlib/win32/NdbTCP.c39
-rw-r--r--ndb/src/common/portlib/win32/NdbThread.c118
-rw-r--r--ndb/src/common/portlib/win32/NdbTick.c64
11 files changed, 915 insertions, 0 deletions
diff --git a/ndb/src/common/portlib/win32/Makefile b/ndb/src/common/portlib/win32/Makefile
new file mode 100644
index 00000000000..bb29ac5547e
--- /dev/null
+++ b/ndb/src/common/portlib/win32/Makefile
@@ -0,0 +1,30 @@
+include .defs.mk
+
+TYPE := util
+
+PIC_ARCHIVE := Y
+ARCHIVE_TARGET := portlib
+
+SOURCES.c = NdbCondition.c \
+ NdbMutex.c \
+ NdbSleep.c \
+ NdbTick.c \
+ NdbEnv.c \
+ NdbThread.c \
+ NdbHost.c \
+ NdbTCP.c \
+ NdbDaemon.c
+
+ifeq ($(NDB_OS), SOFTOSE)
+ SOURCES += NdbMem_SoftOse.cpp
+else
+ SOURCES.c += NdbMem.c
+endif
+
+include $(NDB_TOP)/Epilogue.mk
+
+
+
+
+
+
diff --git a/ndb/src/common/portlib/win32/NdbCondition.c b/ndb/src/common/portlib/win32/NdbCondition.c
new file mode 100644
index 00000000000..12b508cf33b
--- /dev/null
+++ b/ndb/src/common/portlib/win32/NdbCondition.c
@@ -0,0 +1,184 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <windows.h>
+#include <assert.h>
+#include <sys/types.h>
+
+#include "NdbCondition.h"
+#include <NdbMutex.h>
+
+
+struct NdbCondition
+{
+ long nWaiters;
+ NdbMutex* pNdbMutexWaitersLock;
+ HANDLE hSemaphore;
+ HANDLE hEventWaitersDone;
+ int bWasBroadcast;
+};
+
+
+struct NdbCondition*
+NdbCondition_Create(void)
+{
+ int result = 0;
+ struct NdbCondition* pNdbCondition = (struct NdbCondition*)malloc(sizeof(struct NdbCondition));
+ if(!pNdbCondition)
+ return 0;
+
+ pNdbCondition->nWaiters = 0;
+ pNdbCondition->bWasBroadcast = 0;
+ if(!(pNdbCondition->hSemaphore = CreateSemaphore(0, 0, MAXLONG, 0)))
+ result = -1;
+ else if(!(pNdbCondition->pNdbMutexWaitersLock = NdbMutex_Create()))
+ result = -1;
+ else if(!(pNdbCondition->hEventWaitersDone = CreateEvent(0, 0, 0, 0)))
+ result = -1;
+
+ assert(!result);
+ return pNdbCondition;
+}
+
+
+int
+NdbCondition_Wait(struct NdbCondition* p_cond,
+ NdbMutex* p_mutex)
+{
+ int result;
+ int bLastWaiter;
+ if(!p_cond || !p_mutex)
+ return 1;
+
+ NdbMutex_Lock(p_cond->pNdbMutexWaitersLock);
+ p_cond->nWaiters++;
+ NdbMutex_Unlock(p_cond->pNdbMutexWaitersLock);
+
+ if(NdbMutex_Unlock(p_mutex))
+ return -1;
+ result = WaitForSingleObject (p_cond->hSemaphore, INFINITE);
+
+ NdbMutex_Lock(p_cond->pNdbMutexWaitersLock);
+ p_cond->nWaiters--;
+ bLastWaiter = (p_cond->bWasBroadcast && p_cond->nWaiters==0);
+ NdbMutex_Unlock(p_cond->pNdbMutexWaitersLock);
+
+ if(result==WAIT_OBJECT_0 && bLastWaiter)
+ SetEvent(p_cond->hEventWaitersDone);
+
+ NdbMutex_Lock(p_mutex);
+ return result;
+}
+
+
+int
+NdbCondition_WaitTimeout(struct NdbCondition* p_cond,
+ NdbMutex* p_mutex,
+ int msecs)
+{
+ int result;
+ int bLastWaiter;
+ if (!p_cond || !p_mutex)
+ return 1;
+
+ NdbMutex_Lock(p_cond->pNdbMutexWaitersLock);
+ p_cond->nWaiters++;
+ NdbMutex_Unlock(p_cond->pNdbMutexWaitersLock);
+ if(msecs<0)
+ msecs = 0;
+
+ if(NdbMutex_Unlock(p_mutex))
+ return -1;
+ result = WaitForSingleObject(p_cond->hSemaphore, msecs);
+
+ NdbMutex_Lock(p_cond->pNdbMutexWaitersLock);
+ p_cond->nWaiters--;
+ bLastWaiter = (p_cond->bWasBroadcast && p_cond->nWaiters==0);
+ NdbMutex_Unlock(p_cond->pNdbMutexWaitersLock);
+
+ if(result!=WAIT_OBJECT_0)
+ result = -1;
+
+ if(bLastWaiter)
+ SetEvent(p_cond->hEventWaitersDone);
+
+ NdbMutex_Lock(p_mutex);
+ return result;
+}
+
+
+int
+NdbCondition_Signal(struct NdbCondition* p_cond)
+{
+ int bHaveWaiters;
+ if(!p_cond)
+ return 1;
+
+ NdbMutex_Lock(p_cond->pNdbMutexWaitersLock);
+ bHaveWaiters = (p_cond->nWaiters > 0);
+ NdbMutex_Unlock(p_cond->pNdbMutexWaitersLock);
+
+ if(bHaveWaiters)
+ return (ReleaseSemaphore(p_cond->hSemaphore, 1, 0) ? 0 : -1);
+ else
+ return 0;
+}
+
+
+int NdbCondition_Broadcast(struct NdbCondition* p_cond)
+{
+ int bHaveWaiters;
+ int result = 0;
+ if(!p_cond)
+ return 1;
+
+ NdbMutex_Lock(p_cond->pNdbMutexWaitersLock);
+ bHaveWaiters = 0;
+ if(p_cond->nWaiters > 0)
+ {
+ p_cond->bWasBroadcast = !0;
+ bHaveWaiters = 1;
+ }
+ NdbMutex_Unlock(p_cond->pNdbMutexWaitersLock);
+ if(bHaveWaiters)
+ {
+ if(!ReleaseSemaphore(p_cond->hSemaphore, p_cond->nWaiters, 0))
+ result = -1;
+ else if(WaitForSingleObject (p_cond->hEventWaitersDone, INFINITE) != WAIT_OBJECT_0)
+ result = -1;
+ p_cond->bWasBroadcast = 0;
+ }
+ return result;
+}
+
+
+int NdbCondition_Destroy(struct NdbCondition* p_cond)
+{
+ int result;
+ if(!p_cond)
+ return 1;
+
+ CloseHandle(p_cond->hEventWaitersDone);
+ NdbMutex_Destroy(p_cond->pNdbMutexWaitersLock);
+ result = (CloseHandle(p_cond->hSemaphore) ? 0 : -1);
+
+ free(p_cond);
+ return 0;
+}
+
diff --git a/ndb/src/common/portlib/win32/NdbDaemon.c b/ndb/src/common/portlib/win32/NdbDaemon.c
new file mode 100644
index 00000000000..b96d4c20260
--- /dev/null
+++ b/ndb/src/common/portlib/win32/NdbDaemon.c
@@ -0,0 +1,44 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#include "NdbDaemon.h"
+
+#define NdbDaemon_ErrorSize 500
+long NdbDaemon_DaemonPid;
+int NdbDaemon_ErrorCode;
+char NdbDaemon_ErrorText[NdbDaemon_ErrorSize];
+
+int
+NdbDaemon_Make(const char* lockfile, const char* logfile, unsigned flags)
+{
+ // XXX do something
+ return 0;
+}
+
+#ifdef NDB_DAEMON_TEST
+
+int
+main()
+{
+ if (NdbDaemon_Make("test.pid", "test.log", 0) == -1) {
+ fprintf(stderr, "NdbDaemon_Make: %s\n", NdbDaemon_ErrorText);
+ return 1;
+ }
+ sleep(10);
+ return 0;
+}
+
+#endif
diff --git a/ndb/src/common/portlib/win32/NdbEnv.c b/ndb/src/common/portlib/win32/NdbEnv.c
new file mode 100644
index 00000000000..0df703a5e97
--- /dev/null
+++ b/ndb/src/common/portlib/win32/NdbEnv.c
@@ -0,0 +1,33 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+
+#include "NdbEnv.h"
+#include <string.h>
+#include <stdlib.h>
+
+const char* NdbEnv_GetEnv(const char* name, char * buf, int buflen)
+{
+ char* p = NULL;
+ p = getenv(name);
+
+ if (p != NULL && buf != NULL){
+ strncpy(buf, p, buflen);
+ buf[buflen-1] = 0;
+ }
+ return p;
+}
+
diff --git a/ndb/src/common/portlib/win32/NdbHost.c b/ndb/src/common/portlib/win32/NdbHost.c
new file mode 100644
index 00000000000..f91dd1a531c
--- /dev/null
+++ b/ndb/src/common/portlib/win32/NdbHost.c
@@ -0,0 +1,53 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+
+#include "NdbHost.h"
+#include <windows.h>
+#include <process.h>
+
+
+int NdbHost_GetHostName(char* buf)
+{
+ /* We must initialize TCP/IP if we want to call gethostname */
+ WORD wVersionRequested;
+ WSADATA wsaData;
+ int err;
+
+ wVersionRequested = MAKEWORD( 2, 0 );
+ err = WSAStartup( wVersionRequested, &wsaData );
+ if ( err != 0 ) {
+ /**
+ * Tell the user that we couldn't find a usable
+ * WinSock DLL.
+ */
+ return -1;
+ }
+
+ /* Get host name */
+ if(gethostname(buf, MAXHOSTNAMELEN))
+ {
+ return -1;
+ }
+ return 0;
+}
+
+
+int NdbHost_GetProcessId(void)
+{
+ return _getpid();
+}
+
diff --git a/ndb/src/common/portlib/win32/NdbMem.c b/ndb/src/common/portlib/win32/NdbMem.c
new file mode 100644
index 00000000000..274dc31353f
--- /dev/null
+++ b/ndb/src/common/portlib/win32/NdbMem.c
@@ -0,0 +1,237 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+
+#include <windows.h>
+#include <assert.h>
+#include <NdbStdio.h>
+
+#include "NdbMem.h"
+
+
+struct AWEINFO
+{
+ SIZE_T dwSizeInBytesRequested;
+ ULONG_PTR nNumberOfPagesRequested;
+ ULONG_PTR nNumberOfPagesActual;
+ ULONG_PTR nNumberOfPagesFreed;
+ ULONG_PTR* pnPhysicalMemoryPageArray;
+ void* pRegionReserved;
+};
+
+const size_t cNdbMem_nMaxAWEinfo = 256;
+size_t gNdbMem_nAWEinfo = 0;
+
+struct AWEINFO* gNdbMem_pAWEinfo = 0;
+
+
+void ShowLastError(const char* szContext, const char* szFunction)
+{
+ DWORD dwError = GetLastError();
+ LPVOID lpMsgBuf;
+ FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ dwError,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ (LPTSTR)&lpMsgBuf,
+ 0,
+ NULL
+ );
+ printf("%s : %s failed : %lu : %s\n", szContext, szFunction, dwError, (char*)lpMsgBuf);
+ LocalFree(lpMsgBuf);
+}
+
+
+
+void NdbMem_Create()
+{
+ // Address Windowing Extensions
+ struct PRIVINFO
+ {
+ DWORD Count;
+ LUID_AND_ATTRIBUTES Privilege[1];
+ } Info;
+
+ HANDLE hProcess = GetCurrentProcess();
+ HANDLE hToken;
+ if(!OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken))
+ {
+ ShowLastError("NdbMem_Create", "OpenProcessToken");
+ }
+
+ Info.Count = 1;
+ Info.Privilege[0].Attributes = SE_PRIVILEGE_ENABLED;
+ if(!LookupPrivilegeValue(0, SE_LOCK_MEMORY_NAME, &(Info.Privilege[0].Luid)))
+ {
+ ShowLastError("NdbMem_Create", "LookupPrivilegeValue");
+ }
+
+ if(!AdjustTokenPrivileges(hToken, FALSE, (PTOKEN_PRIVILEGES)&Info, 0, 0, 0))
+ {
+ ShowLastError("NdbMem_Create", "AdjustTokenPrivileges");
+ }
+
+ if(!CloseHandle(hToken))
+ {
+ ShowLastError("NdbMem_Create", "CloseHandle");
+ }
+
+ return;
+}
+
+void NdbMem_Destroy()
+{
+ /* Do nothing */
+ return;
+}
+
+void* NdbMem_Allocate(size_t size)
+{
+ // Address Windowing Extensions
+ struct AWEINFO* pAWEinfo;
+ HANDLE hProcess;
+ SYSTEM_INFO sysinfo;
+
+ if(!gNdbMem_pAWEinfo)
+ {
+ gNdbMem_pAWEinfo = VirtualAlloc(0,
+ sizeof(struct AWEINFO)*cNdbMem_nMaxAWEinfo,
+ MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
+ }
+
+ assert(gNdbMem_nAWEinfo < cNdbMem_nMaxAWEinfo);
+ pAWEinfo = gNdbMem_pAWEinfo+gNdbMem_nAWEinfo++;
+
+ hProcess = GetCurrentProcess();
+ GetSystemInfo(&sysinfo);
+ pAWEinfo->nNumberOfPagesRequested = (size+sysinfo.dwPageSize-1)/sysinfo.dwPageSize;
+ pAWEinfo->pnPhysicalMemoryPageArray = VirtualAlloc(0,
+ sizeof(ULONG_PTR)*pAWEinfo->nNumberOfPagesRequested,
+ MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE);
+ pAWEinfo->nNumberOfPagesActual = pAWEinfo->nNumberOfPagesRequested;
+ if(!AllocateUserPhysicalPages(hProcess, &(pAWEinfo->nNumberOfPagesActual), pAWEinfo->pnPhysicalMemoryPageArray))
+ {
+ ShowLastError("NdbMem_Allocate", "AllocateUserPhysicalPages");
+ return 0;
+ }
+ if(pAWEinfo->nNumberOfPagesRequested != pAWEinfo->nNumberOfPagesActual)
+ {
+ ShowLastError("NdbMem_Allocate", "nNumberOfPagesRequested != nNumberOfPagesActual");
+ return 0;
+ }
+
+ pAWEinfo->dwSizeInBytesRequested = size;
+ pAWEinfo->pRegionReserved = VirtualAlloc(0, pAWEinfo->dwSizeInBytesRequested, MEM_RESERVE | MEM_PHYSICAL, PAGE_READWRITE);
+ if(!pAWEinfo->pRegionReserved)
+ {
+ ShowLastError("NdbMem_Allocate", "VirtualAlloc");
+ return 0;
+ }
+
+ if(!MapUserPhysicalPages(pAWEinfo->pRegionReserved, pAWEinfo->nNumberOfPagesActual, pAWEinfo->pnPhysicalMemoryPageArray))
+ {
+ ShowLastError("NdbMem_Allocate", "MapUserPhysicalPages");
+ return 0;
+ }
+
+ /*
+ printf("allocate AWE memory: %lu bytes, %lu pages, address %lx\n",
+ pAWEinfo->dwSizeInBytesRequested,
+ pAWEinfo->nNumberOfPagesActual,
+ pAWEinfo->pRegionReserved);
+ */
+ return pAWEinfo->pRegionReserved;
+}
+
+
+void* NdbMem_AllocateAlign(size_t size, size_t alignment)
+{
+ /*
+ return (void*)memalign(alignment, size);
+ TEMP fix
+ */
+ return NdbMem_Allocate(size);
+}
+
+
+void NdbMem_Free(void* ptr)
+{
+ // VirtualFree(ptr, 0, MEM_DECOMMIT|MEM_RELEASE);
+
+ // Address Windowing Extensions
+ struct AWEINFO* pAWEinfo = 0;
+ size_t i;
+ HANDLE hProcess;
+
+ for(i=0; i<gNdbMem_nAWEinfo; ++i)
+ {
+ if(ptr==gNdbMem_pAWEinfo[i].pRegionReserved)
+ {
+ pAWEinfo = gNdbMem_pAWEinfo+i;
+ }
+ }
+ if(!pAWEinfo)
+ {
+ ShowLastError("NdbMem_Free", "ptr is not AWE memory");
+ }
+
+ hProcess = GetCurrentProcess();
+ if(!MapUserPhysicalPages(ptr, pAWEinfo->nNumberOfPagesActual, 0))
+ {
+ ShowLastError("NdbMem_Free", "MapUserPhysicalPages");
+ }
+
+ if(!VirtualFree(ptr, 0, MEM_RELEASE))
+ {
+ ShowLastError("NdbMem_Free", "VirtualFree");
+ }
+
+ pAWEinfo->nNumberOfPagesFreed = pAWEinfo->nNumberOfPagesActual;
+ if(!FreeUserPhysicalPages(hProcess, &(pAWEinfo->nNumberOfPagesFreed), pAWEinfo->pnPhysicalMemoryPageArray))
+ {
+ ShowLastError("NdbMem_Free", "FreeUserPhysicalPages");
+ }
+
+ VirtualFree(pAWEinfo->pnPhysicalMemoryPageArray, 0, MEM_DECOMMIT|MEM_RELEASE);
+}
+
+
+int NdbMem_MemLockAll()
+{
+ /*
+ HANDLE hProcess = GetCurrentProcess();
+ SIZE_T nMinimumWorkingSetSize;
+ SIZE_T nMaximumWorkingSetSize;
+ GetProcessWorkingSetSize(hProcess, &nMinimumWorkingSetSize, &nMaximumWorkingSetSize);
+ ndbout << "nMinimumWorkingSetSize=" << nMinimumWorkingSetSize << ", nMaximumWorkingSetSize=" << nMaximumWorkingSetSize << endl;
+
+ SetProcessWorkingSetSize(hProcess, 50000000, 100000000);
+
+ GetProcessWorkingSetSize(hProcess, &nMinimumWorkingSetSize, &nMaximumWorkingSetSize);
+ ndbout << "nMinimumWorkingSetSize=" << nMinimumWorkingSetSize << ", nMaximumWorkingSetSize=" << nMaximumWorkingSetSize << endl;
+ */
+ return -1;
+}
+
+int NdbMem_MemUnlockAll()
+{
+ //VirtualUnlock();
+ return -1;
+}
+
diff --git a/ndb/src/common/portlib/win32/NdbMutex.c b/ndb/src/common/portlib/win32/NdbMutex.c
new file mode 100644
index 00000000000..c93384d91db
--- /dev/null
+++ b/ndb/src/common/portlib/win32/NdbMutex.c
@@ -0,0 +1,78 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <windows.h>
+#include <time.h>
+#include <assert.h>
+
+#include "NdbMutex.h"
+
+
+NdbMutex* NdbMutex_Create(void)
+{
+ NdbMutex* pNdbMutex = (NdbMutex*)malloc(sizeof(NdbMutex));
+ if(!pNdbMutex)
+ return 0;
+
+ InitializeCriticalSection(pNdbMutex);
+ return pNdbMutex;
+}
+
+
+int NdbMutex_Destroy(NdbMutex* p_mutex)
+{
+ if(!p_mutex)
+ return -1;
+
+ DeleteCriticalSection(p_mutex);
+ free(p_mutex);
+ return 0;
+}
+
+
+int NdbMutex_Lock(NdbMutex* p_mutex)
+{
+ if(!p_mutex)
+ return -1;
+
+ EnterCriticalSection (p_mutex);
+ return 0;
+}
+
+
+int NdbMutex_Unlock(NdbMutex* p_mutex)
+{
+ if(!p_mutex)
+ return -1;
+
+ LeaveCriticalSection(p_mutex);
+ return 0;
+}
+
+
+int NdbMutex_Trylock(NdbMutex* p_mutex)
+{
+ int result = -1;
+ if(p_mutex)
+ {
+ result = (TryEnterCriticalSection(p_mutex) ? 0 : -1);
+ }
+ return result;
+}
+
diff --git a/ndb/src/common/portlib/win32/NdbSleep.c b/ndb/src/common/portlib/win32/NdbSleep.c
new file mode 100644
index 00000000000..ac0f44dd07f
--- /dev/null
+++ b/ndb/src/common/portlib/win32/NdbSleep.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+
+#include "NdbSleep.h"
+
+#include <windows.h>
+
+
+int
+NdbSleep_MilliSleep(int milliseconds)
+{
+ Sleep(milliseconds);
+ return 0;
+}
+
+int
+NdbSleep_SecSleep(int seconds)
+{
+ return NdbSleep_MilliSleep(seconds*1000);
+}
+
diff --git a/ndb/src/common/portlib/win32/NdbTCP.c b/ndb/src/common/portlib/win32/NdbTCP.c
new file mode 100644
index 00000000000..483a53bd606
--- /dev/null
+++ b/ndb/src/common/portlib/win32/NdbTCP.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+
+#include "NdbTCP.h"
+
+int
+Ndb_getInAddr(struct in_addr * dst, const char *address)
+{
+ struct hostent * hostPtr;
+
+ /* Try it as aaa.bbb.ccc.ddd. */
+ dst->s_addr = inet_addr(address);
+ if (dst->s_addr != -1) {
+ return 0;
+ }
+
+ hostPtr = gethostbyname(address);
+ if (hostPtr != NULL) {
+ dst->s_addr = ((struct in_addr *) *hostPtr->h_addr_list)->s_addr;
+ return 0;
+ }
+
+ return -1;
+}
+
diff --git a/ndb/src/common/portlib/win32/NdbThread.c b/ndb/src/common/portlib/win32/NdbThread.c
new file mode 100644
index 00000000000..ae3c74be70d
--- /dev/null
+++ b/ndb/src/common/portlib/win32/NdbThread.c
@@ -0,0 +1,118 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+
+#include <windows.h>
+#include <process.h>
+#include <assert.h>
+
+#include "NdbThread.h"
+
+
+#define MAX_THREAD_NAME 16
+
+typedef unsigned (WINAPI* NDB_WIN32_THREAD_FUNC)(void*);
+
+
+struct NdbThread
+{
+ HANDLE hThread;
+ unsigned nThreadId;
+ char thread_name[MAX_THREAD_NAME];
+};
+
+
+struct NdbThread* NdbThread_Create(NDB_THREAD_FUNC *p_thread_func,
+ NDB_THREAD_ARG *p_thread_arg,
+ const NDB_THREAD_STACKSIZE thread_stack_size,
+ const char* p_thread_name,
+ NDB_THREAD_PRIO thread_prio)
+{
+ struct NdbThread* tmpThread;
+ unsigned initflag;
+ int nPriority = 0;
+
+ if(!p_thread_func)
+ return 0;
+
+ tmpThread = (struct NdbThread*)malloc(sizeof(struct NdbThread));
+ if(!tmpThread)
+ return 0;
+
+ strncpy((char*)&tmpThread->thread_name, p_thread_name, MAX_THREAD_NAME);
+
+ switch(thread_prio)
+ {
+ case NDB_THREAD_PRIO_HIGHEST: nPriority=THREAD_PRIORITY_HIGHEST; break;
+ case NDB_THREAD_PRIO_HIGH: nPriority=THREAD_PRIORITY_ABOVE_NORMAL; break;
+ case NDB_THREAD_PRIO_MEAN: nPriority=THREAD_PRIORITY_NORMAL; break;
+ case NDB_THREAD_PRIO_LOW: nPriority=THREAD_PRIORITY_BELOW_NORMAL; break;
+ case NDB_THREAD_PRIO_LOWEST: nPriority=THREAD_PRIORITY_LOWEST; break;
+ }
+ initflag = (nPriority ? CREATE_SUSPENDED : 0);
+
+ tmpThread->hThread = (HANDLE)_beginthreadex(0, thread_stack_size,
+ (NDB_WIN32_THREAD_FUNC)p_thread_func, p_thread_arg,
+ initflag, &tmpThread->nThreadId);
+
+ if(nPriority && tmpThread->hThread)
+ {
+ SetThreadPriority(tmpThread->hThread, nPriority);
+ ResumeThread (tmpThread->hThread);
+ }
+
+ assert(tmpThread->hThread);
+ return tmpThread;
+}
+
+
+void NdbThread_Destroy(struct NdbThread** p_thread)
+{
+ CloseHandle((*p_thread)->hThread);
+ (*p_thread)->hThread = 0;
+ free(*p_thread);
+ *p_thread = 0;
+}
+
+
+int NdbThread_WaitFor(struct NdbThread* p_wait_thread, void** status)
+{
+ void *local_status = 0;
+ if (status == 0)
+ status = &local_status;
+
+ if(WaitForSingleObject(p_wait_thread->hThread, INFINITE) == WAIT_OBJECT_0
+ && GetExitCodeThread(p_wait_thread->hThread, (LPDWORD)status))
+ {
+ CloseHandle(p_wait_thread->hThread);
+ p_wait_thread->hThread = 0;
+ return 0;
+ }
+ return -1;
+}
+
+
+void NdbThread_Exit(int status)
+{
+ _endthreadex((DWORD) status);
+}
+
+
+int NdbThread_SetConcurrencyLevel(int level)
+{
+ return 0;
+}
+
diff --git a/ndb/src/common/portlib/win32/NdbTick.c b/ndb/src/common/portlib/win32/NdbTick.c
new file mode 100644
index 00000000000..e3a67d8437d
--- /dev/null
+++ b/ndb/src/common/portlib/win32/NdbTick.c
@@ -0,0 +1,64 @@
+/* Copyright (C) 2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+
+#include <windows.h>
+#include "NdbTick.h"
+
+/*
+#define FILETIME_PER_MICROSEC 10
+#define FILETIME_PER_MILLISEC 10000
+#define FILETIME_PER_SEC 10000000
+
+
+NDB_TICKS NdbTick_CurrentMillisecond(void)
+{
+ ULONGLONG ullTime;
+ GetSystemTimeAsFileTime((LPFILETIME)&ullTime);
+ return (ullTime / FILETIME_PER_MILLISEC);
+}
+
+int
+NdbTick_CurrentMicrosecond(NDB_TICKS * secs, Uint32 * micros)
+{
+ ULONGLONG ullTime;
+ GetSystemTimeAsFileTime((LPFILETIME)&ullTime);
+ *secs = (ullTime / FILETIME_PER_SEC);
+ *micros = (Uint32)((ullTime % FILETIME_PER_SEC) / FILETIME_PER_MICROSEC);
+ return 0;
+}
+*/
+
+
+NDB_TICKS NdbTick_CurrentMillisecond(void)
+{
+ LARGE_INTEGER liCount, liFreq;
+ QueryPerformanceCounter(&liCount);
+ QueryPerformanceFrequency(&liFreq);
+ return (liCount.QuadPart*1000) / liFreq.QuadPart;
+}
+
+int
+NdbTick_CurrentMicrosecond(NDB_TICKS * secs, Uint32 * micros)
+{
+ LARGE_INTEGER liCount, liFreq;
+ QueryPerformanceCounter(&liCount);
+ QueryPerformanceFrequency(&liFreq);
+ *secs = liCount.QuadPart / liFreq.QuadPart;
+ liCount.QuadPart -= *secs * liFreq.QuadPart;
+ *micros = (liCount.QuadPart*1000000) / liFreq.QuadPart;
+ return 0;
+}