[PATCH 26/30] Adding new common/../windows/* files


Michael Schonberg <mschonberg@...>
 

These files contain macros and functions required to support Windows
withouth the need for #ifdef WIN scattered through out the code.

Signed-off-by: Mike Schonberg <mschonberg@...>
---
common/c_cpp/src/c/windows/environment.c | 81 ++++++
common/c_cpp/src/c/windows/lock.h | 82 ++++++
common/c_cpp/src/c/windows/machine_win.c | 213 ++++++++++++++
common/c_cpp/src/c/windows/mmap.h | 28 ++
common/c_cpp/src/c/windows/network.c | 87 ++++++
common/c_cpp/src/c/windows/platform.c | 84 ++++++
common/c_cpp/src/c/windows/port.c | 276 ++++++++++++++++++
common/c_cpp/src/c/windows/port.h | 323 ++++++++++++++++++++++
common/c_cpp/src/c/windows/wSemaphore.c | 147 ++++++++++
common/c_cpp/src/c/windows/wombat/targetsxs.h | 38 +++
common/c_cpp/src/c/windows/wombat/wInterlocked.h | 97 +++++++
11 files changed, 1456 insertions(+), 0 deletions(-)
create mode 100644 common/c_cpp/src/c/windows/environment.c
create mode 100644 common/c_cpp/src/c/windows/lock.h
create mode 100644 common/c_cpp/src/c/windows/machine_win.c
create mode 100644 common/c_cpp/src/c/windows/mmap.h
create mode 100644 common/c_cpp/src/c/windows/network.c
create mode 100644 common/c_cpp/src/c/windows/platform.c
create mode 100644 common/c_cpp/src/c/windows/port.c
create mode 100644 common/c_cpp/src/c/windows/port.h
create mode 100644 common/c_cpp/src/c/windows/wSemaphore.c
create mode 100644 common/c_cpp/src/c/windows/wombat/targetsxs.h
create mode 100644 common/c_cpp/src/c/windows/wombat/wInterlocked.h

diff --git a/common/c_cpp/src/c/windows/environment.c b/common/c_cpp/src/c/windows/environment.c
new file mode 100644
index 0000000..d413432
--- /dev/null
+++ b/common/c_cpp/src/c/windows/environment.c
@@ -0,0 +1,81 @@
+/*
+ * OpenMAMA: The open middleware agnostic messaging API
+ * Copyright (C) 2011 NYSE Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include "stdlib.h"
+#include "wombat/environment.h"
+
+int environment_deleteVariable(const char *name)
+{
+ /* Returns. */
+ int ret = -1;
+
+ /* Check arguments. */
+ if(name != NULL)
+ {
+ /* Set the value. */
+ errno_t pe = _putenv_s(name, "");
+ if(pe == 0)
+ {
+ ret = 0;
+ }
+ }
+
+ return ret;
+}
+
+const char *environment_getVariable(const char *name)
+{
+ /* Returns. */
+ const char *ret = NULL;
+
+ /* Check the argument. */
+ if(name != NULL)
+ {
+ ret = getenv(name);
+
+ /* Return NULL for a blank string. */
+ if((ret != NULL) && (ret[0] == '\0'))
+ {
+ ret = NULL;
+ }
+ }
+
+ return ret;
+}
+
+int environment_setVariable(const char *name, const char *value)
+{
+ /* Returns. */
+ int ret = -1;
+
+ /* Check the arguments. */
+ if((name != NULL) && (value != NULL))
+ {
+ /* Set the value. */
+ errno_t pe = _putenv_s(name, value);
+ if(pe == 0)
+ {
+ ret = 0;
+ }
+ }
+
+ return ret;
+}
+
diff --git a/common/c_cpp/src/c/windows/lock.h b/common/c_cpp/src/c/windows/lock.h
new file mode 100644
index 0000000..50d7c09
--- /dev/null
+++ b/common/c_cpp/src/c/windows/lock.h
@@ -0,0 +1,82 @@
+
+/*
+ * OpenMAMA: The open middleware agnostic messaging API
+ * Copyright (C) 2011 NYSE Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef STATICLOCK_H__
+#define STATICLOCK_H__
+
+/* Make windows synchronization look like pthreads we use 'w' rather than 'p' to
+ * avoid conflicts with other pthreads for windows implementations
+ */
+typedef CRITICAL_SECTION wthread_mutex_t;
+typedef HANDLE wthread_cond_t;
+typedef void * wthread_t;
+
+#define INVALID_THREAD NULL
+
+#define PTHREAD_CREATE_JOINABLE 0
+#define PTHREAD_MUTEX_RECURSIVE_NP 0
+#define PTHREAD_MUTEX_RECURSIVE 0
+
+typedef wthread_mutex_t wthread_spinlock_t;
+
+#define wthread_spin_lock wthread_mutex_lock
+#define wthread_spin_unlock wthread_mutex_unlock
+#define wthread_spin_init wthread_mutex_init
+#define wthread_spin_destroy wthread_mutex_destroy
+
+#define wthread_mutex_init( h, zip ) (InitializeCriticalSection( (h) ))
+#define wthread_mutex_unlock( h ) (LeaveCriticalSection( (h) ) )
+#define wthread_mutex_lock( h ) (EnterCriticalSection( (h) ) )
+#define wthread_mutex_destroy( h ) (DeleteCriticalSection( (h) ) )
+
+/* Windows does not have static lock initializers */
+/* the xxxUseLock variable is needed if 2 threads are started together, the
+ * first thread checks the lexerlockInitialized through atomic action and then
+ * starts to initialize the mutex which isn't atomic. The second thread checks
+ * the variable lexerlockInitialized it has been incremented, this thread would
+ * then try to grab a lock that is not initialized. On windows this causes the
+ * application to hang therefore after the mutex is initialized the variable
+ * xxxUseLock is set to 1. Just before a lock is acquired it will poll until
+ * xxxUseLock is not equal to zero this will stop the race condition. A
+ * condition variable can't be used because you get into the same problem of
+ * waiting for an uninitialized condition variable
+ */
+typedef struct
+{
+ wthread_mutex_t mLock;
+ volatile long mInitialized;
+ volatile long mUseLock;
+} wthread_static_mutex_t;
+
+#define WSTATIC_MUTEX_INITIALIZER {0,0,0}
+
+#define wthread_static_mutex_lock(x) \
+ if( InterlockedIncrement(&((x)->mInitialized)) == 1 ) \
+ { \
+ wthread_mutex_init(&((x)->mLock), NULL); \
+ (x)->mUseLock = 1; \
+ } \
+ while((x)->mUseLock == 0); \
+ wthread_mutex_lock(&((x)->mLock))
+
+#define wthread_static_mutex_unlock(x) wthread_mutex_unlock(&((x)->mLock))
+
+#endif /* STATIClOCK_H__ */
diff --git a/common/c_cpp/src/c/windows/machine_win.c b/common/c_cpp/src/c/windows/machine_win.c
new file mode 100644
index 0000000..f6f3ad5
--- /dev/null
+++ b/common/c_cpp/src/c/windows/machine_win.c
@@ -0,0 +1,213 @@
+/*
+ * OpenMAMA: The open middleware agnostic messaging API
+ * Copyright (C) 2011 NYSE Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include "port.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "wombat/machine.h"
+#include "wombat/wtable.h"
+
+#define DMKEY "HARDWARE\\DESCRIPTION" /*where to look*/
+void GetProcessNameById(DWORD Id, const char *buffer[]);
+
+time_t getTimeSinceEpoch(void)
+{
+ time_t rawTime;
+ time(&rawTime);
+ return rawTime;
+}
+
+int getSystemMemory (systemMemVals* mem)
+{
+ return 0;
+}
+
+long getTotalSystemMem(void)
+{
+ return 0;
+}
+
+int getProcessInfo(int pid ,memVals *memV,cpuVals *cpuV,int childFlag)
+{
+ PDH_FMT_COUNTERVALUE pValue={0};
+ HANDLE gProcessHandle;
+ FILETIME lpCreationTime;
+ FILETIME lpExitTime;
+ FILETIME lpKernelTime;
+ FILETIME lpUserTime;
+
+ LONGLONG tUser64;
+ LONGLONG tKernel64;
+ int error=0;
+
+ static const char* buffer[64];
+ static DWORD processId = 0;
+
+ if (processId ==0)
+ {
+ processId = GetCurrentProcessId();
+ GetProcessNameById(processId,buffer);
+ }
+
+ /*PROCESS_MEMORY_COUNTERS pmc;*/
+ if(cpuV)
+ {
+ if((gProcessHandle =
+ OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
+ FALSE, processId))==NULL)
+ {
+ printf("OpenProcess Error code : %ld \n\n\n",GetLastError());
+ }
+ if((GetProcessTimes(gProcessHandle,&lpCreationTime,&lpExitTime,&lpKernelTime,&lpUserTime))==0)
+ {
+ printf("GetProcessTimes Error code : %ld \n\n\n",GetLastError());
+ }
+ else
+ {
+ tUser64 = *(LONGLONG *)&lpUserTime;
+ tKernel64 = *(LONGLONG *)&lpKernelTime;
+ cpuV->userTime =(tUser64 * 0.0000001);
+ cpuV->sysTime =(tKernel64 * 0.0000001);
+ CloseHandle(gProcessHandle);
+ }
+ }
+ if(memV)
+ {
+ TCHAR memCounterPath[64];
+ HCOUNTER memCounter;
+ PDH_STATUS pdhStatus; /* return status of PDH functions */
+ LPCTSTR szDataSource = NULL;/* NULL for dynamic registry entries */
+ HQUERY phQuery; /* query Handle */
+ PDH_FMT_COUNTERVALUE pValue={0};
+
+ snprintf(memCounterPath,64,"\\Process(%s)\\Private Bytes",buffer);
+
+ /* create query */
+ pdhStatus = PdhOpenQuery(NULL,0,&phQuery);
+ if (pdhStatus != ERROR_SUCCESS)
+ {
+ /* Print the error value. */
+ _tprintf (TEXT("PdhOpenQuery failed with %ld\n"), pdhStatus);
+ error=1;
+ }
+ /* add counter for MEM */
+ pdhStatus = PdhAddCounter(phQuery,memCounterPath,0,&memCounter);
+ if (pdhStatus != ERROR_SUCCESS)
+ {
+ /* Print the error value. */
+ _tprintf (TEXT("PdhAddCounter Failed with 0x%x\n"), pdhStatus);
+ error=1;
+ }
+ /* collect Data */
+ pdhStatus = PdhCollectQueryData(phQuery);
+ if (pdhStatus != ERROR_SUCCESS)
+ {
+ /* Print the error value. */
+ _tprintf (TEXT("PdhCollectQueryData Failed with 0x%x\n"), pdhStatus);
+ error=1;
+ }
+ pdhStatus = PdhGetFormattedCounterValue(memCounter,
+ PDH_FMT_DOUBLE,
+ NULL,
+ &pValue);
+ if (pdhStatus == ERROR_SUCCESS)
+ {
+
+ memV->rss = (long)(pValue.doubleValue/1.0e3);
+ }
+ else
+ {
+ /* Print the error value. */
+ _tprintf (TEXT("PdhGetFormattedCounterValue Failed with 0x%x\n"), pdhStatus);
+ error=1;
+ }
+ PdhCloseQuery(phQuery);
+ }
+ return error;
+}
+
+void searchDirs(int procChildren[], int dirNames[],
+ int count,cpuVals *cpv,int tempPid)
+{
+ /*function not needed on windows*/
+}
+
+void getProcAndChildCpu(int pid, cpuVals* cpv)
+{
+ (void)getProcessInfo(pid ,NULL,cpv,0);
+}
+
+int getNumCpu(void)
+{
+ int value;
+
+ SYSTEM_INFO siSysInfo;
+ GetSystemInfo(&siSysInfo);
+ value = siSysInfo.dwNumberOfProcessors;
+
+ return value;
+}
+
+void initProcTable(int pid, int debuginfo)
+{
+ /*function not needed on windows*/
+}
+
+void getSystemTime(double* upTime,double* idleTime)
+{
+ *upTime=0.0;
+ *idleTime=0.0;
+}
+
+void getProcessorTime(long* usageTime,long* idleTime,int processor)
+{
+ *usageTime=0;
+ *idleTime=0;
+}
+
+void GetProcessNameById(DWORD Id, const char* buffer[])
+{
+ PROCESSENTRY32 pEntry = { 0 };
+ HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
+ pEntry.dwSize = sizeof(PROCESSENTRY32);
+
+ if (Process32First(hSnapShot, &pEntry))
+ {
+ do
+ {
+ if (pEntry.th32ProcessID == Id)
+ {
+ *buffer = (const char*)
+ malloc(strlen((const char*)pEntry.szExeFile) - 4);
+
+ pEntry.szExeFile[strlen((const char*)pEntry.szExeFile) -4]='\0';
+ strcpy((char*)buffer,(const char*)pEntry.szExeFile);
+ break;
+ }
+ }while (Process32Next(hSnapShot, &pEntry));
+ }
+ CloseHandle(hSnapShot);
+}
+
diff --git a/common/c_cpp/src/c/windows/mmap.h b/common/c_cpp/src/c/windows/mmap.h
new file mode 100644
index 0000000..76dd2ed
--- /dev/null
+++ b/common/c_cpp/src/c/windows/mmap.h
@@ -0,0 +1,28 @@
+/*
+ * OpenMAMA: The open middleware agnostic messaging API
+ * Copyright (C) 2011 NYSE Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef WINDOWS_MMAP_H__
+#define WINDOWS_MMAP_H__
+
+/**
+ * Open a file that will be mapped to memory. Return
+ */
+
+#endif /* WINDOWS_MMAP_H__ */
diff --git a/common/c_cpp/src/c/windows/network.c b/common/c_cpp/src/c/windows/network.c
new file mode 100644
index 0000000..e7c1ece
--- /dev/null
+++ b/common/c_cpp/src/c/windows/network.c
@@ -0,0 +1,87 @@
+/*
+ * OpenMAMA: The open middleware agnostic messaging API
+ * Copyright (C) 2011 NYSE Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include "port.h"
+
+struct in_addr resolve_ip (const char * arg)
+{
+ struct in_addr resolved;
+
+ if (0 == strcmp(arg, ""))
+ resolved.s_addr = INADDR_ANY;
+ else
+ resolved.s_addr = inet_addr (arg);
+ return (resolved);
+}
+
+int
+wsetnonblock (int s)
+{
+ unsigned long arg = 1;
+ if (0 != ioctlsocket (s, FIONBIO, &arg))
+ return -1;
+ return 0;
+}
+
+static char gIPAddress[16];
+static const char* gHostName = NULL;
+
+static void lookupIPAddress (void)
+{
+ struct hostent *host = NULL;
+ char *addrStr = "not determined";
+
+ char hostname[256];
+ if( 0 != gethostname( hostname, 256 ) )
+ {
+ snprintf( hostname, strlen( "localhost" ), "localhost" );
+ }
+ gHostName = strdup (hostname);
+
+ host = gethostbyname( gHostName );
+
+ if( gHostName == NULL ||
+ host == NULL ||
+ host->h_addr_list[0] == NULL )
+ {
+ strncpy( (char *)gIPAddress, "not determined", sizeof( gIPAddress ) );
+/* return MAMA_STATUS_IP_NOT_FOUND;*/
+ }
+ else
+ {
+ addrStr = inet_ntoa( *((struct in_addr *)( host->h_addr_list[0] )));
+ }
+
+ strncpy ((char*)gIPAddress, addrStr, sizeof (gIPAddress));
+}
+
+const char* getIpAddress(void)
+{
+ if (NULL == gHostName)
+ lookupIPAddress();
+ return gIPAddress;
+}
+
+const char* getHostName(void)
+{
+ if (NULL == gHostName)
+ lookupIPAddress();
+ return gHostName;
+}
diff --git a/common/c_cpp/src/c/windows/platform.c b/common/c_cpp/src/c/windows/platform.c
new file mode 100644
index 0000000..f17e1f9
--- /dev/null
+++ b/common/c_cpp/src/c/windows/platform.c
@@ -0,0 +1,84 @@
+/*
+ * OpenMAMA: The open middleware agnostic messaging API
+ * Copyright (C) 2011 NYSE Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include "port.h"
+#include "platform.h"
+
+#define PATH_SEPERATOR "\\"
+
+/**
+ * Functions relating to DLLs/shared objects
+ */
+char errorBuf[25];
+LIB_HANDLE openSharedLib (const char* libName, const char* path)
+{
+ size_t nameLength;
+ char* fileName;
+ LIB_HANDLE handle;
+
+ if (path)
+ {
+ nameLength = strlen(path) + strlen(libName) + strlen(LIB_EXTENSION) +
+ strlen(PATH_SEPERATOR) + strlen("lib") + 1;
+ }
+ else
+ {
+ nameLength = strlen(libName) + strlen(LIB_EXTENSION) + strlen("lib") + 1;
+ }
+ fileName = (char*) calloc (nameLength, sizeof (char));
+ if(fileName == NULL)
+ {
+ return 0;
+ }
+
+ if (path)
+ {
+ snprintf (fileName, nameLength, "%s%slib%s%s", path, PATH_SEPERATOR, libName, LIB_EXTENSION);
+ }
+ else
+ {
+ snprintf (fileName, nameLength, "lib%s%s", libName, LIB_EXTENSION);
+ }
+
+ handle = LoadLibrary (fileName);
+ free(fileName);
+ return handle;
+}
+
+
+int closeSharedLib (LIB_HANDLE handle)
+{
+ return FreeLibrary ((HMODULE) handle);
+}
+
+void* loadLibFunc (LIB_HANDLE handle, const char* funcName)
+{
+ return GetProcAddress (handle, funcName);
+
+}
+
+char* getLibError (void)
+{
+ itoa(GetLastError(), errorBuf, 10);
+ return errorBuf;
+}
diff --git a/common/c_cpp/src/c/windows/port.c b/common/c_cpp/src/c/windows/port.c
new file mode 100644
index 0000000..12f6431
--- /dev/null
+++ b/common/c_cpp/src/c/windows/port.c
@@ -0,0 +1,276 @@
+/*
+ * OpenMAMA: The open middleware agnostic messaging API
+ * Copyright (C) 2011 NYSE Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include "port.h"
+
+int gettimeofday( struct timeval *result, void *dummy )
+{
+ time_t rawTime;
+ SYSTEMTIME t;
+ GetSystemTime( &t );
+ time(&rawTime);
+ result->tv_sec = (long)rawTime;
+ result->tv_usec = (t.wMilliseconds*1000);
+
+ return 0;
+}
+
+
+typedef struct
+{
+ HANDLE mThread;
+ int mIsStopping; /* Reads and writes to 32 bit vars are atomic in WIN32 */
+} threadContext;
+
+
+
+int wthread_set_affinity_mask( wthread_t h,
+ CPU_AFFINITY_SET* dwThreadAffinityMask)
+{
+ return (int) SetThreadAffinityMask( ((threadContext*) h)->mThread,
+ (DWORD_PTR) dwThreadAffinityMask );
+}
+
+
+int wthread_create( wthread_t *h, void *atts, void *(*startProc)( void * ), void *arg )
+{
+ threadContext *result = (threadContext *)calloc( 1, sizeof( threadContext ) );
+
+ if( result == NULL )
+ {
+ return 1;
+ }
+
+ *h = result;
+
+ result->mIsStopping = 0;
+
+ result->mThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)startProc, arg, 0, NULL );
+ if (result->mThread == 0)
+ {
+ free( result );
+ return 1;
+ }
+
+ return 0;
+}
+
+void wthread_destroy(wthread_t thread)
+{
+ if(NULL != thread)
+ {
+ /* Get the impl. */
+ threadContext *impl = (threadContext *)thread;
+
+ /* Close the thread handle. */
+ CloseHandle(impl->mThread);
+
+ /* Clean the structure. */
+ free(impl);
+ }
+}
+
+int wthread_join (wthread_t t, void **value_ptr)
+{
+ threadContext *ctx = (threadContext*)t;
+ WaitForSingleObject (ctx->mThread, INFINITE);
+ if (value_ptr!=NULL)
+ *value_ptr = NULL;
+ return 0;
+}
+
+void wthread_testcancel( wthread_t h )
+{
+ threadContext *ctx = (threadContext*)h;
+ if( ctx->mIsStopping )
+ {
+ ExitThread(0);
+ }
+}
+
+void wthread_cancel( wthread_t h )
+{
+ threadContext *ctx = (threadContext*)h;
+ ctx->mIsStopping = 1;
+ WaitForSingleObject( ctx->mThread, INFINITE );
+ free( ctx );
+}
+
+void wthread_attr_init (int* attr)
+{
+}
+
+void wthread_attr_setdetachstate (int* attr, int param)
+{
+}
+
+void wthread_mutexattr_init (int* attr)
+{
+}
+
+void wthread_mutexattr_settype (int* attr, int param)
+{
+}
+
+DWORD wthread_cond_wait( HANDLE *event, LPCRITICAL_SECTION *cs )
+{
+ DWORD rval;
+
+ LeaveCriticalSection( *cs );
+ rval = WaitForSingleObject( *event, INFINITE );
+ ResetEvent( *event );
+ EnterCriticalSection( *cs );
+
+ return rval;
+}
+
+const char* index( const char *str, char c )
+{
+ unsigned int i = 0;
+ while( i < strlen( str ) )
+ {
+ if( str[i] == c )
+ {
+ return str + i;
+ }
+ i++;
+ }
+ return NULL;
+}
+
+int getpid()
+{
+ return GetCurrentProcessId();
+}
+
+struct tm* localtime_r (const time_t* t, struct tm* result)
+{
+ localtime_s (result, t);
+ return result;
+}
+
+char user[256];
+
+const char *getlogin()
+{
+ /* NOTE: This will fail if user name is over 256 characters */
+ unsigned long len = 256;
+ GetUserName( user, &len );
+ return user;
+}
+
+int
+wsocketpair (int domain, int type, int protocol, int* pair)
+{
+ struct sockaddr_in addr;
+ int len = sizeof(addr);
+ int l;
+
+ l = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (INVALID_SOCKET == pair[0])
+ return -1;
+
+ ZeroMemory (&addr, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_port = 0; /* any available */
+ addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+ if (0 != bind (l, (struct sockaddr*)(&addr), sizeof(addr)))
+ {
+ _close (l);
+ return -1;
+ }
+
+ /* Get the port and address for the other end */
+ if( 0 != getsockname (l, (struct sockaddr*)(&addr), &len))
+ {
+ _close (l);
+ return -1;
+ }
+
+ if (0 != listen (l, 1))
+ {
+ _close (l);
+ return -1;
+ }
+
+ pair[0] = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (INVALID_SOCKET == pair[0])
+ {
+ _close (l);
+ return -1;
+ }
+
+ if (0 != connect (pair[0], (struct sockaddr*)(&addr), sizeof(addr)))
+ {
+ _close (l);
+ _close (pair[0]);
+ return -1;
+ }
+
+ pair[1] = accept (l, NULL, NULL);
+ if (INVALID_SOCKET == pair[1])
+ {
+ _close (l);
+ _close (pair[0]);
+ return -1;
+ }
+
+ _close (l);
+
+ return 0;
+}
+
+int
+wthread_key_create(wthread_key_t* key, void* val)
+{
+ *key = TlsAlloc();
+ if (TLS_OUT_OF_INDEXES == *key)
+ return 1;
+ TlsSetValue(*key, val);
+ return 0;
+}
+
+time_t wtimegm (struct tm *tm)
+{
+ time_t ret;
+ char *tz;
+
+ tz = environment_getVariable("TZ");
+ environment_setVariable("TZ", "");
+ tzset();
+ ret = mktime(tm);
+ if (tz)
+ environment_setVariable("TZ", tz);
+ else
+ environment_deleteVariable("TZ");
+ tzset();
+ return ret;
+}
+
+int wnanosleep (struct wtimespec* ts, struct timnespec* remain)
+{
+ DWORD millis = ts->tv_sec * 1000 + ts->tv_nsec/1000;
+ /* if tv_nsec > 0 add at least 1 milli */
+ if (ts->tv_nsec > 0 && ts->tv_nsec < 1000)
+ millis += 1;
+ Sleep(millis);
+ return 0;
+}
diff --git a/common/c_cpp/src/c/windows/port.h b/common/c_cpp/src/c/windows/port.h
new file mode 100644
index 0000000..7df1f55
--- /dev/null
+++ b/common/c_cpp/src/c/windows/port.h
@@ -0,0 +1,323 @@
+/*
+ * OpenMAMA: The open middleware agnostic messaging API
+ * Copyright (C) 2011 NYSE Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef WINDOWS_H__
+#define WINDOWS_H__
+
+#define WIN32_EXTRA_LEAN
+#define WIN32_LEAN_AND_MEAN
+
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <windows.h>
+#include <stdlib.h>
+#include <io.h>
+#include <malloc.h>
+#include <float.h>
+#include <tchar.h>
+#include <pdh.h>
+#include <pdhmsg.h>
+#include <tlhelp32.h>
+#include <time.h>
+
+#include "lock.h"
+#include "mmap.h"
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/* So Windows compiler ignores gcc __attribute__(x) */
+#define __attribute__(a)
+
+#define WCOMMONINLINE __inline
+#define WCOMMONFORCEINLINE __forceinline
+
+/* Type for handle to dynamically loaded library */
+typedef HINSTANCE LIB_HANDLE;
+
+/* Missing typedefs */
+typedef void * caddr_t;
+typedef u_long in_addr_t;
+
+typedef unsigned char uint8_t;
+typedef char int8_t;
+typedef unsigned short uint16_t;
+typedef short int16_t;
+typedef unsigned int uint32_t;
+typedef int int32_t;
+typedef unsigned __int64 uint64_t;
+typedef __int64 int64_t;
+
+
+/* suffix for shared libraries */
+#ifdef _DEBUG
+#define LIB_EXTENSION "mdd.dll"
+#else
+#define LIB_EXTENSION "md.dll"
+#endif
+
+/* 8 byte int typedefs */
+typedef unsigned __int64 w_u64_t;
+typedef __int64 w_i64_t;
+
+/* Network conversion function */
+#define htonll(x) \
+ ((uint64_t)htonl((uint32_t)((x)>>32)) | (uint64_t)htonl((uint32_t)(x))<<32)
+#define ntohll(x) \
+ ((uint64_t)ntohl((uint32_t)((x)>>32)) | (uint64_t)ntohl((uint32_t)(x))<<32)
+
+/* For delimiting multiple paths in env variables properties */
+#define PATH_DELIM ';'
+
+#define PATHSEP "\\"
+
+/* Calling conventions */
+#define MAMACALLTYPE __stdcall
+
+#if defined( COMMON_DLL )
+ /* We are building common dll */
+# define COMMONExpDLL __declspec( dllexport )
+#elif defined( MAMA_DLL ) && defined( MAMA )
+ /* We are building mama as a dll */
+# define COMMONExpDLL __declspec( dllimport )
+# define MAMAExpDLL __declspec( dllexport )
+# define MAMAExpBridgeDLL __declspec( dllexport )
+#elif defined( MAMA_DLL ) && defined( BRIDGE )
+ /* We are building mama bridge as a dll */
+# define MAMAExpDLL __declspec( dllimport )
+# define MAMAExpBridgeDLL __declspec( dllimport )
+# define COMMONExpDLL __declspec( dllimport )
+# define MAMACPPExpDLL
+# define MAMDAExpDLL
+# define MAMDAOPTExpDLL
+# define WMWExpDLL __declspec( dllimport )
+#elif defined( MAMA_DLL ) && defined( MAMACPP )
+ /* We are building mamacpp as a dll */
+# define COMMONExpDLL __declspec( dllimport )
+# define MAMAExpDLL __declspec( dllimport )
+# define MAMACPPExpDLL __declspec( dllexport )
+# define MAMAExpBridgeDLL
+#elif defined( MAMDA_DLL ) && defined( MAMDA )
+ /* We are building mamda as a dll */
+# define COMMONExpDLL __declspec( dllimport )
+# define MAMAExpDLL __declspec( dllimport )
+# define MAMACPPExpDLL __declspec( dllimport )
+# define MAMDAExpDLL __declspec( dllexport )
+# define MAMAExpBridgeDLL
+#elif defined( MAMDA_DLL ) && defined( MAMDAOPT )
+ /* We are building extra mamda as a dll */
+# define COMMONExpDLL __declspec( dllimport )
+# define MAMAExpDLL __declspec( dllimport )
+# define MAMACPPExpDLL __declspec( dllimport )
+# define MAMDAExpDLL __declspec( dllimport )
+# define MAMDAOPTExpDLL __declspec( dllexport )
+# define MAMAExpBridgeDLL
+#elif !defined ( MAMA_STATIC ) && !defined ( WMW_STATIC ) && !defined (WIRECACHE_STATIC)
+ /* We are building mama apps (non static) */
+# define COMMONExpDLL __declspec( dllimport )
+# define WMWExpDLL __declspec( dllexport )
+# define MAMAExpDLL __declspec( dllimport )
+# define MAMACPPExpDLL __declspec( dllimport )
+# define MAMDAExpDLL __declspec( dllimport )
+# define MAMDAOPTExpDLL __declspec( dllimport )
+# define MAMAExpBridgeDLL
+#elif defined( WIN32 ) && defined( WMW_DLL )
+ /* We are building wmw as a dll */
+# define COMMONExpDLL __declspec( dllimport )
+# define WMWExpDLL __declspec( dllexport )
+#elif defined( WIN32 ) && defined( WMW_APP )
+ /* We are building wmw test apps */
+# define COMMONExpDLL __declspec( dllimport )
+# define WMWExpDLL __declspec( dllimport )
+#else
+ /* We are building on linux or statically */
+# define COMMONExpDLL
+# define WMWExpDLL
+# define WCACHEExpDLL
+# define MAMAExpDLL
+# define MAMACPPExpDLL
+# define MAMDAExpDLL
+# define MAMDAOPTExpDLL
+# define MAMAExpBridgeDLL
+#endif
+
+/* Socket Pair and set non blocking */
+COMMONExpDLL int
+wsocketpair (int domain, int type, int protocol, int* pair);
+
+COMMONExpDLL int
+wsetnonblock (int s);
+
+#define shutdown(x, y) closesocket((x))
+
+/* net work utility functions */
+COMMONExpDLL const char* getIpAddress (void);
+COMMONExpDLL const char* getHostName (void);
+COMMONExpDLL const char* getlogin (void);
+COMMONExpDLL struct in_addr resolve_ip (const char * arg);
+
+/* Thread local storage */
+typedef DWORD wthread_key_t;
+
+COMMONExpDLL int
+wthread_key_create(wthread_key_t* key, void* val);
+
+#define wthread_key_delete(x) TlsFree(x)
+#define wthread_setspecific(x, val) TlsSetValue((x),(void*)((val)))
+#define wthread_getspecific(x) TlsGetValue((x))
+
+/* Posix Semaphores for Windows */
+typedef void* wsem_t;
+
+COMMONExpDLL
+int wsem_init (wsem_t* sem, int dummy, int count);
+
+COMMONExpDLL
+int wsem_destroy (wsem_t* sem);
+
+COMMONExpDLL
+int wsem_post (wsem_t* sem);
+
+COMMONExpDLL
+int wsem_wait (wsem_t* sem);
+
+COMMONExpDLL
+int wsem_timedwait (wsem_t* sem, unsigned int ts);
+
+COMMONExpDLL
+int wsem_trywait (wsem_t* sem);
+
+COMMONExpDLL
+int wsem_getvalue (wsem_t*, int* items);
+
+/* These functions are different on Windows */
+#define bzero( x, y ) ZeroMemory( ((void *)(x)), (y) )
+#define strtok_r(x, y, z) strtok((x),(y))
+#define snprintf _snprintf
+#define strdup _strdup
+#define strncasecmp _strnicmp
+#define strcasecmp _stricmp
+#define read _read
+#define write _write
+#define close _close
+#define sleep(x) Sleep( (x)*1000)
+
+COMMONExpDLL
+int gettimeofday( struct timeval *result, void *dummy );
+
+COMMONExpDLL
+int getpid();
+
+const char *index( const char *str, char c );
+
+#define ctime_r ctime
+
+#define gmtime_r( _clock, _result ) \
+ ( *(_result) = *gmtime( (_clock) ), \
+ (_result) )
+
+/*
+ inttypes.h doesn't exist on windows.
+ emulate some definitions here.
+*/
+#define PRId64 "I64d"
+#define PRIu64 "I64u"
+
+#define wthread_detach( h ) /* noop */
+#define wthread_self GetCurrentThread
+#define wthread_equal( h1, h2 ) ((h1) == (h2))
+
+#define wthread_cond_init( h, zip ) ((*(h)) = CreateEvent( NULL, 1, 0, NULL ))
+#define wthread_cond_signal( h ) (SetEvent( *(h) ))
+#define wthread_cond_destroy( h ) (CloseHandle( *(h) ))
+
+COMMONExpDLL DWORD
+wthread_cond_wait( HANDLE *event, LPCRITICAL_SECTION *cs );
+
+#define wthread_exit ExitThread
+
+#define wthread_cleanup_push( x, y ) /* noop */
+#define wthread_cleanup_pop(x) /* noop */
+
+#define CPU_AFFINITY_SET DWORD
+
+COMMONExpDLL int wthread_create( wthread_t *h, void *atts, void *(*startProc)( void * ), void *arg );
+COMMONExpDLL void wthread_destroy(wthread_t thread);
+COMMONExpDLL int wthread_join (wthread_t t, void **value_ptr);
+COMMONExpDLL void wthread_testcancel( wthread_t h );
+COMMONExpDLL void wthread_cancel( wthread_t h );
+COMMONExpDLL struct tm* localtime_r (const time_t* t, struct tm* result);
+COMMONExpDLL int wthread_set_affinity_mask( wthread_t h, CPU_AFFINITY_SET* dwThreadAffinityMask);
+
+typedef int wthread_attr_t;
+COMMONExpDLL void wthread_attr_init (int* attr);
+COMMONExpDLL void wthread_attr_setdetachstate (int* attr, int);
+
+typedef int wthread_mutexattr_t;
+COMMONExpDLL void wthread_mutexattr_init (int* attr);
+COMMONExpDLL void wthread_mutexattr_settype (int* attr, int);
+
+#define wGetCurrentThreadId GetCurrentThreadId
+
+/* Macros for shared library access */
+#define wdlopen(a,b) LoadLibrary(a)
+#define wdlclose FreeLibrary
+#define wdlerror GetLastError
+#define wdlsym GetProcAddress
+
+#define timersub(tvp, uvp, vvp) \
+ do { \
+ (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
+ (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
+ if ((vvp)->tv_usec < 0) { \
+ (vvp)->tv_sec--; \
+ (vvp)->tv_usec += 1000000; \
+ } \
+ } while (0)
+
+#define timeradd(tvp, uvp, vvp) \
+ do { \
+ (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
+ (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
+ if ((vvp)->tv_usec >= 1000000) { \
+ (vvp)->tv_sec++; \
+ (vvp)->tv_usec -= 1000000; \
+ } \
+ } while (0)
+
+
+/* time gm not available on Windows */
+COMMONExpDLL
+time_t wtimegm (struct tm *tm);
+
+struct wtimespec
+{
+ time_t tv_sec;
+ long tv_nsec;
+};
+
+COMMONExpDLL int wnanosleep (struct wtimespec* ts, struct timnespec* remain);
+
+#if defined(__cplusplus)
+} /* extern "C" */
+#endif
+
+#endif /* WINDOWS_H__ */
diff --git a/common/c_cpp/src/c/windows/wSemaphore.c b/common/c_cpp/src/c/windows/wSemaphore.c
new file mode 100644
index 0000000..6947ac4
--- /dev/null
+++ b/common/c_cpp/src/c/windows/wSemaphore.c
@@ -0,0 +1,147 @@
+/*
+ * OpenMAMA: The open middleware agnostic messaging API
+ * Copyright (C) 2011 NYSE Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include "port.h"
+
+#include "wombat/wSemaphore.h"
+
+/**
+ * Waiting on Win32 semaphore involves a system call and is very inefficient. When
+ * we test to determine if the queue is empty with a Win32 semaphore
+ * WaitForSingleObject consumes all the CPU!!!!. We can be much more efficient using
+ * a critical section and not call WaitForSingleObject when there is nothing on the Queue.
+ */
+
+typedef struct
+{
+ unsigned int mCount;
+ HANDLE mEvent;
+ CRITICAL_SECTION mCs;
+} sem_t;
+
+int wsem_init (wsem_t* result, int dummy, int count)
+{
+ sem_t* sem = (sem_t*)malloc (sizeof (sem_t));
+ if (sem == NULL)
+ {
+ return 1;
+ }
+
+ *result = sem;
+ sem->mCount = count;
+ sem->mEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
+ if (sem->mEvent == INVALID_HANDLE_VALUE)
+ {
+ return 1;
+ }
+ InitializeCriticalSection (&sem->mCs);
+
+ return 0;
+}
+
+int wsem_destroy (wsem_t* sem)
+{
+ sem_t* impl = (sem_t*)(*sem);
+ CloseHandle (impl->mEvent);
+ DeleteCriticalSection (&impl->mCs);
+ free (impl);
+ return 0;
+}
+
+int wsem_post (wsem_t* sem)
+{
+ sem_t* impl = (sem_t*)(*sem);
+ EnterCriticalSection (&impl->mCs);
+ impl->mCount++;
+
+ /* MLS: we might be able to optimize here and only call SetEvent when the
+ * count is 1; however, this would require extensive testing as a race
+ * condition would stop dispatching altogether. I don't see any obvious
+ * race conditions but I am a little concerned that there might be undefined
+ * behavior when SetEvent and WaitForSingleObject race. MS does not
+ * indicate this directly but the documentation for PulseEvent() mentions
+ * some potential problems. We don't use pulse event for this reason.
+ */
+ SetEvent (impl->mEvent);
+ LeaveCriticalSection (&impl->mCs);
+ return 0;
+}
+
+int wsem_wait (wsem_t* sem)
+{
+ unsigned int t = INFINITE;
+ return wsem_timedwait (sem, t);
+
+}
+
+int wsem_trywait (wsem_t* sem)
+{
+ sem_t* impl = (sem_t*)(*sem);
+ int wouldWait = 0;
+
+ EnterCriticalSection (&impl->mCs);
+ if (impl->mCount)
+ {
+ impl->mCount--;
+ }
+ else
+ {
+ wouldWait = 1;
+ }
+ LeaveCriticalSection (&impl->mCs);
+
+ return wouldWait;
+}
+
+int wsem_getvalue (wsem_t* sem, int* items)
+{
+ sem_t* impl = (sem_t*)(*sem);
+ EnterCriticalSection (&impl->mCs);
+ *items = impl->mCount;
+ LeaveCriticalSection (&impl->mCs);
+
+ return 0;
+}
+
+
+
+int wsem_timedwait (wsem_t* sem, unsigned int timeoutval)
+{
+ DWORD ts = (DWORD) timeoutval;
+ sem_t* impl = (sem_t*)(*sem);
+ int wait = 0;
+
+ do
+ {
+ EnterCriticalSection (&impl->mCs);
+ if (impl->mCount <= 1) ResetEvent (impl->mEvent);
+ if (impl->mCount)
+ {
+ impl->mCount--;
+ LeaveCriticalSection (&impl->mCs);
+ return 0;
+ }
+ LeaveCriticalSection (&impl->mCs);
+ } while (WAIT_OBJECT_0 == WaitForSingleObject (impl->mEvent, ts));
+
+ /* Time out or worse */
+ return -1;
+}
+
diff --git a/common/c_cpp/src/c/windows/wombat/targetsxs.h b/common/c_cpp/src/c/windows/wombat/targetsxs.h
new file mode 100644
index 0000000..a8d8280
--- /dev/null
+++ b/common/c_cpp/src/c/windows/wombat/targetsxs.h
@@ -0,0 +1,38 @@
+#ifndef _WOMBAT_TARGETSXS_H
+#define _WOMBAT_TARGETSXS_H
+
+#ifndef VC7
+
+#ifdef VC8
+#define _SXS_ASSEMBLY_VERSION "8.0.50727.762"
+#endif
+
+#ifdef VC9
+#define _SXS_ASSEMBLY_VERSION "9.0.21022.8"
+#endif
+
+#ifdef VC10
+#define _SXS_ASSEMBLY_VERSION "10.0.30319.1"
+#endif
+
+#ifndef __midl
+
+#define _CRT_ASSEMBLY_VERSION _SXS_ASSEMBLY_VERSION
+#define _MFC_ASSEMBLY_VERSION _SXS_ASSEMBLY_VERSION
+#define _ATL_ASSEMBLY_VERSION _SXS_ASSEMBLY_VERSION
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+__declspec(selectany) int _forceCRTManifest;
+__declspec(selectany) int _forceMFCManifest;
+__declspec(selectany) int _forceAtlDllManifest;
+__declspec(selectany) int _forceCRTManifestRTM;
+__declspec(selectany) int _forceMFCManifestRTM;
+__declspec(selectany) int _forceAtlDllManifestRTM;
+#ifdef __cplusplus
+}
+#endif
+#endif
+#endif
+#endif
diff --git a/common/c_cpp/src/c/windows/wombat/wInterlocked.h b/common/c_cpp/src/c/windows/wombat/wInterlocked.h
new file mode 100644
index 0000000..ecfb72c
--- /dev/null
+++ b/common/c_cpp/src/c/windows/wombat/wInterlocked.h
@@ -0,0 +1,97 @@
+/*
+ * OpenMAMA: The open middleware agnostic messaging API
+ * Copyright (C) 2011 NYSE Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef WINTERLOCKED_H
+#define WINTERLOCKED_H
+
+#include "port.h"
+
+/* The base interlocked type on Windows. */
+typedef volatile long wInterlockedInt;
+
+/**
+ * This function will initialise a wInterlockedInt.
+ *
+ * @param[in] value Pointer to the item to be initialized.
+ * @return 0 on success.
+ */
+
+WCOMMONINLINE int wInterlocked_initialize(wInterlockedInt *value)
+{
+ return 0;
+}
+
+/**
+ * This function will destroy a wInterlockedInt.
+ *
+ * @param[in] value Pointer to the item to be destroyed.
+ * @return 0 on success.
+ */
+WCOMMONINLINE int wInterlocked_destroy(wInterlockedInt *value)
+{
+ return 0;
+}
+
+/**
+ * This function will atomically decrement a 32-bit integer value.
+ *
+ * @param[in] value Pointer to the value to be decremented.
+ * @return The decremented integer.
+ */
+WCOMMONINLINE int wInterlocked_decrement(wInterlockedInt *value)
+{
+ return (int)InterlockedDecrement(value);
+}
+
+/**
+ * This function will atomically increment a 32-bit integer value.
+ *
+ * @param[in] value Pointer to the value to be incremented.
+ * @return The incremented integer.
+ */
+WCOMMONINLINE int wInterlocked_increment(wInterlockedInt *value)
+{
+ return (int)InterlockedIncrement(value);
+}
+
+/**
+ * This function will return the value of the interlocked variable.
+ *
+ * @param[in] value Pointer to the value to be read.
+ * @return The value itself.
+ */
+WCOMMONINLINE int wInterlocked_read(wInterlockedInt *value)
+{
+ return *value;
+}
+
+/**
+ * This function will atomically set a 32-bit integer value.
+ *
+ * @param[in] newValue The new value to set.
+ * @param[in] value Pointer to the value to be set.
+ * @return The updated integer.
+ */
+WCOMMONINLINE int wInterlocked_set(int newValue, wInterlockedInt *value)
+{
+ return (int)InterlockedExchange(value, (long)newValue);
+}
+
+#endif
--
1.7.7.6