Index: trunk/Ohana/src/opihi/pcontrol/StackOps.c
===================================================================
--- trunk/Ohana/src/opihi/pcontrol/StackOps.c	(revision 8296)
+++ trunk/Ohana/src/opihi/pcontrol/StackOps.c	(revision 8424)
@@ -25,7 +25,7 @@
   ALLOCATE (stack[0].id,     int,    stack[0].NOBJECT);
 
-  // we need to use a mutex of type 
-  // stack[0].mutex = PTHREAD_MUTEX_INITIALIZER;
-
+# ifdef THREADED
+  pthread_mutex_init (&stack[0].mutex, NULL);
+# endif
   return (stack);
 }
@@ -72,5 +72,4 @@
 void *PullStackByLocation (Stack *stack, int where) {
 
-  int i;
   void *object;
   
@@ -96,5 +95,5 @@
 void *PullStackByName (Stack *stack, char *name) {
 
-  int i, j;
+  int i;
   void *object;
 
@@ -106,5 +105,5 @@
     /* here is the element of interest */
     object = stack[0].object[i];
-    RemoveStackEntry (i);
+    RemoveStackEntry (stack, i);
     UnlockStack (stack); 
     return (object);
@@ -117,5 +116,5 @@
 void *PullStackByID (Stack *stack, int id) {
 
-  int i, j;
+  int i;
   void *object;
   
@@ -137,4 +136,6 @@
 /* should only be called if you know where is a valid entry */
 int RemoveStackEntry (Stack *stack, int where) {
+
+  int i;
 
   if (where < 0) abort();
@@ -152,8 +153,8 @@
 }
 
-/* should only be called if manually lock the stack */
-int RemoveStackByID (Stack *stack, int id) {
-
-  int i, j;
+/* should only be called if you manually lock the stack */
+void *RemoveStackByID (Stack *stack, int id) {
+
+  int i;
   void *object;
   
@@ -205,10 +206,14 @@
 
 void LockStack (Stack *stack) {
+# ifdef THREADED
+  pthread_mutex_lock (&stack[0].mutex);
+# endif
   return;
 }
 
 void UnlockStack (Stack *stack) {
+# ifdef THREADED
+  pthread_mutex_unlock (&stack[0].mutex);
+# endif
   return;
 }
-
-// Safe with PTHREAD_MUTEX_INITIALIZER lock
