Index: /code/branches/network/src/network/PacketBuffer.cc
===================================================================
--- /code/branches/network/src/network/PacketBuffer.cc	(revision 173)
+++ /code/branches/network/src/network/PacketBuffer.cc	(revision 174)
@@ -8,5 +8,5 @@
 
 PacketBuffer::PacketBuffer(){
-  locked=false;
+  closed=false;
   first=NULL;
   last=NULL;
@@ -14,41 +14,36 @@
 
 bool PacketBuffer::push(PacketEnvelope pck){
-  if(!locked){
-    locked=true;
-    // also works if fifo is null (queue empty)
-    // just to be sure last is really the last element
-    while(last!=NULL && last->next!=NULL)
-      last=last->next;
-    // first element?
-    if(first==NULL){
-      first=new QueueItem;
-      last=first;
-      last->next=NULL;
-      // change this!!!!!!!
-      last->packet = new PacketEnvelope;
-      last->packet->data = pck.data;
-      last->packet->length = pck.length;
-    } else {
-      //insert a new element at the bottom
-      last->next = new QueueItem;
-      last=last->next;
-      // initialize last->next
-      last->next=NULL;
-      // save the packet to the new element
-      // change this!!!!!!!!
-      last->packet = new PacketEnvelope;
-      last->packet->data = pck.data;
-      last->packet->length = pck.length;
-    }
-    locked=false;
-    return true;
+  boost::mutex::scoped_lock lock(networkPacketBufferMutex);
+  // also works if fifo is null (queue empty)
+  // just to be sure last is really the last element
+  while(last!=NULL && last->next!=NULL)
+    last=last->next;
+  // first element?
+  if(first==NULL){
+    first=new QueueItem;
+    last=first;
+    last->next=NULL;
+    // change this!!!!!!!
+    last->packet = new PacketEnvelope;
+    last->packet->data = pck.data;
+    last->packet->length = pck.length;
+  } else {
+    //insert a new element at the bottom
+    last->next = new QueueItem;
+    last=last->next;
+    // initialize last->next
+    last->next=NULL;
+    // save the packet to the new element
+    // change this!!!!!!!!
+    last->packet = new PacketEnvelope;
+    last->packet->data = pck.data;
+    last->packet->length = pck.length;
   }
-  else
-    return false;
+  return true;
 }
 
-PacketEnvelope *PacketBuffer::pop(){
-  if(!locked && first!=NULL){
-    locked = true;
+PacketEnvelope PacketBuffer::pop(){
+  boost::mutex::scoped_lock lock(networkPacketBufferMutex);
+  if(first!=NULL){
     QueueItem *temp = first;
     // get packet
@@ -57,16 +52,13 @@
     first = first->next;
     delete temp;
-    locked=false;
+    return *p;
+  } else{
+    PacketEnvelope p = {0,0};
     return p;
-  } else
-    return NULL;
+  }
 }
 
 bool PacketBuffer::isEmpty(){
   return (first==NULL);
-}
-
-bool PacketBuffer::isLocked(){
-  return locked;
 }
 
@@ -80,3 +72,12 @@
 }
 
+bool PacketBuffer::isClosed(){
+  return closed;
+}
+
+void PacketBuffer::setClosed(bool value){
+  closed=value;
+  return;
+}
+
 }// namespace network
Index: /code/branches/network/src/network/PacketBuffer.h
===================================================================
--- /code/branches/network/src/network/PacketBuffer.h	(revision 173)
+++ /code/branches/network/src/network/PacketBuffer.h	(revision 174)
@@ -16,4 +16,10 @@
 #include <queue>
 #include <string>
+#include <boost/bind.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/mutex.hpp>
+
+//this is needed in order to make the packetbuffer threadsafe
+boost::mutex networkPacketBufferMutex;
 
 namespace network{
@@ -32,15 +38,19 @@
 public:
   PacketBuffer();
-  bool isLocked();
   bool isEmpty();
+  bool isClosed();
+  void setClosed(bool value);
+  void print();
   // pops a packet from the queue
-  PacketEnvelope *pop();
+  PacketEnvelope pop();
   // pushs a packet to the queue
   bool push(PacketEnvelope pck);
-  void print();
 private:
-  bool locked;
   QueueItem *first;
   QueueItem *last;
+  bool closed;
+  
+  //make it threadsafe
+//   boost::mutex mutex;
 };
 
Index: /code/branches/network/src/network/PacketBufferTest.cc
===================================================================
--- /code/branches/network/src/network/PacketBufferTest.cc	(revision 173)
+++ /code/branches/network/src/network/PacketBufferTest.cc	(revision 174)
@@ -19,5 +19,5 @@
   test.print();
   while(!test.isEmpty()){
-    int i=test.pop()->data;
+    int i=test.pop().data;
     std::cout << "We popped the value " << i << std::endl;
   }
