Date   

[PATCH 01/30] Move Linux Specific #includes and Macros #includes

Michael Schonberg <mschonberg@...>
 

This is the first in a series of patches to add Windows suport. Rather
than peppering the source with #ifdef osXXX blocks, os specific headers
and source files go into directory with the same name as the OS. Ideally,
there will be one linux directory in common, one windows, etc.; however,
the same approach should be used in other modules that require os specific
implementations. "#ifdef OS" should be avoided whenever possible.

Each OS directory must at least contain a file "port.h". This file
contains os-specific includes and macros. At some point, it might make
sense to subdivide port.h into several headers (one for networking,
threads, etc.). For the moement we will stick with one until the process
is complete.

We may also want to move some of the linux/ that is common to other os's
like Solaris and BSD to a /unix directory when we start adding support for
other unix-like platforms.

This change creates common/c_cpp/src/c/linux/port.h. All of the #includes
that are not found by the windows compiler are in port.h as well as some
of the obvious linux specific macros.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/configure.ac | 6 ++
common/c_cpp/src/c/MRSWLock.c | 2 +-
common/c_cpp/src/c/Makefile.am | 1 +
common/c_cpp/src/c/destroyHandle.c | 1 +
common/c_cpp/src/c/linux/port.h | 136 ++++++++++++++++++++++++++++++++
common/c_cpp/src/c/list.c | 6 +-
common/c_cpp/src/c/machine.c | 9 +--
common/c_cpp/src/c/platform.c | 5 +-
common/c_cpp/src/c/platform.h | 21 -----
common/c_cpp/src/c/property.c | 4 +-
common/c_cpp/src/c/queue.c | 22 +-----
common/c_cpp/src/c/strutils.c | 7 +-
common/c_cpp/src/c/systree.h | 4 -
common/c_cpp/src/c/timers.h | 3 +-
common/c_cpp/src/c/wSemaphore.c | 8 +--
common/c_cpp/src/c/wlock.c | 3 +-
common/c_cpp/src/c/wlock.h | 5 -
common/c_cpp/src/c/wombat/queue.h | 15 +---
common/c_cpp/src/c/wombat/strutils.h | 7 --
common/c_cpp/src/c/wombat/wSemaphore.h | 51 +------------
common/c_cpp/src/c/wombat/wincompat.h | 1 +
21 files changed, 163 insertions(+), 154 deletions(-)
create mode 100644 common/c_cpp/src/c/linux/port.h

diff --git a/common/c_cpp/configure.ac b/common/c_cpp/configure.ac
index a95eb91..9b08055 100755
--- a/common/c_cpp/configure.ac
+++ b/common/c_cpp/configure.ac
@@ -43,6 +43,12 @@ AM_INIT_AUTOMAKE([foreign])
AM_CONFIG_HEADER([config.h])
AC_CANONICAL_BUILD()

+# Set up symbolic links for os-specific files
+AC_MSG_NOTICE([Configuring symbolic links for $build_os in $srcdir])
+case $build_os in
+ linux*-*) AC_CONFIG_LINKS([src/c/port.h:src/c/linux/port.h]) ;;
+esac
+
# Checks for programs.
AC_PROG_CXX

diff --git a/common/c_cpp/src/c/MRSWLock.c b/common/c_cpp/src/c/MRSWLock.c
index b7d84c3..8cccb7c 100644
--- a/common/c_cpp/src/c/MRSWLock.c
+++ b/common/c_cpp/src/c/MRSWLock.c
@@ -22,8 +22,8 @@
/* ********************************************************** */
/* Includes. */
/* ********************************************************** */
+#include "port.h"
#include "wombat/MRSWLock.h"
-#include "wombat/wincompat.h"
#include <stdlib.h>

/* ********************************************************** */
diff --git a/common/c_cpp/src/c/Makefile.am b/common/c_cpp/src/c/Makefile.am
index bab6069..facce7c 100644
--- a/common/c_cpp/src/c/Makefile.am
+++ b/common/c_cpp/src/c/Makefile.am
@@ -38,6 +38,7 @@ nobase_include_HEADERS = \
property.h \
wlock.h \
timers.h \
+ port.h \
wombat/MRSWLock.h \
wombat/environment.h \
wombat/machine.h \
diff --git a/common/c_cpp/src/c/destroyHandle.c b/common/c_cpp/src/c/destroyHandle.c
index 37a2ae3..cf63ea8 100644
--- a/common/c_cpp/src/c/destroyHandle.c
+++ b/common/c_cpp/src/c/destroyHandle.c
@@ -22,6 +22,7 @@
/* ************************************************************** */
/* Includes. */
/* ************************************************************** */
+#include "port.h"
#include "destroyHandle.h"
#include <stdio.h>

diff --git a/common/c_cpp/src/c/linux/port.h b/common/c_cpp/src/c/linux/port.h
new file mode 100644
index 0000000..a1de75d
--- /dev/null
+++ b/common/c_cpp/src/c/linux/port.h
@@ -0,0 +1,136 @@
+/*
+ * 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
+ */
+
+/* Linux Specific macros, #includes, and prototypes.
+ *
+ * For Linux, most should be macros. Some of the contents of this file may be
+ * moved to a common "unix.h' file when we port to Solaris and other unix
+ * variants.
+ */
+
+#ifndef PORT_LINUX_H__
+#define PORT_LINUX_H__
+
+#if defined (__cplusplus)
+extern "C"
+{
+#endif
+
+#include <pthread.h>
+#include <sys/types.h>
+#include <sys/vfs.h>
+#include <sys/param.h>
+#include <sys/resource.h>
+#include <sys/time.h>
+#include <sys/times.h>
+#include <netinet/in.h>
+#include <semaphore.h>
+#include <dirent.h>
+#include <dlfcn.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+/* Call Types */
+#define COMMONExpDLL
+#define WMWExpDLL
+#define MAMAExpDLL
+#define MAMACPPExpDLL
+#define MAMDAExpDLL
+#define MAMDAOPTExpDLL
+#define MAMAExpBridgeDLL
+#define MAMACALLTYPE
+
+/* Type for handle to dynamically loaded library */
+typedef void* LIB_HANDLE;
+
+/* suffix for shared libraries */
+#define LIB_EXTENSION ".so"
+
+/* 8 byte int typedefs */
+typedef unsigned long long int w_u64_t;
+typedef long long int w_i64_t;
+
+/* Network conversion function */
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#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)
+#else
+#define htonll(x) ((uint64_t)(x))
+#define ntohll(x) ((uint64_t)(x))
+#endif
+
+/* For delimiting multiple paths in env variables properties */
+#define PATH_DELIM ':'
+
+/* Use Posix semaphores for Linux */
+#define wsem_t sem_t
+#define wsem_init sem_init
+#define wsem_post sem_post
+#define wsem_wait sem_wait
+#define wsem_trywait sem_trywait
+#define wsem_destroy sem_destroy
+#define wsem_getvalue sem_getvalue
+
+int wsem_timedwait (wsem_t* sem, unsigned int ts);
+
+/* User pthreads for linux */
+#define wthread_mutex_t pthread_mutex_t
+#define wthread_mutex_init pthread_mutex_init
+#define wthread_mutex_unlock pthread_mutex_unlock
+#define wthread_mutex_lock pthread_mutex_lock
+#define wthread_mutex_destroy pthread_mutex_destroy
+#define wthread_t pthread_t
+#define wthread_detach pthread_detach
+#define wthread_self pthread_self
+#define wthread_equal pthread_equal
+#define wthread_cleanup_push pthread_cleanup_push
+#define wthread_cleanup_pop pthread_cleanup_pop
+#define wthread_join pthread_join
+#define wthread_create pthread_create
+#define wthread_exit pthread_exit
+
+#define wthread_cond_t pthread_cond_t
+#define wthread_cond_init pthread_cond_init
+#define wthread_cond_signal pthread_cond_signal
+#define wthread_cond_destroy pthread_cond_destroy
+#define wthread_cond_wait pthread_cond_wait
+
+#define wthread_spinlock_t pthread_spinlock_t
+#define wthread_spin_init pthread_spin_init
+#define wthread_spin_unlock pthread_spin_unlock
+#define wthread_spin_lock pthread_spin_lock
+#define wthread_spin_destroy pthread_spin_destroy
+#define wthread_attr_t pthread_attr_t
+#define wthread_attr_init pthread_attr_init
+#define wthread_attr_setdetachstate pthread_attr_setdetachstate
+
+#define wthread_mutexattr_t pthread_mutexattr_t
+#define wthread_mutexattr_init pthread_mutexattr_init
+#define wthread_mutexattr_settype pthread_mutexattr_settype
+
+#define wGetCurrentThreadId pthread_self
+
+#if defined (__cplusplus)
+} /* extern "c" */
+#endif
+
+#endif /* LINUX_H__ */
diff --git a/common/c_cpp/src/c/list.c b/common/c_cpp/src/c/list.c
index e37b4b0..ef3a00d 100644
--- a/common/c_cpp/src/c/list.c
+++ b/common/c_cpp/src/c/list.c
@@ -19,11 +19,7 @@
* 02110-1301 USA
*/

-#ifndef WIN32
-#include <pthread.h>
-#else
-#include "wombat/wincompat.h"
-#endif
+#include "port.h"

#include <stdlib.h>
#include <stdio.h>
diff --git a/common/c_cpp/src/c/machine.c b/common/c_cpp/src/c/machine.c
index 42bd9de..512e1ab 100644
--- a/common/c_cpp/src/c/machine.c
+++ b/common/c_cpp/src/c/machine.c
@@ -19,14 +19,10 @@
* 02110-1301 USA
*/

-#include <sys/param.h>
-#include <sys/resource.h>
+#include "port.h"
#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/times.h>

#include <ctype.h>
-#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@@ -34,10 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/vfs.h>
#include <time.h>
-#include <unistd.h>
-#include <unistd.h>

#include "wombat/machine.h"
#include "wombat/wtable.h"
diff --git a/common/c_cpp/src/c/platform.c b/common/c_cpp/src/c/platform.c
index 0ed6d18..8bf7f4e 100644
--- a/common/c_cpp/src/c/platform.c
+++ b/common/c_cpp/src/c/platform.c
@@ -19,6 +19,7 @@
* 02110-1301 USA
*/

+#include "port.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -27,10 +28,6 @@
#include "platform.h"
#include "wombat/wincompat.h"

-
-#define LIB_EXTENSION ".so"
-
-
/**
* Functions relating to DLLs/shared objects
*/
diff --git a/common/c_cpp/src/c/platform.h b/common/c_cpp/src/c/platform.h
index c3b17d6..440f962 100644
--- a/common/c_cpp/src/c/platform.h
+++ b/common/c_cpp/src/c/platform.h
@@ -25,16 +25,6 @@
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
-#include "wombat/wincompat.h"
-#include <dlfcn.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-
-#ifdef WIN32
-typedef HINSTANCE LIB_HANDLE;
-#else
-typedef void* LIB_HANDLE;
-#endif

/* The platform specific prefix and postfix will automatically be added to the libname
e.g on Linux "mamaImpl" will load "libmamaimpl.so" */
@@ -50,17 +40,6 @@ void* loadLibFunc (LIB_HANDLE handle, const char* funcName);
COMMONExpDLL
char* getLibError (void);

-/* Network conversion function */
-#if defined(WIN32) || __BYTE_ORDER == __LITTLE_ENDIAN
-#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)
-#else
-#define htonll(x) ((uint64_t)(x))
-#define ntohll(x) ((uint64_t)(x))
-#endif
-
#if defined(__cplusplus)
}
#endif /* __cplusplus */
diff --git a/common/c_cpp/src/c/property.c b/common/c_cpp/src/c/property.c
index 456c08f..a5271ec 100644
--- a/common/c_cpp/src/c/property.c
+++ b/common/c_cpp/src/c/property.c
@@ -19,6 +19,8 @@
* 02110-1301 USA
*/

+#include "port.h"
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -32,8 +34,6 @@

#define KEY_BLOCK_SIZE 64

-#define PATH_DELIM ':'
-
int gPropertyDebug = 0;

typedef struct
diff --git a/common/c_cpp/src/c/queue.c b/common/c_cpp/src/c/queue.c
index ce960d1..03cf678 100644
--- a/common/c_cpp/src/c/queue.c
+++ b/common/c_cpp/src/c/queue.c
@@ -19,16 +19,9 @@
* 02110-1301 USA
*/

-#ifndef WIN32
-#include <pthread.h>
-#else
-#include "wombat/wincompat.h"
-#define pthread_mutex_t wthread_mutex_t
-#define pthread_mutex_init wthread_mutex_init
-#define pthread_mutex_destroy wthread_mutex_destroy
-#define pthread_mutex_lock wthread_mutex_lock
-#define pthread_mutex_unlock wthread_mutex_unlock
-#endif
+
+#include "port.h"
+
#include "wombat/wSemaphore.h"

#include <errno.h>
@@ -120,14 +113,10 @@ wombatQueue_create (wombatQueue queue, uint32_t maxSize, uint32_t initialSize,
return WOMBAT_QUEUE_SEM_ERR;
}

-#ifndef WIN32
if (pthread_mutex_init( &impl->mLock, NULL) != 0)
{
return WOMBAT_QUEUE_MTX_ERR;
}
-#else
- wthread_mutex_init( &impl->mLock, NULL);
-#endif

initialSize = initialSize == 0 ? WOMBAT_QUEUE_CHUNK_SIZE : initialSize;
wombatQueueImpl_allocChunk (impl, initialSize);
@@ -173,15 +162,10 @@ wombatQueue_destroy (wombatQueue queue)
result = WOMBAT_QUEUE_SEM_ERR;
}

-#ifndef WIN32
if (pthread_mutex_destroy( &impl->mLock) != 0)
{
result = WOMBAT_QUEUE_MTX_ERR;
}
-#else
- wthread_mutex_destroy( &impl->mLock);
-#endif
-

free (impl);
return WOMBAT_QUEUE_OK;
diff --git a/common/c_cpp/src/c/strutils.c b/common/c_cpp/src/c/strutils.c
index 1fae9b7..4874fe6 100644
--- a/common/c_cpp/src/c/strutils.c
+++ b/common/c_cpp/src/c/strutils.c
@@ -23,17 +23,14 @@
#define __STDC_FORMAT_MACROS
#endif

+#include "port.h"
+
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
-#ifndef WIN32
-#include <inttypes.h>
-#else
-#include <wombat/wincompat.h>
-#endif
#include <wombat/strutils.h>

static const char* gIntegerStrings[] = {
diff --git a/common/c_cpp/src/c/systree.h b/common/c_cpp/src/c/systree.h
index f5a15cc..818be5a 100644
--- a/common/c_cpp/src/c/systree.h
+++ b/common/c_cpp/src/c/systree.h
@@ -24,10 +24,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

-#ifdef WIN32
-#define __attribute__(a)
-#endif
-
#ifndef _SYS_TREE_H_
#define _SYS_TREE_H_

diff --git a/common/c_cpp/src/c/timers.h b/common/c_cpp/src/c/timers.h
index a653dc4..38a3732 100644
--- a/common/c_cpp/src/c/timers.h
+++ b/common/c_cpp/src/c/timers.h
@@ -22,8 +22,7 @@
#ifndef TIMERS_INTERNAL_
#define TIMERS_INTERNAL_

-#include <sys/time.h>
-#include <pthread.h>
+#include "port.h"

typedef void* timerElement;
typedef void* timerHeap;
diff --git a/common/c_cpp/src/c/wSemaphore.c b/common/c_cpp/src/c/wSemaphore.c
index 04b526f..df2bae1 100644
--- a/common/c_cpp/src/c/wSemaphore.c
+++ b/common/c_cpp/src/c/wSemaphore.c
@@ -19,15 +19,11 @@
* 02110-1301 USA
*/

-#include "wombat/wincompat.h"
+#include "port.h"
+
#include "wombat/wSemaphore.h"

#ifndef WIN32
-#include <pthread.h>
-#include <semaphore.h>
-#include <time.h>
-#include <sys/time.h>
-

int wsem_timedwait (wsem_t* sem, unsigned int timeoutval)
{
diff --git a/common/c_cpp/src/c/wlock.c b/common/c_cpp/src/c/wlock.c
index 309b89d..9cd7d21 100644
--- a/common/c_cpp/src/c/wlock.c
+++ b/common/c_cpp/src/c/wlock.c
@@ -19,7 +19,8 @@
* 02110-1301 USA
*/

-#include <pthread.h>
+#include "port.h"
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
diff --git a/common/c_cpp/src/c/wlock.h b/common/c_cpp/src/c/wlock.h
index 4c5a82c..199dad8 100644
--- a/common/c_cpp/src/c/wlock.h
+++ b/common/c_cpp/src/c/wlock.h
@@ -22,11 +22,6 @@
#ifndef _WOMBAT_WLOCK_H
#define _WOMBAT_WLOCK_H

-
-#include "wombat/wincompat.h"
-
-
-
typedef void * wLock;

COMMONExpDLL wLock wlock_create( void );
diff --git a/common/c_cpp/src/c/wombat/queue.h b/common/c_cpp/src/c/wombat/queue.h
index 36590d0..e9e2093 100644
--- a/common/c_cpp/src/c/wombat/queue.h
+++ b/common/c_cpp/src/c/wombat/queue.h
@@ -25,20 +25,7 @@
/*
* Fully thread safe queue implementation.
*/
-
-#ifndef WIN32
-#include <semaphore.h>
-#include <inttypes.h>
-#else
-#include "wombat/wincompat.h"
-#endif
-
-#ifndef WIN32
-/* For Forte */
-#ifndef SEM_VALUE_MAX
-#define SEM_VALUE_MAX 2147483647 /* from headers */
-#endif
-
+#ifdef SEM_VALUE_MAX
#define WOMBAT_QUEUE_MAX_SIZE SEM_VALUE_MAX /* 2_147_483_647 on Linux */
#else
#define WOMBAT_QUEUE_MAX_SIZE 2147483647 /* max possible size */
diff --git a/common/c_cpp/src/c/wombat/strutils.h b/common/c_cpp/src/c/wombat/strutils.h
index b20e712..d5d1fb8 100644
--- a/common/c_cpp/src/c/wombat/strutils.h
+++ b/common/c_cpp/src/c/wombat/strutils.h
@@ -30,13 +30,6 @@ extern "C" {


typedef unsigned long int w_u32_t;
-#ifndef WIN32
-typedef unsigned long long int w_u64_t;
-typedef long long int w_i64_t;
-#else
-typedef unsigned __int64 w_u64_t;
-typedef __int64 w_i64_t;
-#endif
typedef long int w_i32_t;
typedef float w_f32_t;
typedef double w_f64_t;
diff --git a/common/c_cpp/src/c/wombat/wSemaphore.h b/common/c_cpp/src/c/wombat/wSemaphore.h
index 89949a6..9adb8d2 100644
--- a/common/c_cpp/src/c/wombat/wSemaphore.h
+++ b/common/c_cpp/src/c/wombat/wSemaphore.h
@@ -22,55 +22,6 @@
#ifndef WSEMAPHORE_H__
#define WSEMAPHORE_H__

-#ifndef WIN32
-
-#include <pthread.h>
-#include <semaphore.h>
-#include <time.h>
-
-#define wsem_t sem_t
-#define wsem_init sem_init
-#define wsem_post sem_post
-#define wsem_wait sem_wait
-#define wsem_trywait sem_trywait
-#define wsem_destroy sem_destroy
-#define wsem_getvalue sem_getvalue
-
-int wsem_timedwait (wsem_t* sem, unsigned int ts);
-
-#else
-#include "wombat/wincompat.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 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);
-
-#endif
+#include "port.h"

#endif /* WSEMAPHORE_H__ */
diff --git a/common/c_cpp/src/c/wombat/wincompat.h b/common/c_cpp/src/c/wombat/wincompat.h
index 5c78acb..756ecea 100644
--- a/common/c_cpp/src/c/wombat/wincompat.h
+++ b/common/c_cpp/src/c/wombat/wincompat.h
@@ -22,6 +22,7 @@
#ifndef _WOMBAT_WINCOMPAT_H
#define _WOMBAT_WINCOMPAT_H

+#include "port.h"
#include "wConfig.h"

#define PATHSEP "/"
--
1.7.7.6


[PATCH 02/30] Moved Calling Convention from wConfig.h to linux/port.h

Michael Schonberg <mschonberg@...>
 

These are OS specific. wConfig remains for backwards compatibilit; however, it
may be removed in the future. They all default to a no-op for Linux, but are
required for different Windows builds (dynamic, static, debug, etc).

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/src/c/wombat/wConfig.h | 72 +----------------------------------
1 files changed, 2 insertions(+), 70 deletions(-)

diff --git a/common/c_cpp/src/c/wombat/wConfig.h b/common/c_cpp/src/c/wombat/wConfig.h
index c2137df..c7cf7af 100644
--- a/common/c_cpp/src/c/wombat/wConfig.h
+++ b/common/c_cpp/src/c/wombat/wConfig.h
@@ -22,76 +22,8 @@
#ifndef _WOMBAT_WCONFIG_H
#define _WOMBAT_WCONFIG_H

-/* This section defines export semantics for functions exported or
- * imported from Windows libraries. All exported functions must
- * be decorated with the appropriate modifier.
- */
-
-#if defined( WIN32 ) && defined( COMMON_DLL )
- /* We are building common dll */
-# define COMMONExpDLL __declspec( dllexport )
-#elif defined( WIN32 ) && 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( WIN32 ) && 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
-#elif defined( WIN32 ) && 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( WIN32 ) && 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( WIN32 ) && 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( WIN32 ) && !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
-#else
- /* We are building on linux or statically */
-# define COMMONExpDLL
-# define WMWExpDLL
-# define MAMAExpDLL
-# define MAMACPPExpDLL
-# define MAMDAExpDLL
-# define MAMDAOPTExpDLL
-# define MAMAExpBridgeDLL
-#endif /* WIN32 */
-
-/*
- * Windows callback functions require the standard call type.
- */
-#ifdef WIN32
-#define MAMACALLTYPE __stdcall
-#else
-#define MAMACALLTYPE
-#endif
+/* Moved to _os_/port/h */
+#include "port.h"

#endif /* _WOMBAT_WCONFIG_H */

--
1.7.7.6


[PATCH 03/30] Moved environment.c to linux/environment.c

Michael Schonberg <mschonberg@...>
 

The funcitons for manipulating environement variables are os-specific. We
may want to add a generic directory for a default implemenation.

This is in preparation for the windows port.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/configure.ac | 3 +-
common/c_cpp/src/c/environment.c | 59 --------------------------------
common/c_cpp/src/c/linux/environment.c | 59 ++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+), 60 deletions(-)
delete mode 100644 common/c_cpp/src/c/environment.c
create mode 100644 common/c_cpp/src/c/linux/environment.c

diff --git a/common/c_cpp/configure.ac b/common/c_cpp/configure.ac
index 9b08055..b6f537a 100755
--- a/common/c_cpp/configure.ac
+++ b/common/c_cpp/configure.ac
@@ -46,7 +46,8 @@ AC_CANONICAL_BUILD()
# Set up symbolic links for os-specific files
AC_MSG_NOTICE([Configuring symbolic links for $build_os in $srcdir])
case $build_os in
- linux*-*) AC_CONFIG_LINKS([src/c/port.h:src/c/linux/port.h]) ;;
+ linux*-*) AC_CONFIG_LINKS([src/c/port.h:src/c/linux/port.h
+ src/c/environment.c:src/c/linux/environment.c]) ;;
esac

# Checks for programs.
diff --git a/common/c_cpp/src/c/environment.c b/common/c_cpp/src/c/environment.c
deleted file mode 100644
index 34affc0..0000000
--- a/common/c_cpp/src/c/environment.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/* $Id: environment.c,v 1.2.2.3.12.2 2011/08/10 14:53:23 nicholasmarriott Exp $
- *
- * 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
- */
-
-/* ********************************************************** */
-/* Includes. */
-/* ********************************************************** */
-#include "stdlib.h"
-#include "wombat/environment.h"
-
-int environment_deleteVariable(const char *name)
-{
- return unsetenv(name);
-}
-
-const char *environment_getVariable(const char *name)
-{
- /* Returns. */
- const char *ret = NULL;
-
- /* Check the argument. */
- if(name != NULL)
- {
- ret = getenv(name);
- }
-
- return ret;
-}
-
-int environment_setVariable(const char *name, const char *value)
-{
- /* Returns. */
- int ret = -1;
-
- /* Check the arguments. */
- if((name != NULL) && (value != NULL))
- {
- ret = setenv(name, value, 1);
- }
-
- return ret;
-}
diff --git a/common/c_cpp/src/c/linux/environment.c b/common/c_cpp/src/c/linux/environment.c
new file mode 100644
index 0000000..34affc0
--- /dev/null
+++ b/common/c_cpp/src/c/linux/environment.c
@@ -0,0 +1,59 @@
+/* $Id: environment.c,v 1.2.2.3.12.2 2011/08/10 14:53:23 nicholasmarriott Exp $
+ *
+ * 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
+ */
+
+/* ********************************************************** */
+/* Includes. */
+/* ********************************************************** */
+#include "stdlib.h"
+#include "wombat/environment.h"
+
+int environment_deleteVariable(const char *name)
+{
+ return unsetenv(name);
+}
+
+const char *environment_getVariable(const char *name)
+{
+ /* Returns. */
+ const char *ret = NULL;
+
+ /* Check the argument. */
+ if(name != NULL)
+ {
+ ret = getenv(name);
+ }
+
+ return ret;
+}
+
+int environment_setVariable(const char *name, const char *value)
+{
+ /* Returns. */
+ int ret = -1;
+
+ /* Check the arguments. */
+ if((name != NULL) && (value != NULL))
+ {
+ ret = setenv(name, value, 1);
+ }
+
+ return ret;
+}
--
1.7.7.6


[PATCH 04/30] Moved linux code from machine.c to linux/machine.c

Michael Schonberg <mschonberg@...>
 

In preparation for windows support, machine.c contains generic code while
Linux specific code is now in linux/machine.c

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/configure.ac | 1 +
common/c_cpp/src/c/Makefile.am | 1 +
common/c_cpp/src/c/linux/machine.c | 599 ++++++++++++++++++++++++++++++++++++
common/c_cpp/src/c/machine.c | 566 +---------------------------------
4 files changed, 603 insertions(+), 564 deletions(-)
create mode 100644 common/c_cpp/src/c/linux/machine.c

diff --git a/common/c_cpp/configure.ac b/common/c_cpp/configure.ac
index b6f537a..31e78fc 100755
--- a/common/c_cpp/configure.ac
+++ b/common/c_cpp/configure.ac
@@ -47,6 +47,7 @@ AC_CANONICAL_BUILD()
AC_MSG_NOTICE([Configuring symbolic links for $build_os in $srcdir])
case $build_os in
linux*-*) AC_CONFIG_LINKS([src/c/port.h:src/c/linux/port.h
+ src/c/machine_port.c:src/c/linux/machine.c
src/c/environment.c:src/c/linux/environment.c]) ;;
esac

diff --git a/common/c_cpp/src/c/Makefile.am b/common/c_cpp/src/c/Makefile.am
index facce7c..362d457 100644
--- a/common/c_cpp/src/c/Makefile.am
+++ b/common/c_cpp/src/c/Makefile.am
@@ -66,6 +66,7 @@ libwombatcommon_la_SOURCES = \
list.c \
lookup2.c \
machine.c \
+ machine_port.c \
platform.c \
properties.l \
property.c \
diff --git a/common/c_cpp/src/c/linux/machine.c b/common/c_cpp/src/c/linux/machine.c
new file mode 100644
index 0000000..375734c
--- /dev/null
+++ b/common/c_cpp/src/c/linux/machine.c
@@ -0,0 +1,599 @@
+/* $Id: machine.c,v 1.50.16.9 2011/08/10 14:53:24 nicholasmarriott Exp $
+ *
+ * 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 <sys/stat.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "wombat/machine.h"
+#include "wombat/wtable.h"
+
+/* Macros for extract VSIZE and RSS from /proc/pid/stats files */
+#define bytetok(x) (((x) + 512) >> 10)
+
+#define MAXPROCSARRAY 1000 /* need to keep track of processes */
+
+extern int useLWP;
+static int numProc = 0;
+static pid_t procTable[MAXPROCSARRAY];
+static int flagTable[MAXPROCSARRAY];
+
+static char* skip_ws (char* p);
+static char* skip_token (char* p);
+static int uniqueSet (int lhs, int rhs);
+static int isInSet (int lhs, int rhs, int pid);
+void searchDirs (int procChildren[],
+ int dirNames[],
+ int count,
+ cpuVals* cpv,
+ int tempPid);
+pid_t getParentPid (pid_t pid,
+ int childFlag);
+
+time_t getTimeSinceEpoch(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+ return tv.tv_sec;
+}
+
+static char* skip_ws(char* p)
+{
+ while (isspace(*p))
+ p++;
+ return p;
+}
+
+static char* skip_token(char* p)
+{
+ while (isspace(*p))
+ p++;
+ while (*p && !isspace(*p))
+ p++;
+ return p;
+}
+
+void getProcAndChildCpu(int pid, cpuVals* cpv)
+{
+ int i=0;
+ struct cpuVals tempCpu;
+ tempCpu.userTime=0;
+ tempCpu.sysTime=0;
+ cpv->userTime=0;
+ cpv->sysTime=0;
+ for(i = 0; i < numProc; i++)
+ {
+ getProcessInfo(procTable[i],NULL,&tempCpu,flagTable[i]);
+ cpv->userTime += tempCpu.userTime;
+ cpv->sysTime += tempCpu.sysTime;
+ }
+}
+
+int getNumCpu(void)
+{
+ return sysconf (_SC_NPROCESSORS_ONLN);
+}
+
+void initProcTable(int pid, int debuginfo)
+{
+ DIR *dir = NULL;
+ char buffer[4096] = "";
+ struct dirent *ent = NULL;
+ pid_t allPpidTable[MAXPROCSARRAY];
+ pid_t allProcTable[MAXPROCSARRAY];
+ int allFlagTable[MAXPROCSARRAY];
+ pid_t tempPid = 0;
+ int numAllProc = 0;
+ int childFlag = 0;
+ int i = 0;
+ int currentIndex = 0;
+ int childrenIndex = 0;
+ pid_t pgrp = 0;
+ char *dirNamePtr = NULL;
+
+ /* Trying to find all child process by using ppid and pid relationship.*/
+ dir = opendir("/proc/");
+ while ((ent = readdir(dir)) != NULL)
+ {
+ dirNamePtr = ent->d_name;
+ if (ent->d_name[0] == '.')
+ {
+ dirNamePtr += 1;
+ childFlag = 1;
+ }
+ if (isdigit(dirNamePtr[0]))
+ {
+ tempPid=(pid_t)strtol(dirNamePtr,NULL,10);
+
+ if(tempPid!=pid)
+ {
+ allPpidTable[numAllProc] = getParentPid(tempPid,childFlag);
+ if (allPpidTable[numAllProc] == 0)
+ {
+ /* process must have exited, do not store information reg
+ this pid */
+ continue;
+ }
+ allProcTable[numAllProc] = tempPid;
+ allFlagTable[numAllProc] = childFlag;
+ numAllProc++;
+
+ }
+ }
+ childFlag = 0;
+ }
+ closedir(dir);
+
+ procTable[0]=pid;
+ flagTable[0]=0;
+ numProc=1;
+ while(1)
+ {
+ for(i=0;i<numAllProc;i++)
+ {
+ if(allPpidTable[i]==procTable[currentIndex])
+ {
+ childrenIndex++;
+ procTable[childrenIndex]=allProcTable[i];
+ flagTable[childrenIndex]=allFlagTable[i];
+ numProc++;
+ }
+ }
+ if(currentIndex==childrenIndex)
+ {
+ break;
+ }
+ currentIndex++;
+ }
+
+
+ /* Trying to find all child processes by using group pid. */
+ dir = opendir("/proc/");
+ while ((ent = readdir(dir)) != NULL)
+ {
+ /* get pgrp related processes*/
+ dirNamePtr = ent->d_name;
+ childFlag = 0;
+ if (ent->d_name[0] == '.')
+ {
+ dirNamePtr += 1;
+ childFlag = 1;
+ }
+ if (isdigit(dirNamePtr[0]))
+ {
+ tempPid=(int) strtol(dirNamePtr,NULL,10);
+ if (tempPid==pid)
+ continue;
+ pgrp = getpgid (tempPid);
+ if (pgrp == pid)
+ {
+ procTable[numProc]=tempPid;
+ flagTable[numProc]=childFlag;
+ numProc++;
+ }
+ }
+ }
+ closedir(dir);
+
+ /* Trying to find all child processes via LWP on 64 bit */
+ if (useLWP)
+ {
+ sprintf(buffer, "/proc/%d/task", pid);
+ dir = opendir(buffer);
+ if (dir != NULL)
+ {
+ while ((ent = readdir(dir)) != NULL)
+ {
+ dirNamePtr = ent->d_name;
+ childFlag = 0;
+ if (isdigit(dirNamePtr[0]))
+ {
+ tempPid=(int) strtol(dirNamePtr,NULL,10);
+ if (tempPid==pid)
+ continue;
+ procTable[numProc]=tempPid;
+ flagTable[numProc]=childFlag;
+ numProc++;
+ }
+ }
+ closedir(dir);
+ }
+ }
+
+ /* On some linux kernels only one of above methods works. On other kernel
+ * versons both work. So we need to remove duplicated entries
+ */
+
+ numProc = uniqueSet (0, numProc);
+
+ if(debuginfo)
+ {
+ printf("Debug Info for Stats - Processes Table\n");
+ for(i=0;i<numProc;i++)
+ {
+ printf("%d-%d\n",procTable[i],flagTable[i]);
+ }
+ }
+}
+
+/* Take out duplicated entries. So the result is a unique set of pids.*/
+static int uniqueSet (int lhs, int rhs)
+{
+ int curProc = procTable[lhs];
+ int dup = 0;
+
+ if (lhs == rhs - 1)
+ {
+ if (procTable [lhs] == procTable [rhs])
+ return lhs;
+ else
+ return rhs;
+ }
+ rhs = uniqueSet (lhs + 1, rhs);
+ dup = isInSet (lhs + 1, rhs, curProc);
+ if (dup != -1)
+ {
+ procTable[dup] = procTable[rhs];
+ flagTable[dup] = flagTable[rhs];
+ rhs --;
+ }
+ return rhs;
+}
+
+static int isInSet (int lhs, int rhs, int pid)
+{
+ int i = 0;
+ for (i = lhs; i <= rhs; i++)
+ {
+ if (pid == procTable[i])
+ return i;
+ }
+ return -1;
+}
+
+pid_t getParentPid(pid_t pid, int childFlag)
+{
+ char buffer[4096], *p, *q;
+ int state =0;
+ pid_t ppid=0;
+ char name[64];
+ int len = 0;
+ /* grab the proc stat info in one go */
+ {
+ int fd, len;
+ if(childFlag==1)
+ sprintf(buffer, "/proc/.%d/stat", pid);
+ else
+ sprintf(buffer, "/proc/%d/stat", pid);
+
+ fd = open(buffer, 0);
+
+ if (fd==-1)
+ {
+ return 0;
+ }
+
+ len = read(fd, buffer, sizeof(buffer)-1);
+ close(fd);
+ if (len==-1)
+ {
+ return 0;
+ }
+ buffer[len] = '\0';
+ }
+ /* parse out the status */
+ p = buffer;
+ p = strchr(p, '('); /* skip pid */
+ if (p==NULL)
+ {
+ /* Process has exited since the pid was initially obtained */
+ return 0;
+ }
+ {
+ ++p; /* increment past the '(' char */
+ q = strrchr(p, ')'); /*process name*/
+ len = q-p;
+ if (len >= sizeof(name))
+ len = sizeof(name)-1;
+ memcpy(name, p, len);
+ name[len] = 0;
+ p = q+1;
+ }
+ p = skip_ws(p);
+ switch (*p++)
+ {
+ case 'R': state = 1; break;
+ case 'S': state = 2; break;
+ case 'D': state = 3; break;
+ case 'Z': state = 4; break;
+ case 'T': state = 5; break;
+ case 'W': state = 6; break;
+ }
+ ppid = (pid_t)strtol(p,&p,10); /* skip ppid */
+ return ppid;
+}
+
+void searchDirs(int procChildren[], int dirNames[],
+ int count,cpuVals *cpv,int tempPid)
+{
+ int x=0,ppid=0;
+ struct cpuVals tempCpu;
+ for(x = 0; x < count; x++)
+ {
+ ppid = getProcessInfo(dirNames[x],NULL,&tempCpu,procChildren[x]);
+ if(ppid==tempPid)
+ {
+ cpv->userTime += tempCpu.userTime;
+ cpv->sysTime += tempCpu.sysTime;
+ searchDirs(procChildren,dirNames,count,cpv,dirNames[x]);
+ }
+ else
+ {
+ tempCpu.userTime=0;
+ tempCpu.sysTime=0;
+ }
+ }
+}
+
+static long pagetok(long x)
+{
+ /*
+ * This replaces:
+ *
+ * #include <asm/page.h>
+ *
+ * #define pagetok(x) ((x) << (PAGE_SHIFT - 10))
+ *
+ * which is deprecated according to RedHat
+ */
+ static int initDone = 0;
+ static int pageShift = 0;
+
+ if (!initDone) {
+ int pgSize = sysconf(_SC_PAGESIZE);
+
+ /* We have to calc the power-of-2 that the page size represents */
+ for (pageShift = 0; !(pgSize & 0x01); pageShift++, pgSize >>= 1)
+ ;
+
+ /* Convert to 1K units */
+ pageShift -= 10;
+ initDone = 1;
+ }
+ return (x << pageShift);
+}
+
+int getProcessInfo(int pid ,memVals *memV,cpuVals *cpuV,int childFlag)
+{
+ char buffer[4096], *p;
+ int state =0;
+ int ppid=0;
+ long totalMem = getTotalSystemMem();
+ double cpuClockTicksPerSecond = (double)sysconf(_SC_CLK_TCK);
+ /* grab the proc stat info in one go */
+ {
+ int fd, len;
+ if(childFlag==1)
+ sprintf(buffer, "/proc/.%d/stat", pid);
+ else
+ sprintf(buffer, "/proc/%d/stat", pid);
+
+ fd = open(buffer, 0);
+ if (fd == -1)
+ {
+ if (cpuV)
+ {
+ cpuV->userTime = 0;
+ cpuV->sysTime = 0;
+ }
+ if(memV)
+ {
+ memV->vsize = 0;
+ memV->rss = 0;
+ memV->memPercent = 0;
+ }
+ return 0;
+ }
+ len = read(fd, buffer, sizeof(buffer)-1);
+ close(fd);
+ buffer[len] = '\0';
+ }
+ /* parse out the status */
+ p = buffer;
+ p = strchr(p, '(')+1; /* skip pid */
+ {
+ char name[64];
+ char *q = strrchr(p, ')'); /*process name*/
+ int len = q-p;
+ if (len >= sizeof(name))
+ len = sizeof(name)-1;
+ memcpy(name, p, len);
+ name[len] = 0;
+ p = q+1;
+ }
+ p = skip_ws(p);
+ switch (*p++)
+ {
+ case 'R': state = 1; break;
+ case 'S': state = 2; break;
+ case 'D': state = 3; break;
+ case 'Z': state = 4; break;
+ case 'T': state = 5; break;
+ case 'W': state = 6; break;
+ }
+
+ ppid = (int)strtol(p,&p,10); /* skip ppid */
+ p = skip_token(p); /* skip pgrp */
+ p = skip_token(p); /* skip session */
+ p = skip_token(p); /* skip tty */
+ p = skip_token(p); /* skip tty pgrp */
+ p = skip_token(p); /* skip flags */
+ p = skip_token(p); /* skip min flt */
+ p = skip_token(p); /* skip cmin flt */
+ p = skip_token(p); /* skip maj flt */
+ p = skip_token(p); /* skip cmaj flt */
+ if(cpuV)
+ {
+ cpuV->userTime = ((double)strtoul(p, &p, 10))/cpuClockTicksPerSecond; /* utime */
+ cpuV->sysTime = ((double)strtoul(p, &p, 10))/cpuClockTicksPerSecond; /* stime */
+ }
+ else
+ {
+ p = skip_token(p); /* skip utime */
+ p = skip_token(p); /* skip stime */
+ }
+ p = skip_token(p); /* skip cutime */
+ p = skip_token(p); /* skip cstime */
+
+ p = skip_token(p); /* skip priority */
+ p = skip_token(p); /* skip nice */
+
+ p = skip_token(p); /* skip timeout */
+ p = skip_token(p); /* skip it_real_val */
+ p = skip_token(p); /* skip start_time */
+
+ if(memV)
+ {
+ memV->vsize = bytetok(strtoul(p, &p, 10)); /* vsize */
+ memV->rss = pagetok(strtoul(p, &p, 10)); /* rss */
+ memV->memPercent =(double)(memV->rss*100.0)/(double)totalMem;
+ }
+
+ return ppid;
+}
+
+int getSystemMemory (systemMemVals* mem)
+{
+ FILE* fp;
+ char buffer[4096];
+ size_t bytes_read;
+ char* match;
+ long totalMem=-1,freeMem=-1,totalSwap=-1,freeSwap=-1;
+
+ fp = fopen ("/proc/meminfo","r");
+ if (fp==NULL)
+ return -1;
+ bytes_read = fread(buffer, 1, sizeof (buffer), fp);
+ fclose(fp);
+
+ if (bytes_read==0 || bytes_read == sizeof (buffer))
+ return -1;
+ buffer[bytes_read] = '\0';
+
+ match = strstr (buffer, "MemTotal:");
+ if (match == NULL)
+ return -1;
+ sscanf (match, "MemTotal:%ld", &totalMem);
+ match = strstr (buffer, "MemFree:");
+ if (match == NULL)
+ return -1;
+ sscanf (match, "MemFree:%ld", &freeMem);
+ match = strstr (buffer, "SwapTotal:");
+ if (match == NULL)
+ return -1;
+ sscanf (match, "SwapTotal:%ld", &totalSwap);
+ match = strstr (buffer, "SwapFree:");
+ if (match == NULL)
+ return -1;
+ sscanf (match, "SwapFree:%ld", &freeSwap);
+
+ mem->totalMem=totalMem;
+ mem->freeMem=freeMem;
+ mem->totalSwap=totalSwap;
+ mem->freeSwap=freeSwap;
+ return 0;
+}
+
+long getTotalSystemMem(void)
+{
+ /* get system wide memory usage */
+ FILE* fp;
+ char buffer[4096];
+ size_t bytes_read;
+ char* match;
+ long totalMem=-1;
+
+ fp = fopen ("/proc/meminfo","r");
+ if (fp==NULL)
+ return totalMem;
+ bytes_read = fread(buffer, 1, sizeof (buffer), fp);
+ fclose(fp);
+
+ if (bytes_read==0 || bytes_read == sizeof (buffer))
+ return totalMem;
+ buffer[bytes_read] = '\0';
+
+ match = strstr (buffer, "MemTotal:");
+ if (match == NULL)
+ return totalMem;
+
+ sscanf (match, "MemTotal:%ld", &totalMem);
+ return totalMem;
+}
+
+void getSystemTime(double* upTime,double* idleTime)
+{
+ FILE* fp;
+ *upTime = 0;
+ *idleTime = 0;
+ fp = fopen("/proc/uptime", "r");
+ if (fp==NULL)
+ return;
+ fscanf (fp, "%lf %lf\n", upTime, idleTime);
+ fclose (fp);
+}
+
+void getProcessorTime(long* usageTime,long* idleTime,int processor)
+{
+ FILE* fp;
+ char buffer[4096];
+ char cpu[10];
+ size_t bytes_read;
+ char* match;
+ long user_read, system_read, nice_read, idle_read;
+ *usageTime = 0;
+ *idleTime = 0;
+
+ fp = fopen ("/proc/stat","r");
+ if (fp==NULL)
+ return;
+ bytes_read = fread(buffer, 1, sizeof (buffer), fp);
+ fclose(fp);
+ if (bytes_read==0 || bytes_read == sizeof (buffer))
+ return;
+ buffer[bytes_read] = '\0';
+ sprintf(cpu,"cpu%d ",processor);
+ match = strstr (buffer, cpu);
+ if (match == NULL)
+ return;
+ sscanf(match, "%*s %ld %ld %ld %ld", &user_read,&system_read,&nice_read,&idle_read);
+ *usageTime = user_read + system_read + nice_read;
+ *idleTime = idle_read;
+}
diff --git a/common/c_cpp/src/c/machine.c b/common/c_cpp/src/c/machine.c
index 512e1ab..fc43143 100644
--- a/common/c_cpp/src/c/machine.c
+++ b/common/c_cpp/src/c/machine.c
@@ -1,5 +1,4 @@
-/* $Id: machine.c,v 1.50.16.9 2011/08/10 14:53:24 nicholasmarriott Exp $
- *
+/*
* OpenMAMA: The open middleware agnostic messaging API
* Copyright (C) 2011 NYSE Inc.
*
@@ -35,28 +34,7 @@
#include "wombat/machine.h"
#include "wombat/wtable.h"

-static int useLWP = 1;
-
-/* Macros for extract VSIZE and RSS from /proc/pid/stats files */
-#define bytetok(x) (((x) + 512) >> 10)
-
-#define MAXPROCSARRAY 1000 /* need to keep track of processes */
-
-static int numProc = 0;
-static pid_t procTable[MAXPROCSARRAY];
-static int flagTable[MAXPROCSARRAY];
-
-static char* skip_ws (char* p);
-static char* skip_token (char* p);
-static int uniqueSet (int lhs, int rhs);
-static int isInSet (int lhs, int rhs, int pid);
-void searchDirs (int procChildren[],
- int dirNames[],
- int count,
- cpuVals* cpv,
- int tempPid);
-pid_t getParentPid (pid_t pid,
- int childFlag);
+int useLWP = 1;

void enableLWP(void)
{
@@ -76,543 +54,3 @@ void getMemVals(int pid, memVals *memV)
getProcessInfo(pid,memV,NULL,0);
}

-time_t getTimeSinceEpoch(void)
-{
- struct timeval tv;
- gettimeofday(&tv,NULL);
- return tv.tv_sec;
-}
-
-static char* skip_ws(char* p)
-{
- while (isspace(*p))
- p++;
- return p;
-}
-
-static char* skip_token(char* p)
-{
- while (isspace(*p))
- p++;
- while (*p && !isspace(*p))
- p++;
- return p;
-}
-
-void getProcAndChildCpu(int pid, cpuVals* cpv)
-{
- int i=0;
- struct cpuVals tempCpu;
- tempCpu.userTime=0;
- tempCpu.sysTime=0;
- cpv->userTime=0;
- cpv->sysTime=0;
- for(i = 0; i < numProc; i++)
- {
- getProcessInfo(procTable[i],NULL,&tempCpu,flagTable[i]);
- cpv->userTime += tempCpu.userTime;
- cpv->sysTime += tempCpu.sysTime;
- }
-}
-
-int getNumCpu(void)
-{
- return sysconf (_SC_NPROCESSORS_ONLN);
-}
-
-void initProcTable(int pid, int debuginfo)
-{
- DIR *dir = NULL;
- char buffer[4096] = "";
- struct dirent *ent = NULL;
- pid_t allPpidTable[MAXPROCSARRAY];
- pid_t allProcTable[MAXPROCSARRAY];
- int allFlagTable[MAXPROCSARRAY];
- pid_t tempPid = 0;
- int numAllProc = 0;
- int childFlag = 0;
- int i = 0;
- int currentIndex = 0;
- int childrenIndex = 0;
- pid_t pgrp = 0;
- char *dirNamePtr = NULL;
-
- /* Trying to find all child process by using ppid and pid relationship.*/
- dir = opendir("/proc/");
- while ((ent = readdir(dir)) != NULL)
- {
- dirNamePtr = ent->d_name;
- if (ent->d_name[0] == '.')
- {
- dirNamePtr += 1;
- childFlag = 1;
- }
- if (isdigit(dirNamePtr[0]))
- {
- tempPid=(pid_t)strtol(dirNamePtr,NULL,10);
-
- if(tempPid!=pid)
- {
- allPpidTable[numAllProc] = getParentPid(tempPid,childFlag);
- if (allPpidTable[numAllProc] == 0)
- {
- /* process must have exited, do not store information reg
- this pid */
- continue;
- }
- allProcTable[numAllProc] = tempPid;
- allFlagTable[numAllProc] = childFlag;
- numAllProc++;
-
- }
- }
- childFlag = 0;
- }
- closedir(dir);
-
- procTable[0]=pid;
- flagTable[0]=0;
- numProc=1;
- while(1)
- {
- for(i=0;i<numAllProc;i++)
- {
- if(allPpidTable[i]==procTable[currentIndex])
- {
- childrenIndex++;
- procTable[childrenIndex]=allProcTable[i];
- flagTable[childrenIndex]=allFlagTable[i];
- numProc++;
- }
- }
- if(currentIndex==childrenIndex)
- {
- break;
- }
- currentIndex++;
- }
-
-
- /* Trying to find all child processes by using group pid. */
- dir = opendir("/proc/");
- while ((ent = readdir(dir)) != NULL)
- {
- /* get pgrp related processes*/
- dirNamePtr = ent->d_name;
- childFlag = 0;
- if (ent->d_name[0] == '.')
- {
- dirNamePtr += 1;
- childFlag = 1;
- }
- if (isdigit(dirNamePtr[0]))
- {
- tempPid=(int) strtol(dirNamePtr,NULL,10);
- if (tempPid==pid)
- continue;
- pgrp = getpgid (tempPid);
- if (pgrp == pid)
- {
- procTable[numProc]=tempPid;
- flagTable[numProc]=childFlag;
- numProc++;
- }
- }
- }
- closedir(dir);
-
- /* Trying to find all child processes via LWP on 64 bit */
- if (useLWP)
- {
- sprintf(buffer, "/proc/%d/task", pid);
- dir = opendir(buffer);
- if (dir != NULL)
- {
- while ((ent = readdir(dir)) != NULL)
- {
- dirNamePtr = ent->d_name;
- childFlag = 0;
- if (isdigit(dirNamePtr[0]))
- {
- tempPid=(int) strtol(dirNamePtr,NULL,10);
- if (tempPid==pid)
- continue;
- procTable[numProc]=tempPid;
- flagTable[numProc]=childFlag;
- numProc++;
- }
- }
- closedir(dir);
- }
- }
-
- /* On some linux kernels only one of above methods works. On other kernel
- * versons both work. So we need to remove duplicated entries
- */
-
- numProc = uniqueSet (0, numProc);
-
- if(debuginfo)
- {
- printf("Debug Info for Stats - Processes Table\n");
- for(i=0;i<numProc;i++)
- {
- printf("%d-%d\n",procTable[i],flagTable[i]);
- }
- }
-}
-
-/* Take out duplicated entries. So the result is a unique set of pids.*/
-static int uniqueSet (int lhs, int rhs)
-{
- int curProc = procTable[lhs];
- int dup = 0;
-
- if (lhs == rhs - 1)
- {
- if (procTable [lhs] == procTable [rhs])
- return lhs;
- else
- return rhs;
- }
- rhs = uniqueSet (lhs + 1, rhs);
- dup = isInSet (lhs + 1, rhs, curProc);
- if (dup != -1)
- {
- procTable[dup] = procTable[rhs];
- flagTable[dup] = flagTable[rhs];
- rhs --;
- }
- return rhs;
-}
-
-static int isInSet (int lhs, int rhs, int pid)
-{
- int i = 0;
- for (i = lhs; i <= rhs; i++)
- {
- if (pid == procTable[i])
- return i;
- }
- return -1;
-}
-
-pid_t getParentPid(pid_t pid, int childFlag)
-{
- char buffer[4096], *p, *q;
- int state =0;
- pid_t ppid=0;
- char name[64];
- int len = 0;
- /* grab the proc stat info in one go */
- {
- int fd, len;
- if(childFlag==1)
- sprintf(buffer, "/proc/.%d/stat", pid);
- else
- sprintf(buffer, "/proc/%d/stat", pid);
-
- fd = open(buffer, 0);
-
- if (fd==-1)
- {
- return 0;
- }
-
- len = read(fd, buffer, sizeof(buffer)-1);
- close(fd);
- if (len==-1)
- {
- return 0;
- }
- buffer[len] = '\0';
- }
- /* parse out the status */
- p = buffer;
- p = strchr(p, '('); /* skip pid */
- if (p==NULL)
- {
- /* Process has exited since the pid was initially obtained */
- return 0;
- }
- {
- ++p; /* increment past the '(' char */
- q = strrchr(p, ')'); /*process name*/
- len = q-p;
- if (len >= sizeof(name))
- len = sizeof(name)-1;
- memcpy(name, p, len);
- name[len] = 0;
- p = q+1;
- }
- p = skip_ws(p);
- switch (*p++)
- {
- case 'R': state = 1; break;
- case 'S': state = 2; break;
- case 'D': state = 3; break;
- case 'Z': state = 4; break;
- case 'T': state = 5; break;
- case 'W': state = 6; break;
- }
- ppid = (pid_t)strtol(p,&p,10); /* skip ppid */
- return ppid;
-}
-
-void searchDirs(int procChildren[], int dirNames[],
- int count,cpuVals *cpv,int tempPid)
-{
- int x=0,ppid=0;
- struct cpuVals tempCpu;
- for(x = 0; x < count; x++)
- {
- ppid = getProcessInfo(dirNames[x],NULL,&tempCpu,procChildren[x]);
- if(ppid==tempPid)
- {
- cpv->userTime += tempCpu.userTime;
- cpv->sysTime += tempCpu.sysTime;
- searchDirs(procChildren,dirNames,count,cpv,dirNames[x]);
- }
- else
- {
- tempCpu.userTime=0;
- tempCpu.sysTime=0;
- }
- }
-}
-
-static long pagetok(long x)
-{
- /*
- * This replaces:
- *
- * #include <asm/page.h>
- *
- * #define pagetok(x) ((x) << (PAGE_SHIFT - 10))
- *
- * which is deprecated according to RedHat
- */
- static int initDone = 0;
- static int pageShift = 0;
-
- if (!initDone) {
- int pgSize = sysconf(_SC_PAGESIZE);
-
- /* We have to calc the power-of-2 that the page size represents */
- for (pageShift = 0; !(pgSize & 0x01); pageShift++, pgSize >>= 1)
- ;
-
- /* Convert to 1K units */
- pageShift -= 10;
- initDone = 1;
- }
- return (x << pageShift);
-}
-
-int getProcessInfo(int pid ,memVals *memV,cpuVals *cpuV,int childFlag)
-{
- char buffer[4096], *p;
- int state =0;
- int ppid=0;
- long totalMem = getTotalSystemMem();
- double cpuClockTicksPerSecond = (double)sysconf(_SC_CLK_TCK);
- /* grab the proc stat info in one go */
- {
- int fd, len;
- if(childFlag==1)
- sprintf(buffer, "/proc/.%d/stat", pid);
- else
- sprintf(buffer, "/proc/%d/stat", pid);
-
- fd = open(buffer, 0);
- if (fd == -1)
- {
- if (cpuV)
- {
- cpuV->userTime = 0;
- cpuV->sysTime = 0;
- }
- if(memV)
- {
- memV->vsize = 0;
- memV->rss = 0;
- memV->memPercent = 0;
- }
- return 0;
- }
- len = read(fd, buffer, sizeof(buffer)-1);
- close(fd);
- buffer[len] = '\0';
- }
- /* parse out the status */
- p = buffer;
- p = strchr(p, '(')+1; /* skip pid */
- {
- char name[64];
- char *q = strrchr(p, ')'); /*process name*/
- int len = q-p;
- if (len >= sizeof(name))
- len = sizeof(name)-1;
- memcpy(name, p, len);
- name[len] = 0;
- p = q+1;
- }
- p = skip_ws(p);
- switch (*p++)
- {
- case 'R': state = 1; break;
- case 'S': state = 2; break;
- case 'D': state = 3; break;
- case 'Z': state = 4; break;
- case 'T': state = 5; break;
- case 'W': state = 6; break;
- }
-
- ppid = (int)strtol(p,&p,10); /* skip ppid */
- p = skip_token(p); /* skip pgrp */
- p = skip_token(p); /* skip session */
- p = skip_token(p); /* skip tty */
- p = skip_token(p); /* skip tty pgrp */
- p = skip_token(p); /* skip flags */
- p = skip_token(p); /* skip min flt */
- p = skip_token(p); /* skip cmin flt */
- p = skip_token(p); /* skip maj flt */
- p = skip_token(p); /* skip cmaj flt */
- if(cpuV)
- {
- cpuV->userTime = ((double)strtoul(p, &p, 10))/cpuClockTicksPerSecond; /* utime */
- cpuV->sysTime = ((double)strtoul(p, &p, 10))/cpuClockTicksPerSecond; /* stime */
- }
- else
- {
- p = skip_token(p); /* skip utime */
- p = skip_token(p); /* skip stime */
- }
- p = skip_token(p); /* skip cutime */
- p = skip_token(p); /* skip cstime */
-
- p = skip_token(p); /* skip priority */
- p = skip_token(p); /* skip nice */
-
- p = skip_token(p); /* skip timeout */
- p = skip_token(p); /* skip it_real_val */
- p = skip_token(p); /* skip start_time */
-
- if(memV)
- {
- memV->vsize = bytetok(strtoul(p, &p, 10)); /* vsize */
- memV->rss = pagetok(strtoul(p, &p, 10)); /* rss */
- memV->memPercent =(double)(memV->rss*100.0)/(double)totalMem;
- }
-
- return ppid;
-}
-
-int getSystemMemory (systemMemVals* mem)
-{
- FILE* fp;
- char buffer[4096];
- size_t bytes_read;
- char* match;
- long totalMem=-1,freeMem=-1,totalSwap=-1,freeSwap=-1;
-
- fp = fopen ("/proc/meminfo","r");
- if (fp==NULL)
- return -1;
- bytes_read = fread(buffer, 1, sizeof (buffer), fp);
- fclose(fp);
-
- if (bytes_read==0 || bytes_read == sizeof (buffer))
- return -1;
- buffer[bytes_read] = '\0';
-
- match = strstr (buffer, "MemTotal:");
- if (match == NULL)
- return -1;
- sscanf (match, "MemTotal:%ld", &totalMem);
- match = strstr (buffer, "MemFree:");
- if (match == NULL)
- return -1;
- sscanf (match, "MemFree:%ld", &freeMem);
- match = strstr (buffer, "SwapTotal:");
- if (match == NULL)
- return -1;
- sscanf (match, "SwapTotal:%ld", &totalSwap);
- match = strstr (buffer, "SwapFree:");
- if (match == NULL)
- return -1;
- sscanf (match, "SwapFree:%ld", &freeSwap);
-
- mem->totalMem=totalMem;
- mem->freeMem=freeMem;
- mem->totalSwap=totalSwap;
- mem->freeSwap=freeSwap;
- return 0;
-}
-
-long getTotalSystemMem(void)
-{
- /* get system wide memory usage */
- FILE* fp;
- char buffer[4096];
- size_t bytes_read;
- char* match;
- long totalMem=-1;
-
- fp = fopen ("/proc/meminfo","r");
- if (fp==NULL)
- return totalMem;
- bytes_read = fread(buffer, 1, sizeof (buffer), fp);
- fclose(fp);
-
- if (bytes_read==0 || bytes_read == sizeof (buffer))
- return totalMem;
- buffer[bytes_read] = '\0';
-
- match = strstr (buffer, "MemTotal:");
- if (match == NULL)
- return totalMem;
-
- sscanf (match, "MemTotal:%ld", &totalMem);
- return totalMem;
-}
-
-void getSystemTime(double* upTime,double* idleTime)
-{
- FILE* fp;
- *upTime = 0;
- *idleTime = 0;
- fp = fopen("/proc/uptime", "r");
- if (fp==NULL)
- return;
- fscanf (fp, "%lf %lf\n", upTime, idleTime);
- fclose (fp);
-}
-
-void getProcessorTime(long* usageTime,long* idleTime,int processor)
-{
- FILE* fp;
- char buffer[4096];
- char cpu[10];
- size_t bytes_read;
- char* match;
- long user_read, system_read, nice_read, idle_read;
- *usageTime = 0;
- *idleTime = 0;
-
- fp = fopen ("/proc/stat","r");
- if (fp==NULL)
- return;
- bytes_read = fread(buffer, 1, sizeof (buffer), fp);
- fclose(fp);
- if (bytes_read==0 || bytes_read == sizeof (buffer))
- return;
- buffer[bytes_read] = '\0';
- sprintf(cpu,"cpu%d ",processor);
- match = strstr (buffer, cpu);
- if (match == NULL)
- return;
- sscanf(match, "%*s %ld %ld %ld %ld", &user_read,&system_read,&nice_read,&idle_read);
- *usageTime = user_read + system_read + nice_read;
- *idleTime = idle_read;
-}
--
1.7.7.6


[PATCH 05/30] Moved platform.c to linux/platform.c

Michael Schonberg <mschonberg@...>
 

The funcitons for accessing shared libraries in platform.c are os
dependent. This is in prepration for windows support.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/configure.ac | 1 +
common/c_cpp/src/c/linux/platform.c | 85 +++++++++++++++++++++++++++++++++++
common/c_cpp/src/c/platform.c | 85 -----------------------------------
3 files changed, 86 insertions(+), 85 deletions(-)
create mode 100644 common/c_cpp/src/c/linux/platform.c
delete mode 100644 common/c_cpp/src/c/platform.c

diff --git a/common/c_cpp/configure.ac b/common/c_cpp/configure.ac
index 31e78fc..dfd450b 100755
--- a/common/c_cpp/configure.ac
+++ b/common/c_cpp/configure.ac
@@ -48,6 +48,7 @@ AC_MSG_NOTICE([Configuring symbolic links for $build_os in $srcdir])
case $build_os in
linux*-*) AC_CONFIG_LINKS([src/c/port.h:src/c/linux/port.h
src/c/machine_port.c:src/c/linux/machine.c
+ src/c/platform.c:src/c/linux/platform.c
src/c/environment.c:src/c/linux/environment.c]) ;;
esac

diff --git a/common/c_cpp/src/c/linux/platform.c b/common/c_cpp/src/c/linux/platform.c
new file mode 100644
index 0000000..8bf7f4e
--- /dev/null
+++ b/common/c_cpp/src/c/linux/platform.c
@@ -0,0 +1,85 @@
+/* $Id: platform.c,v 1.8.16.2 2011/08/10 14:53:24 nicholasmarriott Exp $
+ *
+ * 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 <string.h>
+#include <stdlib.h>
+#include <stddef.h>
+
+#include "platform.h"
+#include "wombat/wincompat.h"
+
+/**
+ * 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(PATHSEP) + 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, PATHSEP, libName, LIB_EXTENSION);
+ }
+ else
+ {
+ snprintf (fileName, nameLength, "lib%s%s", libName, LIB_EXTENSION);
+ }
+
+ handle = dlopen (fileName, RTLD_NOW | RTLD_GLOBAL);
+
+ free(fileName);
+ return handle;
+}
+
+
+int closeSharedLib (LIB_HANDLE handle)
+{
+ return dlclose (handle);
+}
+
+void* loadLibFunc (LIB_HANDLE handle, const char* funcName)
+{
+ return dlsym (handle, funcName);
+}
+
+char* getLibError (void)
+{
+ return dlerror();
+}
diff --git a/common/c_cpp/src/c/platform.c b/common/c_cpp/src/c/platform.c
deleted file mode 100644
index 8bf7f4e..0000000
--- a/common/c_cpp/src/c/platform.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/* $Id: platform.c,v 1.8.16.2 2011/08/10 14:53:24 nicholasmarriott Exp $
- *
- * 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 <string.h>
-#include <stdlib.h>
-#include <stddef.h>
-
-#include "platform.h"
-#include "wombat/wincompat.h"
-
-/**
- * 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(PATHSEP) + 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, PATHSEP, libName, LIB_EXTENSION);
- }
- else
- {
- snprintf (fileName, nameLength, "lib%s%s", libName, LIB_EXTENSION);
- }
-
- handle = dlopen (fileName, RTLD_NOW | RTLD_GLOBAL);
-
- free(fileName);
- return handle;
-}
-
-
-int closeSharedLib (LIB_HANDLE handle)
-{
- return dlclose (handle);
-}
-
-void* loadLibFunc (LIB_HANDLE handle, const char* funcName)
-{
- return dlsym (handle, funcName);
-}
-
-char* getLibError (void)
-{
- return dlerror();
-}
--
1.7.7.6


[PATCH 06/30] Moved wincompat.h contents to _os_/port.h

Michael Schonberg <mschonberg@...>
 

In preparation for windows support, wincompat.h now simply includes the
appropriate port.h file. The file remains in the tree as other products
include it.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/src/c/linux/port.h | 4 +++
common/c_cpp/src/c/wombat/wincompat.h | 48 +--------------------------------
2 files changed, 5 insertions(+), 47 deletions(-)

diff --git a/common/c_cpp/src/c/linux/port.h b/common/c_cpp/src/c/linux/port.h
index a1de75d..1a00b25 100644
--- a/common/c_cpp/src/c/linux/port.h
+++ b/common/c_cpp/src/c/linux/port.h
@@ -81,6 +81,8 @@ typedef long long int w_i64_t;
/* For delimiting multiple paths in env variables properties */
#define PATH_DELIM ':'

+#define PATHSEP "/"
+
/* Use Posix semaphores for Linux */
#define wsem_t sem_t
#define wsem_init sem_init
@@ -92,6 +94,8 @@ typedef long long int w_i64_t;

int wsem_timedwait (wsem_t* sem, unsigned int ts);

+#define CPU_AFFINITY_SET cpu_set_t
+
/* User pthreads for linux */
#define wthread_mutex_t pthread_mutex_t
#define wthread_mutex_init pthread_mutex_init
diff --git a/common/c_cpp/src/c/wombat/wincompat.h b/common/c_cpp/src/c/wombat/wincompat.h
index 756ecea..c80c60b 100644
--- a/common/c_cpp/src/c/wombat/wincompat.h
+++ b/common/c_cpp/src/c/wombat/wincompat.h
@@ -22,53 +22,7 @@
#ifndef _WOMBAT_WINCOMPAT_H
#define _WOMBAT_WINCOMPAT_H

+/* Moved to _os_/port.h */
#include "port.h"
-#include "wConfig.h"
-
-#define PATHSEP "/"
-#define CPU_AFFINITY_SET cpu_set_t
-
-#define wthread_mutex_t pthread_mutex_t
-#define wthread_mutex_init pthread_mutex_init
-#define wthread_mutex_unlock pthread_mutex_unlock
-#define wthread_mutex_lock pthread_mutex_lock
-#define wthread_mutex_destroy pthread_mutex_destroy
-
-#define wthread_t pthread_t
-#define wthread_detach pthread_detach
-#define wthread_self pthread_self
-#define wthread_equal pthread_equal
-#define wthread_cleanup_push pthread_cleanup_push
-#define wthread_cleanup_pop pthread_cleanup_pop
-#define wthread_join pthread_join
-#define wthread_create pthread_create
-#define wthread_exit pthread_exit
-
-#define wthread_cond_t pthread_cond_t
-#define wthread_cond_init pthread_cond_init
-#define wthread_cond_signal pthread_cond_signal
-#define wthread_cond_destroy pthread_cond_destroy
-#define wthread_cond_wait pthread_cond_wait
-
-#define wthread_spinlock_t pthread_spinlock_t
-#define wthread_spin_init pthread_spin_init
-#define wthread_spin_unlock pthread_spin_unlock
-#define wthread_spin_lock pthread_spin_lock
-#define wthread_spin_destroy pthread_spin_destroy
-
-#define wdlopen dlopen
-#define wdlsym dlsym
-#define wdlclose dlclose
-#define wdlerror dlerror
-
-#define wthread_attr_t pthread_attr_t
-#define wthread_attr_init pthread_attr_init
-#define wthread_attr_setdetachstate pthread_attr_setdetachstate
-
-#define wthread_mutexattr_t pthread_mutexattr_t
-#define wthread_mutexattr_init pthread_mutexattr_init
-#define wthread_mutexattr_settype pthread_mutexattr_settype
-
-#define wGetCurrentThreadId pthread_self

#endif /* _WOMBAT_WINCOMPAT_H */
--
1.7.7.6


[PATCH 07/30] Changes for queue.c to build on windows

Michael Schonberg <mschonberg@...>
 

We need to call the wthread_xxx macros rather than pthread_xxx. A few
compiler warnings and bugs fixed as well.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/src/c/queue.c | 94 +++++++++++++++++++------------------------
1 files changed, 42 insertions(+), 52 deletions(-)

diff --git a/common/c_cpp/src/c/queue.c b/common/c_cpp/src/c/queue.c
index 03cf678..6ae740b 100644
--- a/common/c_cpp/src/c/queue.c
+++ b/common/c_cpp/src/c/queue.c
@@ -19,15 +19,12 @@
* 02110-1301 USA
*/

-
#include "port.h"
-
-#include "wombat/wSemaphore.h"
-
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include "wombat/queue.h"
+#include "wombat/wSemaphore.h"

#define WQ_REMOVE(impl, ele) \
(ele)->mPrev->mNext = (ele)->mNext; \
@@ -52,7 +49,7 @@ typedef struct wombatQueueItem_
typedef struct
{
wsem_t mSem;
- pthread_mutex_t mLock; /* for multiple readers */
+ wthread_mutex_t mLock; /* for multiple readers */

uint8_t mUnblocking;

@@ -113,10 +110,7 @@ wombatQueue_create (wombatQueue queue, uint32_t maxSize, uint32_t initialSize,
return WOMBAT_QUEUE_SEM_ERR;
}

- if (pthread_mutex_init( &impl->mLock, NULL) != 0)
- {
- return WOMBAT_QUEUE_MTX_ERR;
- }
+ wthread_mutex_init( &impl->mLock, NULL);

initialSize = initialSize == 0 ? WOMBAT_QUEUE_CHUNK_SIZE : initialSize;
wombatQueueImpl_allocChunk (impl, initialSize);
@@ -134,7 +128,7 @@ wombatQueue_destroy (wombatQueue queue)
wombatQueueStatus result = WOMBAT_QUEUE_OK;
wombatQueueItem *curItem;

- pthread_mutex_lock (&impl->mLock);
+ wthread_mutex_lock (&impl->mLock);
/* Free the datas */
curItem = impl->mChunks;
while (curItem)
@@ -144,9 +138,9 @@ wombatQueue_destroy (wombatQueue queue)
curItem = tmp;
}

- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);

- /* Thee wsem_destroy and pthread_mutex_destroy methods simply makes
+ /* Thee wsem_destroy and wthread_mutex_destroy methods simply makes
* sure that no threads are waiting since the synchronization objects can
* not be destroyed if threads are waiting. We could devise a mechanism
* to ensure that dispatchers are not waiting or dispatching. We can
@@ -162,11 +156,7 @@ wombatQueue_destroy (wombatQueue queue)
result = WOMBAT_QUEUE_SEM_ERR;
}

- if (pthread_mutex_destroy( &impl->mLock) != 0)
- {
- result = WOMBAT_QUEUE_MTX_ERR;
- }
-
+ wthread_mutex_destroy( &impl->mLock);
free (impl);
return WOMBAT_QUEUE_OK;
}
@@ -201,7 +191,7 @@ wombatQueue_enqueue (wombatQueue queue,
wombatQueueImpl* impl = (wombatQueueImpl*)queue;
wombatQueueItem* item = NULL;

- pthread_mutex_lock (&impl->mLock);
+ wthread_mutex_lock (&impl->mLock);

/* If there are no items in the free list, allocate some. It will set the
* next free node to NULL if the queue is too big or there is no memory.
@@ -227,7 +217,7 @@ wombatQueue_enqueue (wombatQueue queue,

/* Notify next available thread that an item is ready */
wsem_post (&impl->mSem);
- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);

return WOMBAT_QUEUE_OK;
}
@@ -254,7 +244,7 @@ wombatQueue_dispatchInt (wombatQueue queue, void** data, void** closure,

if (isTimed)
{
- if (wsem_timedwait (&impl->mSem, timout) !=0)
+ if (wsem_timedwait (&impl->mSem, (unsigned int)timout) !=0)
return WOMBAT_QUEUE_TIMEOUT;
}
else
@@ -271,7 +261,7 @@ wombatQueue_dispatchInt (wombatQueue queue, void** data, void** closure,
}
}

- pthread_mutex_lock (&impl->mLock); /* May be multiple readers */
+ wthread_mutex_lock (&impl->mLock); /* May be multiple readers */

/* remove the item */
head = impl->mHead.mNext;
@@ -288,7 +278,7 @@ wombatQueue_dispatchInt (wombatQueue queue, void** data, void** closure,
closure_ = head->mClosure;
data_ = head->mData;

- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);

if (cb)
{
@@ -326,7 +316,7 @@ wombatQueue_poll (wombatQueue queue, void** data, void** closure)
return WOMBAT_QUEUE_WOULD_BLOCK;
}

- pthread_mutex_lock (&impl->mLock);
+ wthread_mutex_lock (&impl->mLock);

head = impl->mHead.mNext;
WQ_REMOVE (impl, head);
@@ -342,7 +332,7 @@ wombatQueue_poll (wombatQueue queue, void** data, void** closure)
closure_ = head->mClosure;
data_ = head->mData;

- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);

if (cb)
{
@@ -375,7 +365,7 @@ wombatQueueImpl_allocChunk ( wombatQueueImpl* impl, unsigned int items)

/* Create the links */
{
- int i;
+ unsigned int i;
for (i = 0; i < items - 1; i++) /* -1 so last is NULL */
{
result[i].mNext = &result[i+1];
@@ -408,14 +398,14 @@ wombatQueue_flush (wombatQueue queue, wombatQueueFlushCb cb, void* closure)
return WOMBAT_QUEUE_OK;
}

- pthread_mutex_lock (&impl->mLock);
+ wthread_mutex_lock (&impl->mLock);

head = impl->mHead.mNext;
WQ_REMOVE (impl, head);

cb (queue, head->mData, head->mClosure, closure);

- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);

return WOMBAT_QUEUE_OK;
}
@@ -425,7 +415,7 @@ wombatQueueStatus
wombatQueue_next (wombatQueue queue, void** data, void** closure)
{
wombatQueueImpl* impl = (wombatQueueImpl*)queue;
- pthread_mutex_lock (&impl->mLock);
+ wthread_mutex_lock (&impl->mLock);
impl->mIterator = impl->mIterator->mNext;

if (impl->mIterator == &impl->mTail) /* at end */
@@ -439,7 +429,7 @@ wombatQueue_next (wombatQueue queue, void** data, void** closure)
* expected.
*/
impl->mIterator = impl->mIterator->mPrev;
- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);
return WOMBAT_QUEUE_END;
}

@@ -448,7 +438,7 @@ wombatQueue_next (wombatQueue queue, void** data, void** closure)
if (closure)
*closure = impl->mIterator->mClosure;

- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);
return WOMBAT_QUEUE_OK;
}

@@ -456,7 +446,7 @@ wombatQueueStatus
wombatQueue_prev (wombatQueue queue, void** data, void** closure)
{
wombatQueueImpl* impl = (wombatQueueImpl*)queue;
- pthread_mutex_lock (&impl->mLock);
+ wthread_mutex_lock (&impl->mLock);
impl->mIterator = impl->mIterator->mPrev;

if (impl->mIterator == &impl->mHead) /* at beginning */
@@ -470,7 +460,7 @@ wombatQueue_prev (wombatQueue queue, void** data, void** closure)
* expected.
*/
impl->mIterator = impl->mIterator->mNext;
- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);
return WOMBAT_QUEUE_END;
}

@@ -479,7 +469,7 @@ wombatQueue_prev (wombatQueue queue, void** data, void** closure)
if (closure)
*closure = impl->mIterator->mClosure;

- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);
return WOMBAT_QUEUE_OK;
}

@@ -487,7 +477,7 @@ wombatQueueStatus
wombatQueue_cur (wombatQueue queue, void** data, void** closure)
{
wombatQueueImpl* impl = (wombatQueueImpl*)queue;
- pthread_mutex_lock (&impl->mLock);
+ wthread_mutex_lock (&impl->mLock);

if (impl->mIterator == &impl->mHead || impl->mIterator == &impl->mTail)
{
@@ -496,7 +486,7 @@ wombatQueue_cur (wombatQueue queue, void** data, void** closure)
if (closure)
*closure = NULL;

- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);
return WOMBAT_QUEUE_END;
}

@@ -505,7 +495,7 @@ wombatQueue_cur (wombatQueue queue, void** data, void** closure)
if (closure)
*closure = impl->mIterator->mClosure;

- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);
return WOMBAT_QUEUE_OK;
}

@@ -514,11 +504,11 @@ wombatQueue_remove (wombatQueue queue, void** data, void** closure)
{
wombatQueueImpl* impl = (wombatQueueImpl*)queue;
wombatQueueItem* tmp;
- pthread_mutex_lock (&impl->mLock);
+ wthread_mutex_lock (&impl->mLock);

if (impl->mIterator == &impl->mHead || impl->mIterator == &impl->mTail)
{
- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);
return WOMBAT_QUEUE_END;
}

@@ -537,7 +527,7 @@ wombatQueue_remove (wombatQueue queue, void** data, void** closure)
tmp->mNext = impl->mFirstFree.mNext;
impl->mFirstFree.mNext = tmp;

- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);
return WOMBAT_QUEUE_OK;
}

@@ -550,11 +540,11 @@ wombatQueue_insertAfter (wombatQueue queue,
wombatQueueImpl* impl = (wombatQueueImpl*)queue;
wombatQueueItem* item = NULL;

- pthread_mutex_lock (&impl->mLock);
+ wthread_mutex_lock (&impl->mLock);

/* If we are empty and positioned on the tail move to the head. */
if (impl->mIterator == &impl->mTail)
- impl->mIterator == &impl->mHead;
+ impl->mIterator = &impl->mHead;

/* If there are no items in the free list, allocate some. It will set the
* Next free node to NULL if the queue is too big or there is no memeory.
@@ -580,7 +570,7 @@ wombatQueue_insertAfter (wombatQueue queue,

/* Notify next available thread that an item is ready */
wsem_post (&impl->mSem);
- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);

return WOMBAT_QUEUE_OK;
}
@@ -594,11 +584,11 @@ wombatQueue_insertBefore (wombatQueue queue,
wombatQueueImpl* impl = (wombatQueueImpl*)queue;
wombatQueueItem* item = NULL;

- pthread_mutex_lock (&impl->mLock);
+ wthread_mutex_lock (&impl->mLock);

/* If we are empty and positioned on the head move to the tail. */
if (impl->mIterator == &impl->mHead)
- impl->mIterator == &impl->mTail;
+ impl->mIterator = &impl->mTail;

/* If there are no items in the free list, allocate some. It will set the
* Next free node to NULL if the queue is too big or there is no memeory.
@@ -624,7 +614,7 @@ wombatQueue_insertBefore (wombatQueue queue,

/* Notify next available thread that an item is ready */
wsem_post (&impl->mSem);
- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);

return WOMBAT_QUEUE_OK;
}
@@ -636,18 +626,18 @@ wombatQueue_replace (wombatQueue queue,
void* closure)
{
wombatQueueImpl* impl = (wombatQueueImpl*)queue;
- pthread_mutex_lock (&impl->mLock);
+ wthread_mutex_lock (&impl->mLock);

if (impl->mIterator == &impl->mHead || impl->mIterator == &impl->mTail)
{
- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);
return WOMBAT_QUEUE_END;
}

impl->mIterator->mData = data;
impl->mIterator->mClosure = closure;

- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);
return WOMBAT_QUEUE_OK;
}

@@ -656,9 +646,9 @@ wombatQueue_begin (wombatQueue queue)
{
wombatQueueImpl* impl = (wombatQueueImpl*)queue;

- pthread_mutex_lock (&impl->mLock);
+ wthread_mutex_lock (&impl->mLock);
impl->mIterator = &impl->mHead;
- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);

return WOMBAT_QUEUE_OK;
}
@@ -668,9 +658,9 @@ wombatQueue_end (wombatQueue queue)
{
wombatQueueImpl* impl = (wombatQueueImpl*)queue;

- pthread_mutex_lock (&impl->mLock);
+ wthread_mutex_lock (&impl->mLock);
impl->mIterator = &impl->mTail;
- pthread_mutex_unlock (&impl->mLock);
+ wthread_mutex_unlock (&impl->mLock);

return WOMBAT_QUEUE_OK;
}
--
1.7.7.6


[PATCH 08/30] wlock.c changes for windows support

Michael Schonberg <mschonberg@...>
 

The pthread_xxx references changed to wthread_xxx

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/src/c/wlock.c | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/common/c_cpp/src/c/wlock.c b/common/c_cpp/src/c/wlock.c
index 9cd7d21..e23daa6 100644
--- a/common/c_cpp/src/c/wlock.c
+++ b/common/c_cpp/src/c/wlock.c
@@ -39,10 +39,10 @@ wlock_create( void )
{
wLockImpl* rval = calloc(1, sizeof( wLockImpl ) );

- pthread_mutexattr_t attr;
- pthread_mutexattr_init (&attr);
- pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE_NP);
- pthread_mutex_init (&rval->mMutex, &attr);
+ wthread_mutexattr_t attr;
+ wthread_mutexattr_init (&attr);
+ wthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE_NP);
+ wthread_mutex_init (&rval->mMutex, &attr);

return( rval );
}
--
1.7.7.6


[PATCH 09/30] Preparing timer.c and timer.c for windows support

Michael Schonberg <mschonberg@...>
 

These files are required by the Avis bridge as Avis does not provide
native timer support. The changes include changing pthread_xxx calls to
wthread_xxx calls, and implementing macros for socketpair and setting
nonblocking because windows does not support socketpair() and uses a
slightly differfent call for setting non-blocking on a socket.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/src/c/linux/port.h | 7 ++
common/c_cpp/src/c/timers.c | 176 +++++++++++++++++++--------------------
common/c_cpp/src/c/timers.h | 2 +-
3 files changed, 92 insertions(+), 93 deletions(-)

diff --git a/common/c_cpp/src/c/linux/port.h b/common/c_cpp/src/c/linux/port.h
index 1a00b25..f8b711c 100644
--- a/common/c_cpp/src/c/linux/port.h
+++ b/common/c_cpp/src/c/linux/port.h
@@ -40,6 +40,7 @@ extern "C"
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/times.h>
+#include <sys/socket.h>
#include <netinet/in.h>
#include <semaphore.h>
#include <dirent.h>
@@ -94,9 +95,15 @@ typedef long long int w_i64_t;

int wsem_timedwait (wsem_t* sem, unsigned int ts);

+/* Windows does not support AF_UNIX sockets, socketpairs, etc */
+#define wsocketpair(dom, type, prot, pair) (socketpair((dom),(type),(prot),(pair)))
+#define wsetnonblock(s) (fcntl((s), F_SETFL, O_NONBLOCK))
+
#define CPU_AFFINITY_SET cpu_set_t

/* User pthreads for linux */
+#define INVALID_THREAD (-1)
+
#define wthread_mutex_t pthread_mutex_t
#define wthread_mutex_init pthread_mutex_init
#define wthread_mutex_unlock pthread_mutex_unlock
diff --git a/common/c_cpp/src/c/timers.c b/common/c_cpp/src/c/timers.c
index 5901643..b5680c8 100644
--- a/common/c_cpp/src/c/timers.c
+++ b/common/c_cpp/src/c/timers.c
@@ -19,11 +19,10 @@
* 02110-1301 USA
*/

+#include "port.h"
#include "timers.h"

-#include <sys/socket.h>
#include <sys/types.h>
-#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
@@ -59,41 +58,33 @@ RB_GENERATE_STATIC(orderedTimeRBTree_, timerImpl_, mTreeEntry, orderedTimeRBTree

typedef struct timerHeapImpl_
{
- pthread_mutex_t mLock;
- pthread_t mDispatchThread;
+ wthread_mutex_t mLock;
+ wthread_t mDispatchThread;
orderedTimeRBTree mTimeTree;
int mSockPair[2];
- pthread_mutex_t mEndingLock;
- pthread_cond_t mEndingCond;
+ wthread_mutex_t mEndingLock;
+ wthread_cond_t mEndingCond;
int mEnding;
} timerHeapImpl;


int createTimerHeap (timerHeap* heap)
{
- pthread_mutexattr_t attr;
+ wthread_mutexattr_t attr;
timerHeapImpl* heapImpl = (timerHeapImpl*)calloc (1, sizeof (timerHeapImpl));
if (heapImpl == NULL)
return -1;

- pthread_mutexattr_init (&attr);
- pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE_NP);
+ wthread_mutexattr_init (&attr);
+ wthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE_NP);

/* Need to make the lock recursive as it should be possible to remove timers
in the call back */
- if (pthread_mutex_init (&heapImpl->mLock, &attr) != 0)
- {
- free (heapImpl);
- return -1;
- }
+ wthread_mutex_init (&heapImpl->mLock, &attr);

- if (pthread_mutex_init (&heapImpl->mEndingLock, NULL) != 0)
- {
- free (heapImpl);
- return -1;
- }
+ wthread_mutex_init (&heapImpl->mEndingLock, NULL);

- if (pthread_cond_init (&heapImpl->mEndingCond, NULL) != 0)
+ if (wthread_cond_init (&heapImpl->mEndingCond, NULL) != 0)
{
free (heapImpl);
return -1;
@@ -101,14 +92,14 @@ int createTimerHeap (timerHeap* heap)

RB_INIT (&heapImpl->mTimeTree);

- if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, heapImpl->mSockPair) == -1)
+ if (wsocketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, heapImpl->mSockPair) == -1)
{
free (heapImpl);
return -1;
}

- fcntl (heapImpl->mSockPair[0], F_SETFL, O_NONBLOCK);
- fcntl (heapImpl->mSockPair[1], F_SETFL, O_NONBLOCK);
+ wsetnonblock(heapImpl->mSockPair[0]);
+ wsetnonblock(heapImpl->mSockPair[1]);

*heap = heapImpl;
return 0;
@@ -126,42 +117,42 @@ void* dispatchEntry (void *closure)
timerImpl* ele = NULL;
struct timeval timeout, now, *timeptr;

- pthread_mutex_lock (&heap->mLock);
+ wthread_mutex_lock (&heap->mLock);
ele = RB_MIN (orderedTimeRBTree_, &heap->mTimeTree);

while (1)
{
if (ele==NULL)
timeptr = NULL;
- else
- {
- timeptr = &timeout;
- gettimeofday (&now, NULL);
- if (!timercmp(&ele->mTimeout, &now, >))
- timerclear (&timeout);
- else
- timersub(&ele->mTimeout, &now, &timeout);
- }
- pthread_mutex_unlock (&heap->mLock);
-
- /* Sit on Select as it has the best resolution */
- FD_ZERO(&wakeUpDes);
- FD_SET(heap->mSockPair[0], &wakeUpDes);
+ else
+ {
+ timeptr = &timeout;
+ gettimeofday (&now, NULL);
+ if (!timercmp(&ele->mTimeout, &now, >))
+ timerclear (&timeout);
+ else
+ timersub(&ele->mTimeout, &now, &timeout);
+ }
+ wthread_mutex_unlock (&heap->mLock);
+
+ /* Sit on Select as it has the best resolution */
+ FD_ZERO(&wakeUpDes);
+ FD_SET(heap->mSockPair[0], &wakeUpDes);

- selectReturn = select(heap->mSockPair[0] + 1, &wakeUpDes, NULL, NULL, timeptr);
+ selectReturn = select(heap->mSockPair[0] + 1, &wakeUpDes, NULL, NULL, timeptr);

- pthread_mutex_lock (&heap->mLock);
- if (selectReturn == -1)
- {
+ wthread_mutex_lock (&heap->mLock);
+ if (selectReturn == -1)
+ {
if (errno != EINTR)
- perror("select()");
- }
- else if (selectReturn)
- {
- int numRead = 0;
- do
- {
- numRead = read(heap->mSockPair[0], &buff, sizeof (buff));
+ perror("select()");
+ }
+ else if (selectReturn)
+ {
+ int numRead = 0;
+ do
+ {
+ numRead = read(heap->mSockPair[0], &buff, sizeof (buff));
if (numRead < 0)
{
if (errno == EINTR)
@@ -169,33 +160,33 @@ void* dispatchEntry (void *closure)
}
if (buff == 'd')
goto endLoop;
- }
- while (numRead > 0);
- }
-
- /* Dispatch all expired timers */
- ele = RB_MIN (orderedTimeRBTree_, &heap->mTimeTree);
- /* It is possible that this could be empty if the timer was removed before timeout */
- if (ele != NULL)
- {
+ }
+ while (numRead > 0);
+ }
+
+ /* Dispatch all expired timers */
+ ele = RB_MIN (orderedTimeRBTree_, &heap->mTimeTree);
+ /* It is possible that this could be empty if the timer was removed before timeout */
+ if (ele != NULL)
+ {
gettimeofday (&now, NULL);
- while (!timercmp(&ele->mTimeout, &now, >))
- {
- RB_REMOVE (orderedTimeRBTree_, &heap->mTimeTree, ele);
- ele->mCb (ele, ele->mClosure);
- ele = RB_MIN (orderedTimeRBTree_, &heap->mTimeTree);
- /* No timers left so break */
- if (ele == NULL)
- break;
+ while (!timercmp(&ele->mTimeout, &now, >))
+ {
+ RB_REMOVE (orderedTimeRBTree_, &heap->mTimeTree, ele);
+ ele->mCb (ele, ele->mClosure);
+ ele = RB_MIN (orderedTimeRBTree_, &heap->mTimeTree);
+ /* No timers left so break */
+ if (ele == NULL)
+ break;
}
- }
+ }
}
endLoop:
- pthread_mutex_unlock (&heap->mLock);
- pthread_mutex_lock (&heap->mEndingLock);
+ wthread_mutex_unlock (&heap->mLock);
+ wthread_mutex_lock (&heap->mEndingLock);
heap->mEnding = 1;
- pthread_cond_signal (&heap->mEndingCond);
- pthread_mutex_unlock (&heap->mEndingLock);
+ wthread_cond_signal (&heap->mEndingCond);
+ wthread_mutex_unlock (&heap->mEndingLock);
}
return NULL;
}
@@ -206,14 +197,15 @@ int startDispatchTimerHeap (timerHeap heap)
return -1;
{
timerHeapImpl* heapImpl = (timerHeapImpl*)heap;
- return pthread_create(&heapImpl->mDispatchThread, NULL, dispatchEntry, (void*)heapImpl);
+ return wthread_create(&heapImpl->mDispatchThread, NULL, dispatchEntry, (void*)heapImpl);
}
}

-pthread_t timerHeapGetTid (timerHeap heap)
+wthread_t timerHeapGetTid (timerHeap heap)
{
if (heap == NULL)
- return -1;
+ return INVALID_THREAD;
+
{
timerHeapImpl* heapImpl = (timerHeapImpl*)heap;
return heapImpl->mDispatchThread;
@@ -240,13 +232,13 @@ writeagain:
}
}

- pthread_mutex_lock (&heapImpl->mEndingLock);
+ wthread_mutex_lock (&heapImpl->mEndingLock);
while (heapImpl->mEnding == 0)
{
- pthread_cond_wait (&heapImpl->mEndingCond,
+ wthread_cond_wait (&heapImpl->mEndingCond,
&heapImpl->mEndingLock);
}
- pthread_mutex_unlock (&heapImpl->mEndingLock);
+ wthread_mutex_unlock (&heapImpl->mEndingLock);
free (heapImpl);
}
return 0;
@@ -273,7 +265,7 @@ int createTimer (timerElement* timer, timerHeap heap, timerFireCb cb, struct tim
ele->mCb = cb;
ele->mClosure = closure;

- pthread_mutex_lock (&heapImpl->mLock);
+ wthread_mutex_lock (&heapImpl->mLock);
nextTimeOut = RB_MIN (orderedTimeRBTree_, &heapImpl->mTimeTree);
if (nextTimeOut == NULL)
kickPipe = 1;
@@ -286,18 +278,18 @@ int createTimer (timerElement* timer, timerHeap heap, timerFireCb cb, struct tim
{
writeagain:
if (write (heapImpl->mSockPair[1], "w", 1) < 0)
- {
- if ((errno == EINTR) || (errno == EAGAIN))
- goto writeagain;
- else
- {
- perror ("write()");
- pthread_mutex_unlock (&heapImpl->mLock);
- return -1;
- }
- }
+ {
+ if ((errno == EINTR) || (errno == EAGAIN))
+ goto writeagain;
+ else
+ {
+ perror ("write()");
+ wthread_mutex_unlock (&heapImpl->mLock);
+ return -1;
+ }
+ }
}
- pthread_mutex_unlock (&heapImpl->mLock);
+ wthread_mutex_unlock (&heapImpl->mLock);

*timer = ele;
}
@@ -313,10 +305,10 @@ int destroyTimer (timerHeap heap, timerElement timer)
timerImpl* ele = (timerImpl*)timer;
timerHeapImpl* heapImpl = (timerHeapImpl*)heap;

- pthread_mutex_lock (&heapImpl->mLock);
+ wthread_mutex_lock (&heapImpl->mLock);
if (RB_FIND (orderedTimeRBTree_, &heapImpl->mTimeTree, ele))
RB_REMOVE (orderedTimeRBTree_, &heapImpl->mTimeTree, ele);
- pthread_mutex_unlock (&heapImpl->mLock);
+ wthread_mutex_unlock (&heapImpl->mLock);
free (ele);
}
return 0;
diff --git a/common/c_cpp/src/c/timers.h b/common/c_cpp/src/c/timers.h
index 38a3732..4f4fb4d 100644
--- a/common/c_cpp/src/c/timers.h
+++ b/common/c_cpp/src/c/timers.h
@@ -31,7 +31,7 @@ typedef void (*timerFireCb)(timerElement timer, void* mClosure);

int createTimerHeap (timerHeap* heap);
int startDispatchTimerHeap (timerHeap heap);
-pthread_t timerHeapGetTid (timerHeap heap);
+wthread_t timerHeapGetTid (timerHeap heap);
int destroyHeap (timerHeap heap);

int createTimer (timerElement* timer, timerHeap heap, timerFireCb cb, struct timeval* timeout, void* closure);
--
1.7.7.6


[PATCH 10/30] Move wSemaphore.c to linx/wSemaphroe.c

Michael Schonberg <mschonberg@...>
 

In preparation for windows support.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/configure.ac | 1 +
common/c_cpp/src/c/linux/wSemaphore.c | 57 ++++++++++
common/c_cpp/src/c/wSemaphore.c | 188 ---------------------------------
3 files changed, 58 insertions(+), 188 deletions(-)
create mode 100644 common/c_cpp/src/c/linux/wSemaphore.c
delete mode 100644 common/c_cpp/src/c/wSemaphore.c

diff --git a/common/c_cpp/configure.ac b/common/c_cpp/configure.ac
index dfd450b..39b145f 100755
--- a/common/c_cpp/configure.ac
+++ b/common/c_cpp/configure.ac
@@ -49,6 +49,7 @@ case $build_os in
linux*-*) AC_CONFIG_LINKS([src/c/port.h:src/c/linux/port.h
src/c/machine_port.c:src/c/linux/machine.c
src/c/platform.c:src/c/linux/platform.c
+ src/c/wSemaphore.c:src/c/linux/wSemaphore.c
src/c/environment.c:src/c/linux/environment.c]) ;;
esac

diff --git a/common/c_cpp/src/c/linux/wSemaphore.c b/common/c_cpp/src/c/linux/wSemaphore.c
new file mode 100644
index 0000000..39327fb
--- /dev/null
+++ b/common/c_cpp/src/c/linux/wSemaphore.c
@@ -0,0 +1,57 @@
+/* $Id: wSemaphore.c,v 1.3.16.4 2011/09/07 09:45:08 emmapollock Exp $
+ *
+ * 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"
+
+int wsem_timedwait (wsem_t* sem, unsigned int timeoutval)
+{
+ struct timespec ts;
+ struct timeval tv;
+
+ /*NB! - sem_timedwait() uses an absolute timeout on Linux!!*/
+ if (0!=gettimeofday (&tv, NULL))
+ {
+ return 0;
+ }
+
+ /*Convert the timeval to timespec*/
+ ts.tv_sec = tv.tv_sec;
+ ts.tv_nsec = tv.tv_usec * 1000;
+
+ /* Now add our relative timeout to the current time
+ Integer division truncation will give us the seconds.
+ The timeout passed in is in milliseconds*/
+ ts.tv_sec += (timeoutval/1000);
+ /* Now calculate the relative nsec component*/
+ ts.tv_nsec += ((timeoutval%1000) * 1000000);
+
+ /* The nsec component may now be greater than the maximum possible value.
+ If so adjust the members accordingly. */
+ if (ts.tv_nsec>=1000000000)
+ {
+ ts.tv_nsec -= 1000000000;
+ ts.tv_sec += 1;
+ }
+
+ return sem_timedwait (sem, &ts);
+}
diff --git a/common/c_cpp/src/c/wSemaphore.c b/common/c_cpp/src/c/wSemaphore.c
deleted file mode 100644
index df2bae1..0000000
--- a/common/c_cpp/src/c/wSemaphore.c
+++ /dev/null
@@ -1,188 +0,0 @@
-/* $Id: wSemaphore.c,v 1.3.16.4 2011/09/07 09:45:08 emmapollock Exp $
- *
- * 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"
-
-#ifndef WIN32
-
-int wsem_timedwait (wsem_t* sem, unsigned int timeoutval)
-{
- struct timespec ts;
- struct timeval tv;
-
- /*NB! - sem_timedwait() uses an absolute timeout on Linux!!*/
- if (0!=gettimeofday (&tv, NULL))
- {
- return 0;
- }
-
- /*Convert the timeval to timespec*/
- ts.tv_sec = tv.tv_sec;
- ts.tv_nsec = tv.tv_usec * 1000;
-
- /* Now add our relative timeout to the current time
- Integer division truncation will give us the seconds.
- The timeout passed in is in milliseconds*/
- ts.tv_sec += (timeoutval/1000);
- /* Now calculate the relative nsec component*/
- ts.tv_nsec += ((timeoutval%1000) * 1000000);
-
- /* The nsec component may now be greater than the maximum possible value.
- If so adjust the members accordingly. */
- if (ts.tv_nsec>=1000000000)
- {
- ts.tv_nsec -= 1000000000;
- ts.tv_sec += 1;
- }
-
- return sem_timedwait (sem, &ts);
-}
-
-
-#else
-
-
-/**
- * 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;
-}
-
-#endif
--
1.7.7.6


[PATCH 11/30] Moved macros for inline functions to _os_/port.h

Michael Schonberg <mschonberg@...>
 

These are compiler/os specific.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/src/c/linux/port.h | 3 +++
common/c_cpp/src/c/wombat/wCommon.h | 27 ++-------------------------
2 files changed, 5 insertions(+), 25 deletions(-)

diff --git a/common/c_cpp/src/c/linux/port.h b/common/c_cpp/src/c/linux/port.h
index f8b711c..00a1405 100644
--- a/common/c_cpp/src/c/linux/port.h
+++ b/common/c_cpp/src/c/linux/port.h
@@ -58,6 +58,9 @@ extern "C"
#define MAMAExpBridgeDLL
#define MAMACALLTYPE

+#define WCOMMONINLINE inline static
+#define WCOMMONFORCEINLINE inline static
+
/* Type for handle to dynamically loaded library */
typedef void* LIB_HANDLE;

diff --git a/common/c_cpp/src/c/wombat/wCommon.h b/common/c_cpp/src/c/wombat/wCommon.h
index 6b0752b..93c99d1 100644
--- a/common/c_cpp/src/c/wombat/wCommon.h
+++ b/common/c_cpp/src/c/wombat/wCommon.h
@@ -22,30 +22,7 @@
#ifndef _WOMBAT_WCOMMON_H
#define _WOMBAT_WCOMMON_H

-/* Inline function declarations are different on each platform, this define
- * provides the correct keyword.
- */
-#ifndef WCOMMONINLINE
-
-/* Windows */
-#ifdef WIN32
-
-#define WCOMMONINLINE __inline
-#define WCOMMONFORCEINLINE __forceinline
-
-/* Solaris */
-#elif __SUNPRO_C
-
-#define WCOMMONINLINE inline static
-#define WCOMMONFORCEINLINE inline static
-
-/* All other OS, assuming that GCC is supported. */
-#else
-#define WCOMMONINLINE inline static
-#define WCOMMONFORCEINLINE inline static
-
-#endif
-
-#endif
+/* Moved to _os_/port.h */
+#include "port.h"

#endif /* _WOMBAT_WCOMMON_H */
--
1.7.7.6


[PATCH 12/30] Added wthread_global_mutex macros

Michael Schonberg <mschonberg@...>
 

In preparation for windows support, replace global phread_mutex_t and
wthread_mutex_t inititialized with PTHREAD_MUTEX_INITIALIZER with
wthread_gobal_mtuex() macros. This is required because Windows critical
sections and mutexes do not have static initializers. They need to be
protected with atomic access to a global state variable.

The macros are simple for Linux:
WTHREAD_GLOBAL_MUTEX(NAME) initializes the mutex
wthread_mutex_(un)lock(name) locks and unlocks.

For Windows, the lock macro increments a global reference count to ensure
that the mutex only gets initialized once, and spins on a another variable
to wait until initialization complets. See windows/port.h (future check
in) for details.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/src/c/linux/port.h | 7 +++++++
common/c_cpp/src/c/properties.l | 16 ++++++----------
2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/common/c_cpp/src/c/linux/port.h b/common/c_cpp/src/c/linux/port.h
index 00a1405..8b4b873 100644
--- a/common/c_cpp/src/c/linux/port.h
+++ b/common/c_cpp/src/c/linux/port.h
@@ -58,6 +58,13 @@ extern "C"
#define MAMAExpBridgeDLL
#define MAMACALLTYPE

+/* PTHREAD static locks are easy */
+typedef pthread_mutex_t wthread_static_mutex_t;
+#define WSTATIC_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+#define wthread_static_mutex_lock(x) pthread_mutex_lock((x))
+#define wthread_static_mutex_unlock(x) pthread_mutex_unlock((x))
+
+
#define WCOMMONINLINE inline static
#define WCOMMONFORCEINLINE inline static

diff --git a/common/c_cpp/src/c/properties.l b/common/c_cpp/src/c/properties.l
index 555483b..3c327e3 100644
--- a/common/c_cpp/src/c/properties.l
+++ b/common/c_cpp/src/c/properties.l
@@ -22,19 +22,15 @@
/** This file should be processed by FLEX or LEX **/

%{
+#include "port.h"
#include "propertyinternal.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "wombat/wincompat.h"

-#ifndef WIN32
-#include <pthread.h>
-#endif
-
extern int gPropertyDebug;
-
-wthread_mutex_t lexerLock = PTHREAD_MUTEX_INITIALIZER;
+wthread_static_mutex_t lexerLock = WSTATIC_MUTEX_INITIALIZER;

%}

@@ -200,12 +196,12 @@ propertiesImpl_ImportPropertiesFromFile( propertiesImpl this,
return 0;
}

- wthread_mutex_lock (&lexerLock);
+ wthread_static_mutex_lock (&lexerLock);
yyrestart(f);
properties = this;
yylex();
properties = NULL;
- wthread_mutex_unlock (&lexerLock);
+ wthread_static_mutex_unlock (&lexerLock);

free( fullPath );
fclose( f );
@@ -220,7 +216,7 @@ propertiesImpl_AddString( propertiesImpl this,

if( gPropertyDebug ) fprintf( stderr, "Scanning property string %s\n", string );

- wthread_mutex_lock (&lexerLock);
+ wthread_static_mutex_lock (&lexerLock);

properties = this;
/* yy_scan_string changes the global lex stack buffer there lock until this
@@ -229,7 +225,7 @@ propertiesImpl_AddString( propertiesImpl this,
yylex();
yy_delete_buffer(buf);
properties = NULL;
- wthread_mutex_unlock (&lexerLock);
+ wthread_static_mutex_unlock (&lexerLock);

return 1;
}
--
1.7.7.6


[PATCH 13/30] Header changes for windows support

Michael Schonberg <mschonberg@...>
 

Removed Linux specific #include's from MAMA files and added the missing
ones to common/.../linux/port.h.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/src/c/linux/port.h | 6 ++++++
mama/c_cpp/src/c/datetime.c | 3 +--
mama/c_cpp/src/c/ft.c | 10 ----------
mama/c_cpp/src/c/imagerequest.c | 2 +-
mama/c_cpp/src/c/imagerequest.h | 2 +-
mama/c_cpp/src/c/mama.c | 15 +--------------
mama/c_cpp/src/c/mama/types.h | 2 +-
mama/c_cpp/src/c/msg.c | 2 +-
mama/c_cpp/src/c/queue.c | 2 +-
mama/c_cpp/src/c/senderId.c | 7 +------
mama/c_cpp/src/c/stat.c | 2 +-
mama/c_cpp/src/c/timezone.c | 4 +---
12 files changed, 16 insertions(+), 41 deletions(-)

diff --git a/common/c_cpp/src/c/linux/port.h b/common/c_cpp/src/c/linux/port.h
index 8b4b873..9e77781 100644
--- a/common/c_cpp/src/c/linux/port.h
+++ b/common/c_cpp/src/c/linux/port.h
@@ -35,18 +35,24 @@ extern "C"

#include <pthread.h>
#include <sys/types.h>
+#include <sys/ioctl.h>
#include <sys/vfs.h>
#include <sys/param.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/socket.h>
+#include <sys/utsname.h>
+#include <arpa/inet.h>
#include <netinet/in.h>
+#include <net/if.h>
+#include <netdb.h>
#include <semaphore.h>
#include <dirent.h>
#include <dlfcn.h>
#include <unistd.h>
#include <inttypes.h>
+#include <pwd.h>

/* Call Types */
#define COMMONExpDLL
diff --git a/mama/c_cpp/src/c/datetime.c b/mama/c_cpp/src/c/datetime.c
index a489c9b..3639fa6 100644
--- a/mama/c_cpp/src/c/datetime.c
+++ b/mama/c_cpp/src/c/datetime.c
@@ -688,8 +688,7 @@ mamaDateTime_getEpochTime(const mamaDateTime dateTime,
precision, NULL);
}

-MAMAExpDLL
-extern mama_status
+mama_status
mamaDateTime_getEpochTimeWithTz(const mamaDateTime dateTime,
mama_u32_t* seconds,
mama_u32_t* microseconds,
diff --git a/mama/c_cpp/src/c/ft.c b/mama/c_cpp/src/c/ft.c
index 0a7931c..700a022 100644
--- a/mama/c_cpp/src/c/ft.c
+++ b/mama/c_cpp/src/c/ft.c
@@ -27,17 +27,7 @@
#include <mama/ft.h>
#include <mama/io.h>

-
-#include <netinet/in.h>
-#include <unistd.h>
-#include <net/if.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <netdb.h>
-#include <arpa/inet.h>
#include <sys/types.h>
-#include <net/if.h>
-#include <sys/ioctl.h>


#define FT_SYMBOL_PREFIX "MAMA_FT"
diff --git a/mama/c_cpp/src/c/imagerequest.c b/mama/c_cpp/src/c/imagerequest.c
index 8a044db..7e42ed6 100644
--- a/mama/c_cpp/src/c/imagerequest.c
+++ b/mama/c_cpp/src/c/imagerequest.c
@@ -19,7 +19,7 @@
* 02110-1301 USA
*/

-#include <pthread.h>
+#include "port.h"
#include <mama/mama.h>
#include <mamainternal.h>
#include <imagerequest.h>
diff --git a/mama/c_cpp/src/c/imagerequest.h b/mama/c_cpp/src/c/imagerequest.h
index 2ce4d5b..9605916 100644
--- a/mama/c_cpp/src/c/imagerequest.h
+++ b/mama/c_cpp/src/c/imagerequest.h
@@ -22,7 +22,7 @@
#ifndef MamaImageRequestH__
#define MamaImageRequestH__

-#include <inttypes.h>
+#include "port.h"

#include "wombat/wincompat.h"
#include "throttle.h"
diff --git a/mama/c_cpp/src/c/mama.c b/mama/c_cpp/src/c/mama.c
index 0657286..9ac45b4 100644
--- a/mama/c_cpp/src/c/mama.c
+++ b/mama/c_cpp/src/c/mama.c
@@ -23,21 +23,8 @@
#include <stdio.h>
#include <limits.h>

-#include "wombat/wincompat.h"
+#include "port.h"
#include "wombat/environment.h"
-
-
-#include <netdb.h>
-#include <sys/utsname.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <pwd.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <dlfcn.h>
-#include <pthread.h>
-
#include "wombat/strutils.h"

#include <mama/mama.h>
diff --git a/mama/c_cpp/src/c/mama/types.h b/mama/c_cpp/src/c/mama/types.h
index 67d4086..4874fc8 100644
--- a/mama/c_cpp/src/c/mama/types.h
+++ b/mama/c_cpp/src/c/mama/types.h
@@ -26,7 +26,7 @@
extern "C" {
#endif

-#include <inttypes.h>
+#include "port.h"
#include <stdlib.h>
#include <string.h>

diff --git a/mama/c_cpp/src/c/msg.c b/mama/c_cpp/src/c/msg.c
index 59d7e11..ca26b6b 100644
--- a/mama/c_cpp/src/c/msg.c
+++ b/mama/c_cpp/src/c/msg.c
@@ -20,6 +20,7 @@
* 02110-1301 USA
*/

+#include "port.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
@@ -39,7 +40,6 @@
#include "list.h"

#include "wombat/wincompat.h"
-#include "inttypes.h"


#define MAX_SUBJECT 256
diff --git a/mama/c_cpp/src/c/queue.c b/mama/c_cpp/src/c/queue.c
index 7190819..2dcda25 100644
--- a/mama/c_cpp/src/c/queue.c
+++ b/mama/c_cpp/src/c/queue.c
@@ -19,6 +19,7 @@
* 02110-1301 USA
*/

+#include "port.h"
#include <mama/mama.h>
#include <mama/queue.h>
#include "bridge.h"
@@ -31,7 +32,6 @@
#include "statinternal.h"
#include "wlock.h"
#include "wombat/wInterlocked.h"
-#include <pthread.h>
#include <wombat/strutils.h>

extern int gGenerateQueueStats;
diff --git a/mama/c_cpp/src/c/senderId.c b/mama/c_cpp/src/c/senderId.c
index 5650d31..f37c94c 100644
--- a/mama/c_cpp/src/c/senderId.c
+++ b/mama/c_cpp/src/c/senderId.c
@@ -19,12 +19,7 @@
* 02110-1301 USA
*/

-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <arpa/inet.h>
-#include <unistd.h>
-
+#include "port.h"
#include "wombat/wincompat.h"
#include "mama/senderId.h"

diff --git a/mama/c_cpp/src/c/stat.c b/mama/c_cpp/src/c/stat.c
index 8dfa8b5..4564edb 100644
--- a/mama/c_cpp/src/c/stat.c
+++ b/mama/c_cpp/src/c/stat.c
@@ -19,9 +19,9 @@
* 02110-1301 USA
*/

+#include "port.h"
#include <string.h>
#include <stddef.h>
-#include <pthread.h>
#include "wombat/wincompat.h"
#include "mama/types.h"
#include "mama/mama.h"
diff --git a/mama/c_cpp/src/c/timezone.c b/mama/c_cpp/src/c/timezone.c
index 3754d23..932a48b 100644
--- a/mama/c_cpp/src/c/timezone.c
+++ b/mama/c_cpp/src/c/timezone.c
@@ -19,14 +19,12 @@
* 02110-1301 USA
*/

+#include "port.h"
#include "wombat/environment.h"
#include <mama/timezone.h>
#include <list.h>
#include <string.h>
#include <stdio.h>
-#include <unistd.h>
-#include <pthread.h>
-#include <sys/time.h>
#include <wombat/wincompat.h>
#include <time.h>
#include <assert.h>
--
1.7.7.6


[PATCH 14/30] Prepare ft.c for Windows support

Michael Schonberg <mschonberg@...>
 

Use MAMACALLTYPE (__stdcall for windows) for callbacks. Move os dependent
network calls to common/.../_os_/. Fixed some compiler warnings.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/configure.ac | 1 +
common/c_cpp/src/c/Makefile.am | 1 +
common/c_cpp/src/c/linux/network.c | 149 +++++++++++++++++++++++++++
common/c_cpp/src/c/linux/port.h | 2 +-
common/c_cpp/src/c/wombat/wCommon.h | 2 +
mama/c_cpp/src/c/ft.c | 189 ++++++-----------------------------
mama/c_cpp/src/c/mama/ft.h | 4 +-
7 files changed, 187 insertions(+), 161 deletions(-)
create mode 100644 common/c_cpp/src/c/linux/network.c

diff --git a/common/c_cpp/configure.ac b/common/c_cpp/configure.ac
index 39b145f..115602e 100755
--- a/common/c_cpp/configure.ac
+++ b/common/c_cpp/configure.ac
@@ -50,6 +50,7 @@ case $build_os in
src/c/machine_port.c:src/c/linux/machine.c
src/c/platform.c:src/c/linux/platform.c
src/c/wSemaphore.c:src/c/linux/wSemaphore.c
+ src/c/network.c:src/c/linux/network.c
src/c/environment.c:src/c/linux/environment.c]) ;;
esac

diff --git a/common/c_cpp/src/c/Makefile.am b/common/c_cpp/src/c/Makefile.am
index 362d457..9258c21 100644
--- a/common/c_cpp/src/c/Makefile.am
+++ b/common/c_cpp/src/c/Makefile.am
@@ -66,6 +66,7 @@ libwombatcommon_la_SOURCES = \
list.c \
lookup2.c \
machine.c \
+ network.c \
machine_port.c \
platform.c \
properties.l \
diff --git a/common/c_cpp/src/c/linux/network.c b/common/c_cpp/src/c/linux/network.c
new file mode 100644
index 0000000..f5923d9
--- /dev/null
+++ b/common/c_cpp/src/c/linux/network.c
@@ -0,0 +1,149 @@
+
+/*
+ * 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 "wombat/wCommon.h"
+
+
+struct in_addr resolve_ip (const char * arg)
+{
+
+ struct in_addr resolved;
+ struct in_addr addr;
+ unsigned long netip = 0;
+ const char * ifname = arg;
+ int sock = -1;
+ int i=0;
+ unsigned numreqs=0;
+ struct ifconf ifc;
+ struct ifreq *ifr;
+ resolved = inet_makeaddr(0,0);
+ addr = inet_makeaddr(0,0);
+
+
+ if (!arg || (strlen(arg)==0))
+ {
+ resolved.s_addr = INADDR_ANY;
+ return resolved;
+ }
+ /* 1. try interpreting as network or host IP address */
+ {
+ netip = inet_network (arg);
+ if (netip != (unsigned long)(-1))
+ {
+ addr = inet_makeaddr(netip, 0);
+ }
+ }
+ /* 2. try interpreting as network name */
+ if (! addr.s_addr)
+ {
+ struct netent * net = getnetbyname (arg);
+ if ((net != NULL) && (net->n_addrtype == AF_INET))
+ {
+ addr = inet_makeaddr (net->n_net, 0);
+ }
+ }
+ /* 3. try interpreting as host name */
+ if (! addr.s_addr)
+ {
+ struct hostent * host = gethostbyname (arg);
+ if ((host != NULL) && (host->h_addrtype == AF_INET))
+ {
+ addr = *(struct in_addr *)(host->h_addr_list[0]);
+ }
+ }
+
+ /* 4. try interpreting as a NIC interface name */
+ numreqs = 30;
+ sock = socket(AF_INET, SOCK_DGRAM, 0);
+
+ ifc.ifc_buf = NULL;
+ for (;;)
+ {
+ ifc.ifc_len = sizeof(struct ifreq) * numreqs;
+ ifc.ifc_buf = (char *)malloc(ifc.ifc_len);
+ if (ioctl(sock, SIOCGIFCONF, &ifc) < 0)
+ {
+ perror ("SIOCGIFCONF");
+ resolved.s_addr = (unsigned long) -1;
+ return resolved;
+ }
+ if (ifc.ifc_len == (sizeof(struct ifreq) * numreqs))
+ {
+ numreqs *= 2;
+ continue;
+ }
+ break;
+ }
+
+ ifr = ifc.ifc_req;
+ for (i = 0; i < ifc.ifc_len; i += sizeof(struct ifreq))
+ {
+ struct sockaddr_in hostaddr;
+ struct sockaddr_in netmask;
+ struct in_addr network = inet_makeaddr(0,0);
+
+ hostaddr.sin_addr = inet_makeaddr(0,0);
+ netmask.sin_addr = inet_makeaddr(0,0);
+
+ if (ioctl(sock, SIOCGIFADDR, ifr) < 0)
+ {
+ perror ("SIOCGIFADDR");
+ resolved.s_addr = (unsigned long)-1;
+ return resolved;
+ }
+ memcpy (&hostaddr, &(ifr->ifr_addr), sizeof(struct sockaddr_in));
+
+ if (ioctl(sock, SIOCGIFNETMASK, ifr) < 0)
+ {
+ perror ("SIOCGIFNETMASK");
+ resolved.s_addr = (unsigned long)-1;
+ return resolved;
+ }
+ memcpy (&netmask, &(ifr->ifr_addr), sizeof (struct sockaddr_in));
+ network.s_addr = hostaddr.sin_addr.s_addr & netmask.sin_addr.s_addr;
+ if (addr.s_addr)
+ {
+ if (addr.s_addr == hostaddr.sin_addr.s_addr)
+ {
+ resolved = hostaddr.sin_addr;
+ break;
+ }
+ else if (addr.s_addr == network.s_addr)
+ {
+ resolved = hostaddr.sin_addr;
+ break;
+ }
+ }
+
+ if (strcmp(ifr->ifr_name, ifname) == 0)
+ {
+ resolved = hostaddr.sin_addr;
+ break;
+ }
+ ifr++;
+ }
+
+ if (!resolved.s_addr)
+ {
+ resolved.s_addr = (unsigned long)-1;
+ }
+ return (resolved);
+}
diff --git a/common/c_cpp/src/c/linux/port.h b/common/c_cpp/src/c/linux/port.h
index 9e77781..86d2e50 100644
--- a/common/c_cpp/src/c/linux/port.h
+++ b/common/c_cpp/src/c/linux/port.h
@@ -113,7 +113,7 @@ int wsem_timedwait (wsem_t* sem, unsigned int ts);

/* Windows does not support AF_UNIX sockets, socketpairs, etc */
#define wsocketpair(dom, type, prot, pair) (socketpair((dom),(type),(prot),(pair)))
-#define wsetnonblock(s) (fcntl((s), F_SETFL, O_NONBLOCK))
+#define wsetnonblock(s) (fcntl((s), F_SETFL, fcntl((s), F_GETFL) | O_NONBLOCK))

#define CPU_AFFINITY_SET cpu_set_t

diff --git a/common/c_cpp/src/c/wombat/wCommon.h b/common/c_cpp/src/c/wombat/wCommon.h
index 93c99d1..c40112f 100644
--- a/common/c_cpp/src/c/wombat/wCommon.h
+++ b/common/c_cpp/src/c/wombat/wCommon.h
@@ -25,4 +25,6 @@
/* Moved to _os_/port.h */
#include "port.h"

+struct in_addr resolve_ip(const char * arg);
+
#endif /* _WOMBAT_WCOMMON_H */
diff --git a/mama/c_cpp/src/c/ft.c b/mama/c_cpp/src/c/ft.c
index 700a022..1948650 100644
--- a/mama/c_cpp/src/c/ft.c
+++ b/mama/c_cpp/src/c/ft.c
@@ -163,10 +163,10 @@ typedef struct mamaFtMemberImpl_
/*****************************************
* General callback functions
******************************************/
-static void
+static void MAMACALLTYPE
ftHeartbeatTimerCb (mamaTimer timer, void* closure);

-static void
+static void MAMACALLTYPE
ftTimeoutTimerCb (mamaTimer timer, void* closure);


@@ -178,7 +178,7 @@ static char* genInstanceId (const char* groupName);
static char* genSymbol (const char* groupName);

/* A callback function that does nothing. */
-static void
+static void MAMACALLTYPE
mamaFtCallbackNoOp (
mamaFtMember ftMember,
const char* groupName,
@@ -188,7 +188,7 @@ mamaFtCallbackNoOp (
}

/* FT callbacks: */
-static void
+static void MAMACALLTYPE
ioCallback (mamaIo io, mamaIoType ioType, void* closure);

static mamaIo gReadHandler = NULL;
@@ -196,27 +196,27 @@ static mamaIo gReadHandler = NULL;
/* General implementation functions. */
int receiveHeartbeat (mamaFtMemberImpl* impl);

- void checkHeartbeat (mamaFtMemberImpl* impl,
- int hbWeight,
- int hbIncarnation,
- int hbPid,
- int hbIpAddr,
- int hbPrimary,
- char *hbGroupName);
+void checkHeartbeat (mamaFtMemberImpl* impl,
+ unsigned int hbWeight,
+ unsigned int hbIncarnation,
+ int hbPid,
+ int hbIpAddr,
+ int hbPrimary,
+ char* hbGroupName);

struct in_addr resolve_ip (const char * arg);

/* FT callbacks: */
-static void
+static void MAMACALLTYPE
ftSubCreateCb (mamaSubscription subscription, void* closure);

-static void
+static void MAMACALLTYPE
ftSubErrorCb (mamaSubscription subscription,
mama_status status,
void* platformError,
const char* subject,
void* closure);
-static void
+static void MAMACALLTYPE
ftSubMsgCb (mamaSubscription subscription,
mamaMsg msg,
void* closure,
@@ -608,7 +608,7 @@ static void checkState (mamaFtMemberImpl* impl,
}
}

-static void
+static void MAMACALLTYPE
ftHeartbeatTimerCb (mamaTimer timer,
void* closure)
{
@@ -617,7 +617,7 @@ ftHeartbeatTimerCb (mamaTimer timer,
impl->ftSendHeartbeat (impl);
}

-static void
+static void MAMACALLTYPE
ftTimeoutTimerCb (mamaTimer timer,
void* closure)
{
@@ -665,7 +665,8 @@ mama_status resetTimeoutTimer (mamaFtMemberImpl* impl)
return mamaTimer_reset (impl->myTimeoutTimer);
}

-int betterCredentials(mamaFtMemberImpl* impl, int weight, int incarnation, in_addr_t ipAddr, int pid)
+int betterCredentials(mamaFtMemberImpl* impl, unsigned int weight,
+ unsigned int incarnation, in_addr_t ipAddr, int pid)
{
if (weight > impl->myWeight)
{
@@ -697,14 +698,14 @@ int betterCredentials(mamaFtMemberImpl* impl, int weight, int incarnation, in_a
}


- void checkHeartbeat (mamaFtMemberImpl* impl,
- int hbWeight,
- int hbIncarnation,
- int hbPid,
- int hbIpAddr,
- int hbPrimary,
- char *hbGroupName)
- {
+void checkHeartbeat (mamaFtMemberImpl* impl,
+ unsigned int hbWeight,
+ unsigned int hbIncarnation,
+ int hbPid,
+ int hbIpAddr,
+ int hbPrimary,
+ char* hbGroupName)
+{

if (strcmp (hbGroupName, impl->myGroupName) != 0)
{
@@ -745,132 +746,6 @@ int betterCredentials(mamaFtMemberImpl* impl, int weight, int incarnation, in_a
}
}

-struct in_addr resolve_ip (const char * arg)
-{
-
- struct in_addr resolved;
- struct in_addr addr;
- unsigned long netip = 0;
- const char * ifname = arg;
- int sock = -1;
- int i=0;
- unsigned numreqs=0;
- struct ifconf ifc;
- struct ifreq *ifr;
- resolved = inet_makeaddr(0,0);
- addr = inet_makeaddr(0,0);
-
-
- if (!arg || (strlen(arg)==0))
- {
- resolved.s_addr = INADDR_ANY;
- return resolved;
- }
- /* 1. try interpreting as network or host IP address */
- {
- netip = inet_network (arg);
- if (netip != (unsigned long)(-1))
- {
- addr = inet_makeaddr(netip, 0);
- }
- }
- /* 2. try interpreting as network name */
- if (! addr.s_addr)
- {
- struct netent * net = getnetbyname (arg);
- if ((net != NULL) && (net->n_addrtype == AF_INET))
- {
- addr = inet_makeaddr (net->n_net, 0);
- }
- }
- /* 3. try interpreting as host name */
- if (! addr.s_addr)
- {
- struct hostent * host = gethostbyname (arg);
- if ((host != NULL) && (host->h_addrtype == AF_INET))
- {
- addr = *(struct in_addr *)(host->h_addr_list[0]);
- }
- }
-
- /* 4. try interpreting as a NIC interface name */
- numreqs = 30;
- sock = socket(AF_INET, SOCK_DGRAM, 0);
-
- ifc.ifc_buf = NULL;
- for (;;)
- {
- ifc.ifc_len = sizeof(struct ifreq) * numreqs;
- ifc.ifc_buf = (char *)malloc(ifc.ifc_len);
- if (ioctl(sock, SIOCGIFCONF, &ifc) < 0)
- {
- perror ("SIOCGIFCONF");
- resolved.s_addr = INADDR_NONE;
- return resolved;
- }
- if (ifc.ifc_len == (sizeof(struct ifreq) * numreqs))
- {
- numreqs *= 2;
- continue;
- }
- break;
- }
-
- ifr = ifc.ifc_req;
- for (i = 0; i < ifc.ifc_len; i += sizeof(struct ifreq))
- {
- struct sockaddr_in hostaddr;
- struct sockaddr_in netmask;
- struct in_addr network = inet_makeaddr(0,0);
-
- hostaddr.sin_addr = inet_makeaddr(0,0);
- netmask.sin_addr = inet_makeaddr(0,0);
-
- if (ioctl(sock, SIOCGIFADDR, ifr) < 0)
- {
- perror ("SIOCGIFADDR");
- resolved.s_addr = INADDR_NONE;
- return resolved;
- }
- memcpy (&hostaddr, &(ifr->ifr_addr), sizeof(struct sockaddr_in));
-
- if (ioctl(sock, SIOCGIFNETMASK, ifr) < 0)
- {
- perror ("SIOCGIFNETMASK");
- resolved.s_addr = INADDR_NONE;
- return resolved;
- }
- memcpy (&netmask, &(ifr->ifr_addr), sizeof (struct sockaddr_in));
- network.s_addr = hostaddr.sin_addr.s_addr & netmask.sin_addr.s_addr;
- if (addr.s_addr)
- {
- if (addr.s_addr == hostaddr.sin_addr.s_addr)
- {
- resolved = hostaddr.sin_addr;
- break;
- }
- else if (addr.s_addr == network.s_addr)
- {
- resolved = hostaddr.sin_addr;
- break;
- }
- }
-
- if (strcmp(ifr->ifr_name, ifname) == 0)
- {
- resolved = hostaddr.sin_addr;
- break;
- }
- ifr++;
- }
-
- if (!resolved.s_addr)
- {
- resolved.s_addr = INADDR_NONE;
- }
- return (resolved);
-}
-
/****************************************************************************
* Multicast FT specific
******************************************************************************/
@@ -990,7 +865,7 @@ multicastFt_setup (
ftTtl = multicastFt_getProperty (propertyName,
"mama.native.transport.%s.ttl", transportName);
if (ftTtl != NULL)
- ttl = atol (ftTtl);
+ ttl = (unsigned char)atol (ftTtl);
}

iorecvstr = multicastFt_getProperty (propertyName,
@@ -1055,7 +930,7 @@ multicastFt_setup (
"MAMA multicast FT: multicast socket failed %s",strerror(errno));
return MAMA_STATUS_SYSTEM_ERROR;
}
- iRet = fcntl (sock, F_SETFL, fcntl(sock, F_GETFL) | O_NONBLOCK);
+ iRet = wsetnonblock(sock);
if (iRet != 0)
{
mama_log (MAMA_LOG_LEVEL_ERROR,
@@ -1224,7 +1099,7 @@ static void multicastFt_sendHeartbeat (void* member)
}
}

-static void
+static void MAMACALLTYPE
ioCallback (mamaIo io, mamaIoType ioType, void *closure)
{
int i = 0;
@@ -1390,7 +1265,7 @@ bridgeFt_deactivate (
return MAMA_STATUS_OK;
}

-static void
+static void MAMACALLTYPE
ftSubCreateCb (mamaSubscription subscription,
void* closure)
{
@@ -1398,7 +1273,7 @@ ftSubCreateCb (mamaSubscription subscription,
"MAMA FT: heartbeat subscription created successfully");
}

-static void
+static void MAMACALLTYPE
ftSubErrorCb (mamaSubscription subscription,
mama_status status,
void* platformError,
@@ -1448,7 +1323,7 @@ void bridgeFt_sendHeartbeat (mamaFtMember member)
mamaPublisher_send (impl->myPublisher, impl->myHeartbeatMsg);
}

-static void
+static void MAMACALLTYPE
ftSubMsgCb (mamaSubscription subscription,
mamaMsg msg,
void* closure,
diff --git a/mama/c_cpp/src/c/mama/ft.h b/mama/c_cpp/src/c/mama/ft.h
index d3b8302..2a96db4 100644
--- a/mama/c_cpp/src/c/mama/ft.h
+++ b/mama/c_cpp/src/c/mama/ft.h
@@ -49,9 +49,7 @@ typedef void* mamaFtMember;
* Callback function type for MAMA fault tolerance events.
*/
typedef void (
-#ifdef WIN32
-__stdcall
-#endif
+MAMACALLTYPE
*mamaFtMemberOnFtStateChangeCb) (mamaFtMember ftMember,
const char* groupName,
mamaFtState state,
--
1.7.7.6


[PATCH 15/30] Removed PATHSEP macro

Michael Schonberg <mschonberg@...>
 

This is os dependent and defined in common/.../_os_/port.h

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
mama/c_cpp/src/c/fileutils.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/mama/c_cpp/src/c/fileutils.c b/mama/c_cpp/src/c/fileutils.c
index 54aac59..beae12a 100644
--- a/mama/c_cpp/src/c/fileutils.c
+++ b/mama/c_cpp/src/c/fileutils.c
@@ -27,7 +27,6 @@
#include "ctype.h"
#include "fileutils.h"

-#define PATHSEP "/"
mama_status openWombatFile(
const char* fileName,
const char* mode,
--
1.7.7.6


[PATCH 16/30] Added Thread Local Storage

Michael Schonberg <mschonberg@...>
 

In preparation for windows support macros for pthread style thread local
storage added to linux/port.h

wthread_key_create
wthread_key_delete
wthread_getspecific
wthread_setspecific
These map directly to the same pthread_xxx methods for linux, but they
are implemented with TlsAlloc(), etc for windows.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/src/c/linux/port.h | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/common/c_cpp/src/c/linux/port.h b/common/c_cpp/src/c/linux/port.h
index 86d2e50..e289006 100644
--- a/common/c_cpp/src/c/linux/port.h
+++ b/common/c_cpp/src/c/linux/port.h
@@ -100,6 +100,13 @@ typedef long long int w_i64_t;

#define PATHSEP "/"

+/* Thread local storage */
+typedef pthread_key_t wthread_key_t;
+#define wthread_key_create(x, val) pthread_key_create((x), (val))
+#define wthread_key_delete(x) pthread_key_delete((x))
+#define wthread_setspecific(x, val) pthread_setspecific((x),(void*)((val)))
+#define wthread_getspecific(x) pthread_getspecific((x))
+
/* Use Posix semaphores for Linux */
#define wsem_t sem_t
#define wsem_init sem_init
--
1.7.7.6


[PATCH 17/30] Added getHostName and getIpAddress.

Michael Schonberg <mschonberg@...>
 

Added to linux/port.h and linux/network.c for windows support. The API
calls to determine the hostname and ip address are os specific.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/src/c/linux/network.c | 46 ++++++++++++++++++++++++++++++++++++
common/c_cpp/src/c/linux/port.h | 4 +++
2 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/common/c_cpp/src/c/linux/network.c b/common/c_cpp/src/c/linux/network.c
index f5923d9..75e5658 100644
--- a/common/c_cpp/src/c/linux/network.c
+++ b/common/c_cpp/src/c/linux/network.c
@@ -19,6 +19,9 @@
* 02110-1301 USA
*/

+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
#include "wombat/wCommon.h"


@@ -147,3 +150,46 @@ struct in_addr resolve_ip (const char * arg)
}
return (resolved);
}
+
+static const char gIPAddress[16];
+static const char* gHostName = NULL;
+
+static void lookupIPAddress (void)
+{
+ struct hostent *host = NULL;
+ char *addrStr = "not determined";
+
+ struct utsname uts;
+ memset( gIPAddress, 0, 16 );
+ uname (&uts);
+ gHostName = strdup (uts.nodename);
+
+ host = gethostbyname( gHostName );
+
+ if( gHostName == NULL ||
+ host == NULL ||
+ host->h_addr_list[0] == NULL )
+ {
+ strncpy( (char *)gIPAddress, "not determined", sizeof( gIPAddress ) );
+ }
+ 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/linux/port.h b/common/c_cpp/src/c/linux/port.h
index e289006..86d6d2b 100644
--- a/common/c_cpp/src/c/linux/port.h
+++ b/common/c_cpp/src/c/linux/port.h
@@ -163,6 +163,10 @@ int wsem_timedwait (wsem_t* sem, unsigned int ts);

#define wGetCurrentThreadId pthread_self

+/* net work utility functions */
+const char* getIpAddress (void);
+const char* getHostName (void);
+
#if defined (__cplusplus)
} /* extern "c" */
#endif
--
1.7.7.6


[PATCH 18/30] mama.c changes for windows support

Michael Schonberg <mschonberg@...>
 

Converted pthread_xxx calls to wthread_xxx. Use getLogin(),
getIpAddress(), and getHostName() from common for os dependent
implemnatons of these functions.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
mama/c_cpp/src/c/mama.c | 148 +++++++++++++++++------------------------------
1 files changed, 53 insertions(+), 95 deletions(-)

diff --git a/mama/c_cpp/src/c/mama.c b/mama/c_cpp/src/c/mama.c
index 9ac45b4..3891b39 100644
--- a/mama/c_cpp/src/c/mama.c
+++ b/mama/c_cpp/src/c/mama.c
@@ -109,13 +109,8 @@ int gPublishGlobalStats = 0;
int gPublishLbmStats = 0;
int gCatchCallbackExceptions = 0;

-static char gIPAddress[16];
-static const char* gUserName = NULL;
-static const char* gHostName = NULL;
-
static void lookupIPAddress (void);

-
wproperty_t gProperties = 0;
static mamaStatsLogger gStatsPublisher = NULL;

@@ -136,7 +131,7 @@ mamaStat gRvMsgsStat;

static mamaPayloadBridge gDefaultPayload = NULL;

-static pthread_key_t last_err_key;
+static wthread_key_t last_err_key;

/**
* struct mamaApplicationGroup
@@ -157,18 +152,18 @@ typedef struct mamaAppContext_
*/
typedef struct mamaImpl_
{
- mamaBridge myBridges[MAMA_MIDDLEWARE_MAX];
- mamaPayloadBridge myPayloads[MAMA_PAYLOAD_MAX];
- LIB_HANDLE myBridgeLibraries[MAMA_MIDDLEWARE_MAX];
- LIB_HANDLE myPayloadLibraries[MAMA_PAYLOAD_MAX];
- unsigned int myRefCount;
- pthread_mutex_t myLock;
+ mamaBridge myBridges[MAMA_MIDDLEWARE_MAX];
+ mamaPayloadBridge myPayloads[MAMA_PAYLOAD_MAX];
+ LIB_HANDLE myBridgeLibraries[MAMA_MIDDLEWARE_MAX];
+ LIB_HANDLE myPayloadLibraries[MAMA_PAYLOAD_MAX];
+ unsigned int myRefCount;
+ wthread_static_mutex_t myLock;
} mamaImpl;

static mamaApplicationContext appContext;
static char mama_ver_string[256];

-static mamaImpl gImpl = {{0}, {0}, {0}, {0}, 0, PTHREAD_MUTEX_INITIALIZER};
+static mamaImpl gImpl = {{0}, {0}, {0}, {0}, 0, WSTATIC_MUTEX_INITIALIZER};

/* ************************************************************************* */
/* Private Function Prototypes. */
@@ -378,11 +373,10 @@ mamaInternal_createStatsPublisher ()
return result;

mama_getUserName (&userName);
- lookupIPAddress();
mamaStatsLogger_setReportSize (gStatsPublisher, 100);
mamaStatsLogger_setUserName (gStatsPublisher, userName);
- mamaStatsLogger_setIpAddress (gStatsPublisher, gIPAddress);
- mamaStatsLogger_setHostName (gStatsPublisher, gHostName);
+ mamaStatsLogger_setIpAddress (gStatsPublisher, getIpAddress());
+ mamaStatsLogger_setHostName (gStatsPublisher, getHostName());
mamaStatsLogger_setApplicationName (gStatsPublisher,
appContext.myApplicationName);
mamaStatsLogger_setApplicationClass (gStatsPublisher,
@@ -651,9 +645,9 @@ mama_openWithPropertiesCount (const char* path,
const char* statsLogging = "false";
const char* catchCallbackExceptions = NULL;

- pthread_mutex_lock (&gImpl.myLock);
+ wthread_static_mutex_lock (&gImpl.myLock);

- if (pthread_key_create(&last_err_key, NULL) != 0)
+ if (wthread_key_create(&last_err_key, NULL) != 0)
{
mama_log (MAMA_LOG_LEVEL_NORMAL, "WARNING!!! - CANNOT ALLOCATE KEY FOR ERRORS");
}
@@ -696,7 +690,7 @@ mama_openWithPropertiesCount (const char* path,
if (count)
*count = gImpl.myRefCount;

- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return result;
}
/* Code after this point is one-time initialization */
@@ -721,7 +715,6 @@ mama_openWithPropertiesCount (const char* path,

mamaInternal_loadProperties (path, filename);

- lookupIPAddress();
initReservedFields();
mama_loginit();

@@ -761,7 +754,7 @@ mama_openWithPropertiesCount (const char* path,
if (count)
*count = gImpl.myRefCount;

- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return result;
}

@@ -881,7 +874,7 @@ mama_openWithPropertiesCount (const char* path,
if (count)
*count = gImpl.myRefCount;

- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_NO_BRIDGE_IMPL;
}

@@ -893,7 +886,7 @@ mama_openWithPropertiesCount (const char* path,
if (count)
*count = gImpl.myRefCount;

- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_NO_BRIDGE_IMPL;
}

@@ -910,7 +903,7 @@ mama_openWithPropertiesCount (const char* path,
mama_log (MAMA_LOG_LEVEL_SEVERE,
"mama_openWithProperties(): "
"Error connecting to Entitlements Server");
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
mama_close();

if (count)
@@ -954,7 +947,7 @@ mama_openWithPropertiesCount (const char* path,
{
if (count)
*count = gImpl.myRefCount;
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return result;
}
}
@@ -966,7 +959,7 @@ mama_openWithPropertiesCount (const char* path,
"Could not set queue for stats generator.");
if (count)
*count = gImpl.myRefCount;
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return result;
}

@@ -977,7 +970,7 @@ mama_openWithPropertiesCount (const char* path,
"Failed to enable stats logging");
if (count)
*count = gImpl.myRefCount;
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return result;
}
}
@@ -985,7 +978,7 @@ mama_openWithPropertiesCount (const char* path,
gImpl.myRefCount++;
if (count)
*count = gImpl.myRefCount;
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return result;
}

@@ -1114,12 +1107,12 @@ mama_closeCount (unsigned int* count)
mamaMiddleware middleware = 0;
int payload = 0;

- pthread_mutex_lock (&gImpl.myLock);
+ wthread_static_mutex_lock (&gImpl.myLock);
if (gImpl.myRefCount == 0)
{
if (count)
*count = gImpl.myRefCount;
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_OK;
}

@@ -1133,7 +1126,7 @@ mama_closeCount (unsigned int* count)
}
#endif /* WITH_ENTITLEMENTS */

- pthread_key_delete(last_err_key);
+ wthread_key_delete(last_err_key);

for (middleware = 0; middleware != MAMA_MIDDLEWARE_MAX; ++middleware)
{
@@ -1234,9 +1227,6 @@ mama_closeCount (unsigned int* count)

cleanupReservedFields();

- if (gHostName)
- free ((void*)gHostName);
-
/* Look for a bridge for each of the middlewares and close them */
for (middleware = 0; middleware != MAMA_MIDDLEWARE_MAX; ++middleware)
{
@@ -1281,7 +1271,7 @@ mama_closeCount (unsigned int* count)
}
if (count)
*count = gImpl.myRefCount;
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return result;
}

@@ -1315,9 +1305,9 @@ mama_start (mamaBridge bridgeImpl)
return MAMA_STATUS_INVALID_QUEUE;
}

- pthread_mutex_lock(&gImpl.myLock);
+ wthread_static_mutex_lock(&gImpl.myLock);
prevRefCnt = impl->mRefCount++;
- pthread_mutex_unlock(&gImpl.myLock);
+ wthread_static_mutex_unlock(&gImpl.myLock);

if (prevRefCnt > 0)
return MAMA_STATUS_OK;
@@ -1328,9 +1318,9 @@ mama_start (mamaBridge bridgeImpl)

if (rval != MAMA_STATUS_OK)
{
- pthread_mutex_lock(&gImpl.myLock);
+ wthread_static_mutex_lock(&gImpl.myLock);
impl->mRefCount--;
- pthread_mutex_unlock(&gImpl.myLock);
+ wthread_static_mutex_unlock(&gImpl.myLock);
}

return rval;
@@ -1425,7 +1415,7 @@ mama_stop (mamaBridge bridgeImpl)
}

/*Delegate to the bridge specific implementation*/
- pthread_mutex_lock(&gImpl.myLock);
+ wthread_static_mutex_lock(&gImpl.myLock);
if (impl->mRefCount > 0)
{
impl->mRefCount--;
@@ -1436,7 +1426,7 @@ mama_stop (mamaBridge bridgeImpl)
impl->mRefCount++;
}
}
- pthread_mutex_unlock(&gImpl.myLock);
+ wthread_static_mutex_unlock(&gImpl.myLock);
return rval;
}

@@ -1499,12 +1489,7 @@ mama_getUserName (const char** userName)
if (userName == NULL)
return MAMA_STATUS_NULL_ARG;

- if (!gUserName)
- {
- gUserName = strdup (getpwuid(getuid())->pw_name);
- }
-
- *userName = gUserName;
+ *userName = getlogin();
return MAMA_STATUS_OK;
}

@@ -1512,7 +1497,7 @@ mama_status
mama_getHostName (const char** hostName)
{
if (hostName == NULL) return MAMA_STATUS_NULL_ARG;
- *hostName = gHostName;
+ *hostName = getHostName();
return MAMA_STATUS_OK;
}

@@ -1520,37 +1505,10 @@ mama_status
mama_getIpAddress (const char** ipAddress)
{
if (ipAddress == NULL) return MAMA_STATUS_NULL_ARG;
- *ipAddress = gIPAddress;
+ *ipAddress = getIpAddress();
return MAMA_STATUS_OK;
}

-static void
-lookupIPAddress (void)
-{
- struct hostent *host = NULL;
- char *addrStr = "not determined";
-
- struct utsname uts;
- memset( gIPAddress, 0, 16 );
- uname (&uts);
- gHostName = strdup (uts.nodename);
-
- host = gethostbyname( gHostName );
-
- if( gHostName == NULL ||
- host == NULL ||
- host->h_addr_list[0] == NULL )
- {
- strncpy( (char *)gIPAddress, "not determined", sizeof( gIPAddress ) );
- }
- else
- {
- addrStr = inet_ntoa( *((struct in_addr *)( host->h_addr_list[0] )));
- }
-
- strncpy ((char*)gIPAddress, addrStr, sizeof (gIPAddress));
-}
-
#ifdef WITH_ENTITLEMENTS

mama_status
@@ -1800,10 +1758,10 @@ mamaInternal_registerBridge (mamaBridge bridge,
return;
}

- pthread_mutex_lock (&gImpl.myLock);
+ wthread_static_mutex_lock (&gImpl.myLock);
gImpl.myBridges[middleware] = bridge;
((mamaBridgeImpl*)(bridge))->mRefCount = 0;
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
}

mama_status
@@ -1836,7 +1794,7 @@ mama_loadPayloadBridgeInternal (mamaPayloadBridge* impl,
payloadName);

if (lock)
- pthread_mutex_lock (&gImpl.myLock);
+ wthread_static_mutex_lock (&gImpl.myLock);

bridgeLib = openSharedLib (bridgeImplName, NULL);

@@ -1849,7 +1807,7 @@ mama_loadPayloadBridgeInternal (mamaPayloadBridge* impl,
bridgeImplName ? bridgeImplName : "",
getLibError());
if (lock)
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_NO_BRIDGE_IMPL;
}

@@ -1868,7 +1826,7 @@ mama_loadPayloadBridgeInternal (mamaPayloadBridge* impl,
closeSharedLib (bridgeLib);

if (lock)
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);

return MAMA_STATUS_NO_BRIDGE_IMPL;
}
@@ -1876,7 +1834,7 @@ mama_loadPayloadBridgeInternal (mamaPayloadBridge* impl,
if (MAMA_STATUS_OK != (status = initFunc (impl, &payloadChar)))
{
if (lock)
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);

return status;
}
@@ -1887,7 +1845,7 @@ mama_loadPayloadBridgeInternal (mamaPayloadBridge* impl,
"mama_loadPayloadBridge(): Error in [%s] ", initFuncName);

if (lock)
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);

return MAMA_STATUS_NO_BRIDGE_IMPL;
}
@@ -1900,7 +1858,7 @@ mama_loadPayloadBridgeInternal (mamaPayloadBridge* impl,
payloadName);

if (lock)
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);

return MAMA_STATUS_OK;
}
@@ -1919,7 +1877,7 @@ mama_loadPayloadBridgeInternal (mamaPayloadBridge* impl,
payloadName, bridgeImplName);

if (lock)
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);

return MAMA_STATUS_OK;
}
@@ -1973,14 +1931,14 @@ mama_loadBridgeWithPathInternal (mamaBridge* impl,
}

if (lock)
- pthread_mutex_lock (&gImpl.myLock);
+ wthread_static_mutex_lock (&gImpl.myLock);

/* Check if a bridge has already been initialized for the middleware */
if (gImpl.myBridges [middleware])
{
*impl = gImpl.myBridges [middleware];
if (lock)
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_OK;
}

@@ -2009,7 +1967,7 @@ mama_loadBridgeWithPathInternal (mamaBridge* impl,
getLibError());
}
if (lock)
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_NO_BRIDGE_IMPL;
}

@@ -2027,7 +1985,7 @@ mama_loadBridgeWithPathInternal (mamaBridge* impl,
bridgeImplName ? bridgeImplName : "");
closeSharedLib (bridgeLib);
if (lock)
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_NO_BRIDGE_IMPL;
}

@@ -2038,7 +1996,7 @@ mama_loadBridgeWithPathInternal (mamaBridge* impl,
mama_log (MAMA_LOG_LEVEL_ERROR,
"mama_loadBridge(): Error in [%s] ", initFuncName);
if (lock)
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_NO_BRIDGE_IMPL;
}

@@ -2053,7 +2011,7 @@ mama_loadBridgeWithPathInternal (mamaBridge* impl,
if (MAMA_STATUS_OK != result)
{
if (lock)
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return result;
}

@@ -2070,7 +2028,7 @@ mama_loadBridgeWithPathInternal (mamaBridge* impl,
gImpl.myBridgeLibraries [middleware] = bridgeLib;

if (lock)
- pthread_mutex_unlock (&gImpl.myLock);
+ wthread_static_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_OK;
}

@@ -2121,19 +2079,19 @@ mama_wrapperGetVersion(mamaBridge bridge)
void
mama_setLastError (mamaError error)
{
- pthread_setspecific(last_err_key, (void*)error);
+ wthread_setspecific(last_err_key, (void*)error);
}

mamaError
mama_getLastErrorCode (void)
{
- return (mamaError)pthread_getspecific(last_err_key);
+ return (mamaError)wthread_getspecific(last_err_key);
}

const char*
mama_getLastErrorText (void)
{
- return mamaError_convertToString((mamaError)pthread_getspecific(last_err_key));
+ return mamaError_convertToString((mamaError)wthread_getspecific(last_err_key));
}


--
1.7.7.6


[PATCH 19/30] Moved wombat/wInterlocked.h to Linux directory

Michael Schonberg <mschonberg@...>
 

From: Mike Schonberg <mschonberg@nyx.com>

These inline asm functions are os depenent.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/configure.ac | 1 +
common/c_cpp/src/c/linux/wInterlocked.h | 142 ++++++++++++++++++++++++++++++
common/c_cpp/src/c/wombat/wInterlocked.h | 142 ------------------------------
3 files changed, 143 insertions(+), 142 deletions(-)
create mode 100644 common/c_cpp/src/c/linux/wInterlocked.h
delete mode 100644 common/c_cpp/src/c/wombat/wInterlocked.h

diff --git a/common/c_cpp/configure.ac b/common/c_cpp/configure.ac
index 115602e..ab991b4 100755
--- a/common/c_cpp/configure.ac
+++ b/common/c_cpp/configure.ac
@@ -47,6 +47,7 @@ AC_CANONICAL_BUILD()
AC_MSG_NOTICE([Configuring symbolic links for $build_os in $srcdir])
case $build_os in
linux*-*) AC_CONFIG_LINKS([src/c/port.h:src/c/linux/port.h
+ src/c/wombat/wInterlocked.h:src/c/linux/wInterlocked.h
src/c/machine_port.c:src/c/linux/machine.c
src/c/platform.c:src/c/linux/platform.c
src/c/wSemaphore.c:src/c/linux/wSemaphore.c
diff --git a/common/c_cpp/src/c/linux/wInterlocked.h b/common/c_cpp/src/c/linux/wInterlocked.h
new file mode 100644
index 0000000..c128804
--- /dev/null
+++ b/common/c_cpp/src/c/linux/wInterlocked.h
@@ -0,0 +1,142 @@
+/* $Id: wInterlocked.h,v 1.1.2.6.8.3 2011/08/10 14:53:24 nicholasmarriott Exp $
+ *
+ * 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 _WOMBAT_WINTERLOCKED_H
+#define _WOMBAT_WINTERLOCKED_H
+
+/*
+ * This file contains a set of interlock functions for atomic access on scalar
+ * variables.
+ */
+
+#include "wCommon.h"
+
+/* *************************************************** */
+/* Linux implementation. */
+/* *************************************************** */
+
+/* 32-bit atomic exchange. Returns previous value. */
+static __inline__ uint32_t
+axchg32 (uint32_t* ptr, uint32_t newVal)
+{
+ __asm__ volatile ("xchgl %k0, %1"
+ : "=r" (newVal)
+ : "m" (*ptr), "0" (newVal)
+ : "memory");
+ return newVal;
+}
+
+/* 32-bit atomic increment. */
+static __inline__ void
+ainc32 (uint32_t* ptr)
+{
+ __asm__ volatile ("lock; incl %0"
+ : "=m" (*ptr)
+ : "m" (*ptr));
+}
+
+/* 32-bit atomic decrement. */
+static __inline__ void
+adec32 (uint32_t* ptr)
+{
+ __asm__ volatile ("lock; decl %0"
+ : "=m" (*ptr)
+ : "m" (*ptr));
+}
+
+/* *************************************************** */
+/* Type Defines. */
+/* *************************************************** */
+/* The structure on linux. */
+typedef uint32_t 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)
+{
+ adec32(value);
+ return (int)*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)
+{
+ ainc32(value);
+ return (int)*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 (int)*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)
+{
+ axchg32(value, (uint32_t)newValue);
+ return (int)*value;
+}
+
+#endif /* _WOMBAT_WINTERLOCKED_H */
diff --git a/common/c_cpp/src/c/wombat/wInterlocked.h b/common/c_cpp/src/c/wombat/wInterlocked.h
deleted file mode 100644
index c128804..0000000
--- a/common/c_cpp/src/c/wombat/wInterlocked.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/* $Id: wInterlocked.h,v 1.1.2.6.8.3 2011/08/10 14:53:24 nicholasmarriott Exp $
- *
- * 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 _WOMBAT_WINTERLOCKED_H
-#define _WOMBAT_WINTERLOCKED_H
-
-/*
- * This file contains a set of interlock functions for atomic access on scalar
- * variables.
- */
-
-#include "wCommon.h"
-
-/* *************************************************** */
-/* Linux implementation. */
-/* *************************************************** */
-
-/* 32-bit atomic exchange. Returns previous value. */
-static __inline__ uint32_t
-axchg32 (uint32_t* ptr, uint32_t newVal)
-{
- __asm__ volatile ("xchgl %k0, %1"
- : "=r" (newVal)
- : "m" (*ptr), "0" (newVal)
- : "memory");
- return newVal;
-}
-
-/* 32-bit atomic increment. */
-static __inline__ void
-ainc32 (uint32_t* ptr)
-{
- __asm__ volatile ("lock; incl %0"
- : "=m" (*ptr)
- : "m" (*ptr));
-}
-
-/* 32-bit atomic decrement. */
-static __inline__ void
-adec32 (uint32_t* ptr)
-{
- __asm__ volatile ("lock; decl %0"
- : "=m" (*ptr)
- : "m" (*ptr));
-}
-
-/* *************************************************** */
-/* Type Defines. */
-/* *************************************************** */
-/* The structure on linux. */
-typedef uint32_t 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)
-{
- adec32(value);
- return (int)*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)
-{
- ainc32(value);
- return (int)*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 (int)*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)
-{
- axchg32(value, (uint32_t)newValue);
- return (int)*value;
-}
-
-#endif /* _WOMBAT_WINTERLOCKED_H */
--
1.7.7.6


[PATCH 20/30] Add wtimegm macro for poritning timegm

Michael Schonberg <mschonberg@...>
 

timegm() is not avaliable on windows so we need a macro to abstract the
method. The windows implementation is simple using mktime() and
temporarily setting the timezone to GMT.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/src/c/linux/port.h | 3 +++
mama/c_cpp/src/c/datetime.c | 2 +-
2 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/common/c_cpp/src/c/linux/port.h b/common/c_cpp/src/c/linux/port.h
index 86d6d2b..fc80ed9 100644
--- a/common/c_cpp/src/c/linux/port.h
+++ b/common/c_cpp/src/c/linux/port.h
@@ -163,6 +163,9 @@ int wsem_timedwait (wsem_t* sem, unsigned int ts);

#define wGetCurrentThreadId pthread_self

+/* time gm not available on Windows */
+#define wtimegm timegm
+
/* net work utility functions */
const char* getIpAddress (void);
const char* getHostName (void);
diff --git a/mama/c_cpp/src/c/datetime.c b/mama/c_cpp/src/c/datetime.c
index 3639fa6..1cb8cde 100644
--- a/mama/c_cpp/src/c/datetime.c
+++ b/mama/c_cpp/src/c/datetime.c
@@ -1653,7 +1653,7 @@ unsigned long makeTime (
timeInfo.tm_sec = sec;
timeInfo.tm_isdst = 0;

- return timegm (&timeInfo);
+ return wtimegm (&timeInfo);
}

void utcTm (
--
1.7.7.6

81 - 100 of 2305