Index: trunk/psLib/src/mathtypes/psImage.h
===================================================================
--- trunk/psLib/src/mathtypes/psImage.h	(revision 19052)
+++ trunk/psLib/src/mathtypes/psImage.h	(revision 19056)
@@ -9,6 +9,6 @@
  * @author Joshua Hoblitt, University of Hawaii
  *
- * @version $Revision: 1.96 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-12-07 19:33:19 $
+ * @version $Revision: 1.97 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2008-08-14 03:18:41 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -24,5 +24,5 @@
 #include "psArray.h"
 #include "psConstants.h"
-
+#include "psMutex.h"
 
 /** Basic image data structure.
@@ -56,5 +56,5 @@
     psPtr p_rawDataBuffer;             ///< Raw data buffer for Allocating/Freeing Images; private
     psArray* children;                 ///< Children of this region.
-    void *lock;                        ///< Optional lock for thread safety
+    psMutex lock;                       ///< Optional lock for thread safety
 }
 psImage;
Index: trunk/psLib/src/mathtypes/psVector.h
===================================================================
--- trunk/psLib/src/mathtypes/psVector.h	(revision 19052)
+++ trunk/psLib/src/mathtypes/psVector.h	(revision 19056)
@@ -10,6 +10,6 @@
  * @author Joshua Hoblitt, University of Hawaii
  *
- * @version $Revision: 1.71 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-06-24 21:32:52 $
+ * @version $Revision: 1.72 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2008-08-14 03:18:41 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -23,4 +23,5 @@
 #include <stdio.h>
 #include "psType.h"
+#include "psMutex.h"
 
 /** An vector to support primitive types.
@@ -46,5 +47,5 @@
         psF64* F64;                    ///< Double-precision float data.
     } data;
-    void *lock;                        ///< Optional lock for thread safety.
+    psMutex lock;                       ///< Optional lock for thread safety.
 }
 psVector;
Index: trunk/psLib/src/pslib_strict.h
===================================================================
--- trunk/psLib/src/pslib_strict.h	(revision 19052)
+++ trunk/psLib/src/pslib_strict.h	(revision 19056)
@@ -9,6 +9,6 @@
 *  @author Eric Van Alst, MHPCC
 *
-*  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2008-08-08 18:07:49 $
+*  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2008-08-14 03:18:41 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -74,4 +74,5 @@
 #include "psMinimizePowell.h"
 #include "psMinimizePolyFit.h"
+#include "psMutex.h"
 #include "psRandom.h"
 #include "psRegionForImage.h"
Index: trunk/psLib/src/sys/Makefile.am
===================================================================
--- trunk/psLib/src/sys/Makefile.am	(revision 19052)
+++ trunk/psLib/src/sys/Makefile.am	(revision 19056)
@@ -41,4 +41,5 @@
 	psLogMsg.h     \
 	psMemory.h     \
+	psMutex.h      \
 	psSlurp.h      \
 	psString.h     \
Index: trunk/psLib/src/sys/psMutex.h
===================================================================
--- trunk/psLib/src/sys/psMutex.h	(revision 19056)
+++ trunk/psLib/src/sys/psMutex.h	(revision 19056)
@@ -0,0 +1,36 @@
+#ifndef PS_MUTEX_H
+#define PS_MUTEX_H
+
+#include <pthread.h>
+
+typedef pthread_mutex_t psMutex;        /// Mutual Exclusion using pthreads
+
+/// Initialize a mutex
+#define psMutexInit(PTR) { \
+    /* Gotta go the long way, since we can't use PTHREAD_MUTEX_INITIALIZER after we declare the variable */ \
+    pthread_mutexattr_t attr; /* Mutex attributes */ \
+    pthread_mutexattr_init(&attr); \
+    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_FAST_NP); \
+    pthread_mutex_init(&(PTR)->lock, &attr); \
+    pthread_mutexattr_destroy(&attr); \
+}
+
+/// Lock a mutex
+#define psMutexLock(PTR) \
+if (pthread_mutex_lock(&(PTR)->lock) == EINVAL) { \
+    psAbort("Cannot lock mutex on %s: not initialised", #PTR); \
+}
+
+/// Unlock a mutex
+#define psMutexUnlock(PTR) \
+if (pthread_mutex_unlock(&(PTR)->lock) == EINVAL) { \
+    psAbort("Cannot unlock mutex on %s: not initialised", #PTR); \
+}
+
+/// Destroy a mutex
+#define psMutexDestroy(PTR) \
+if (pthread_mutex_destroy(&(PTR)->lock) == EBUSY) { \
+    psAbort("Cannot destroy mutex on %s: is busy", #PTR); \
+}
+
+#endif
Index: trunk/psLib/src/types/psArray.h
===================================================================
--- trunk/psLib/src/types/psArray.h	(revision 19052)
+++ trunk/psLib/src/types/psArray.h	(revision 19056)
@@ -10,6 +10,6 @@
  *  @author Joshua Hoblitt, University of Hawaii
  *
- *  @version $Revision: 1.53 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-08-08 18:05:34 $
+ *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-08-14 03:18:41 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -22,4 +22,5 @@
 #include "psCompare.h"
 #include "psVector.h"
+#include "psMutex.h"
 
 /// @addtogroup DataContainer Data Containers
@@ -36,5 +37,5 @@
     const long nalloc;                 ///< Total number of elements available.
     psPtr* data;                       ///< An Array of pointer elements
-    void *lock;                        ///< Optional lock for thread safety
+    psMutex lock;                       ///< Optional lock for thread safety
 }
 psArray;
Index: trunk/psLib/src/types/psBitSet.h
===================================================================
--- trunk/psLib/src/types/psBitSet.h	(revision 19052)
+++ trunk/psLib/src/types/psBitSet.h	(revision 19056)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-09 01:40:08 $
+ *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-08-14 03:18:41 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -21,4 +21,5 @@
 
 #include "psType.h"
+#include "psMutex.h"
 
 /// @addtogroup DataContainer Data Containers
@@ -39,5 +40,5 @@
     long n;                            ///< Number of bytes in the array
     psU8 *bits;                        ///< Aray of bytes holding bits
-    void *lock;                        ///< Optional lock for thread safety
+    psMutex lock;                       ///< Optional lock for thread safety
 }
 psBitSet;
Index: trunk/psLib/src/types/psHash.h
===================================================================
--- trunk/psLib/src/types/psHash.h	(revision 19052)
+++ trunk/psLib/src/types/psHash.h	(revision 19056)
@@ -11,6 +11,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-09 01:40:08 $
+ *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-08-14 03:18:41 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -24,4 +24,5 @@
 
 #include "psList.h"
+#include "psMutex.h"
 
 /** A bucket that holds an item of data. */
@@ -42,5 +43,5 @@
     long n;                            ///< Number of buckets in hash table.
     psHashBucket* *buckets;            ///< The bucket data.
-    void *lock;                        ///< Optional lock for thread safety.
+    psMutex lock;                       ///< Optional lock for thread safety.
 }
 psHash;
Index: trunk/psLib/src/types/psList.h
===================================================================
--- trunk/psLib/src/types/psList.h	(revision 19052)
+++ trunk/psLib/src/types/psList.h	(revision 19056)
@@ -5,6 +5,6 @@
  *  @author Robert Daniel DeSonia, MHPCC
  *
- *  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-08-08 18:06:27 $
+ *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-08-14 03:18:41 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -16,4 +16,5 @@
 #include "psCompare.h"
 #include "psArray.h"
+#include "psMutex.h"
 
 /// @addtogroup DataContainer Data Containers
@@ -54,5 +55,5 @@
     ///< used internally to improve performance when using indexed access, all
     ///< others are user-level iterators created by psListIteratorAlloc.
-    void *lock;                        ///< Optional lock for thread safety
+    psMutex lock;                       ///< Optional lock for thread safety
 } psList;
 
Index: trunk/psLib/src/types/psMetadata.h
===================================================================
--- trunk/psLib/src/types/psMetadata.h	(revision 19052)
+++ trunk/psLib/src/types/psMetadata.h	(revision 19056)
@@ -9,6 +9,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.104 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2008-05-05 00:09:04 $
+*  @version $Revision: 1.105 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2008-08-14 03:18:41 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -29,4 +29,5 @@
 #include "psTime.h"
 #include "psLookupTable.h"
+#include "psMutex.h"
 
 #define PS_DATA_IS_PRIMITIVE(TYPE) \
@@ -57,12 +58,12 @@
  */
 typedef enum {
-    PS_META_DEFAULT       = 0,		///< default behaviour (duplicate entry is an error)
-    PS_META_REPLACE       = 0x01000000,	///< allow entry to be replaced
-    PS_META_NO_REPLACE    = 0x02000000,	///< duplicate entry is silently skipped
-    PS_META_DUPLICATE_OK  = 0x04000000,	///< allow duplicate entries
-    PS_META_UPDATE_FOLDER = 0x08000000,	///< for a metadata folder, merge contents with existing md
-    PS_META_NULL          = 0x10000000,	///< psMetadataItem.data is a NULL value
-    PS_META_REQUIRE_ENTRY = 0x20000000,	///< require pre-existing entry with same name
-    PS_META_REQUIRE_TYPE  = 0x40000000	///< require pre-existing entry to have same type
+    PS_META_DEFAULT       = 0,          ///< default behaviour (duplicate entry is an error)
+    PS_META_REPLACE       = 0x01000000, ///< allow entry to be replaced
+    PS_META_NO_REPLACE    = 0x02000000, ///< duplicate entry is silently skipped
+    PS_META_DUPLICATE_OK  = 0x04000000, ///< allow duplicate entries
+    PS_META_UPDATE_FOLDER = 0x08000000, ///< for a metadata folder, merge contents with existing md
+    PS_META_NULL          = 0x10000000, ///< psMetadataItem.data is a NULL value
+    PS_META_REQUIRE_ENTRY = 0x20000000, ///< require pre-existing entry with same name
+    PS_META_REQUIRE_TYPE  = 0x40000000  ///< require pre-existing entry to have same type
 } psMetadataFlags;
 
@@ -83,5 +84,5 @@
     psList*  list;                     ///< Metadata in linked-list
     psHash*  hash;                     ///< Metadata in a hash table
-    void *lock;                        ///< Optional lock for thread safety
+    psMutex lock;                       ///< Optional lock for thread safety
 }
 psMetadata;
Index: trunk/psLib/src/types/psPixels.h
===================================================================
--- trunk/psLib/src/types/psPixels.h	(revision 19052)
+++ trunk/psLib/src/types/psPixels.h	(revision 19056)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-08-09 01:40:08 $
+ *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-08-14 03:18:41 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -45,5 +45,5 @@
     const long nalloc;                 ///< Number allocated
     psPixelCoord* data;                ///< The pixel coordinates
-    void *lock;                        ///< Option lock for thread safety
+    psMutex lock;                       ///< Option lock for thread safety
 }
 psPixels;
