[Pvfs2-cvs] commit by sampson in pvfs2/src/common/gen-locks:
gen-win-locks.c gen-locks.h
CVS commit program
cvs at parl.clemson.edu
Fri Sep 24 17:38:53 EDT 2010
Update of /projects/cvsroot/pvfs2/src/common/gen-locks
In directory parlweb1:/tmp/cvs-serv8231/src/common/gen-locks
Modified Files:
Tag: windows-client
gen-locks.h
Added Files:
Tag: windows-client
gen-win-locks.c
Log Message:
Updated Windows bmi-wintcp, gen-locks
--- /dev/null 2004-06-24 14:04:38.000000000 -0400
+++ gen-win-locks.c 2010-09-24 17:38:53.000000000 -0400
@@ -0,0 +1,154 @@
+/*
+ * (C) 2001 Clemson University and The University of Chicago
+ *
+ * See COPYING in top-level directory.
+ */
+
+
+/* This code implements generic locking that can be turned on or off at
+ * compile time.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+
+#include "gen-locks.h"
+
+/***************************************************************
+ * visible functions
+ */
+
+#ifndef __GEN_NULL_LOCKING__
+/*
+ * gen_mutex_init()
+ *
+ * initializes a previously declared mutex
+ *
+ * returns 0 on success, -1 and sets errno on failure.
+ */
+int gen_win_mutex_init(
+ HANDLE *mut)
+{
+ *mut = CreateMutex(NULL, false, NULL);
+ return (*mut) ? 0 : -1;
+}
+
+/*
+ * gen_mutex_lock()
+ *
+ * blocks until it obtains a mutex lock on the given mutex
+ *
+ * returns 0 on success, -1 and sets errno on failure.
+ */
+int gen_win_mutex_lock(
+ HANDLE *mut)
+{
+ DWORD dwWaitResult;
+
+ dwWaitResult = WaitForSingleObject(*mut, INFINITE);
+
+ return (dwWaitResult == WAIT_OBJECT_0 || dwWaitResult == WAIT_ABANDONED) ? 0 : -1;
+}
+
+
+/*
+ * gen_mutex_unlock()
+ *
+ * releases a lock held on a mutex
+ *
+ * returns 0 on success, -1 and sets errno on failure
+ */
+int gen_win_mutex_unlock(
+ HANDLE *mut)
+{
+ BOOL rc = ReleaseMutex(*mut);
+
+ return (rc) ? 0 : -1;
+}
+
+
+/*
+ * pthread_mutex_trylock()
+ *
+ * nonblocking attempt to acquire a lock.
+ *
+ * returns 0 on success, -1 and sets errno on failure, sets errno to EBUSY
+ * if it cannot obtain the lock
+ */
+int gen_win_mutex_trylock(
+ HANDLE *mut)
+{
+ return (pthread_mutex_trylock(mut));
+}
+
+/*
+ * gen_mutex_destroy()
+ *
+ * uninitializes the mutex and frees all memory associated with it.
+ *
+ * returns 0 on success, -errno on failure.
+ */
+int gen_win_mutex_destroy(
+ HANDLE *mut)
+{
+
+ if (!mut || *mut == INVALID_HANDLE_VALUE)
+ {
+ return (-EINVAL);
+ }
+ CloseHandle(*mut);
+
+ return (0);
+}
+
+HANDLE gen_win_thread_self(void)
+{
+ return pthread_self();
+}
+
+int gen_win_cond_destroy(HANDLE cond)
+{
+ if(!cond)
+ {
+ return -EINVAL;
+ }
+ pthread_cond_destroy(cond);
+ return 0;
+}
+
+int gen_win_cond_wait(HANDLE cond, HANDLE mut)
+{
+ return pthread_cond_wait(cond, mut);
+}
+
+int gen_win_cond_timedwait(HANDLE cond, HANDLE mut,
+ const struct timespec *abstime)
+{
+ return pthread_cond_timedwait(cond, mut, abstime);
+}
+
+int gen_win_cond_signal(HANDLE cond)
+{
+ return pthread_cond_signal(cond);
+}
+
+int gen_win_cond_broadcast(HANDLE cond)
+{
+ return pthread_cond_broadcast(cond);
+}
+
+int gen_win_cond_init(HANDLE cond, void *attr)
+{
+ return pthread_cond_init(cond, attr);
+}
+
+#endif
+
+/*
+ * Local variables:
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * End:
+ *
+ * vim: ts=8 sts=4 sw=4 expandtab
+ */
Index: gen-locks.h
===================================================================
RCS file: /projects/cvsroot/pvfs2/src/common/gen-locks/gen-locks.h,v
diff -p -u -r1.18 -r1.18.32.1
--- gen-locks.h 20 Feb 2009 15:55:00 -0000 1.18
+++ gen-locks.h 24 Sep 2010 21:38:53 -0000 1.18.32.1
@@ -26,9 +26,17 @@
/* this is especially important for development in which case the locks
* should really be enabled in order to verify proper operation
*/
-#if !defined(__GEN_NULL_LOCKING__) && !defined(__GEN_POSIX_LOCKING__)
+#if !defined(__GEN_NULL_LOCKING__)
+#ifdef WIN32
+#if !defined(__GEN_WIN_LOCKING__)
+#define __GEN_WIN_LOCKING__
+#endif
+#else
+#if !defined(__GEN_POSIX_LOCKING__)
#define __GEN_POSIX_LOCKING__
#endif
+#endif
+#endif
#ifdef __GEN_POSIX_LOCKING__
#include <pthread.h>
@@ -69,6 +77,45 @@ typedef pthread_cond_t gen_cond_t;
#define gen_cond_signal(c) gen_posix_cond_signal(c)
#define gen_cond_broadcast(c) gen_posix_cond_broadcast(c)
+#elif defined (__GEN_WIN_LOCKING__)
+
+#include <Windows.h>
+
+int gen_win_mutex_lock(HANDLE *mut);
+int gen_win_mutex_unlock(HANDLE *mut);
+int gen_win_mutex_trylock(HANDLE *mut);
+HANDLE *gen_win_mutex_build(void);
+int gen_win_mutex_destroy(HANDLE *mut);
+int gen_win_mutex_init(HANDLE *mut);
+HANDLE gen_win_thread_self(void);
+
+int gen_win_cond_init(HANDLE *cond, void *attr);
+int gen_win_cond_destroy(HANDLE *cond);
+int gen_win_cond_wait(HANDLE *cond, HANDLE *mut);
+int gen_win_cond_timedwait(HANDLE *cond, HANDLE *mut,
+ const struct timespec *abstime);
+int gen_win_cond_signal(HANDLE *cond);
+int gen_win_cond_broadcast(HANDLE *cond);
+
+typedef HANDLE gen_mutex_t;
+typedef HANDLE gen_thread_t;
+typedef HANDLE gen_cond_t;
+#define GEN_MUTEX_INITIALIZER CreateMutex(NULL, false, NULL);
+#define GEN_COND_INITIALIZER PTHREAD_COND_INITIALIZER;
+#define gen_mutex_lock(m) gen_win_mutex_lock(m)
+#define gen_mutex_unlock(m) gen_win_mutex_unlock(m)
+#define gen_mutex_trylock(m) gen_win_mutex_trylock(m)
+#define gen_mutex_destroy(m) gen_win_mutex_destroy(m)
+#define gen_mutex_init(m) gen_win_mutex_init(m)
+#define gen_thread_self() gen_win_thread_self()
+
+#define gen_cond_init(c) gen_win_cond_init(c, NULL)
+#define gen_cond_destroy(c) gen_win_cond_destroy(c)
+#define gen_cond_wait(c, m) gen_win_cond_wait(c, m)
+#define gen_cond_timedwait(c, m, s) gen_win_cond_timedwait(c, m, s)
+#define gen_cond_signal(c) gen_win_cond_signal(c)
+#define gen_cond_broadcast(c) gen_win_cond_broadcast(c)
+
#elif defined (__GEN_NULL_LOCKING__)
/* this stuff messes around just enough to prevent warnings */
typedef int gen_mutex_t;
@@ -132,7 +179,7 @@ static inline int gen_cond_broadcast(gen
}
#else /* __GEN_NULL_LOCKING__ */
-#error "Must define either POSIX or NULL locking"
+#error "Must define either POSIX, Windows or NULL locking"
#endif
#endif /* __GEN_LOCKS_H */
More information about the Pvfs2-cvs
mailing list