Index: trunk/MagicSoft/Cosy/base/MThread.cc
===================================================================
--- trunk/MagicSoft/Cosy/base/MThread.cc	(revision 910)
+++ trunk/MagicSoft/Cosy/base/MThread.cc	(revision 910)
@@ -0,0 +1,135 @@
+#include <MThread.h>
+
+#include <pthread.h>
+#include <sys/resource.h>  // PRIO_PROCESS
+
+// ----------------------------------------------------------------------
+//
+// Constructor
+//
+// Starts the derived thread if you don't specify false.
+//
+MThread::MThread(bool start) : fIsRunning(false), fIsDetached(false), fThread(NULL), fReturn(NULL), fPriority(0)
+{
+    if (start)
+        Start();
+}
+
+// ----------------------------------------------------------------------
+//
+// Destructor
+//
+// Stops the derived thread if it is still running.
+//
+MThread::~MThread()
+{
+    if (fIsRunning)
+        Stop();
+}
+
+// ----------------------------------------------------------------------
+//
+// Detach the derived thread. This means, that if the thread ends the
+// needed resources (eg. for storing the return code) are freed.
+// In other word you cannot get any value back from the Thread.
+//
+void MThread::Detach()
+{
+    if (fIsRunning)
+        pthread_detach(*fThread);
+
+    fIsDetached = true;
+}
+
+// ----------------------------------------------------------------------
+//
+// Sets the priority of the thread.
+//  -20 highest priority
+//    0 standard
+//  +20 lowest priority
+// This can only be done before the thread is started.
+//
+bool MThread::SetPriority(int prio)
+{
+    if (fIsRunning)
+        return false;
+
+    fPriority = prio;
+    return true;
+}
+
+// ----------------------------------------------------------------------
+//
+// Now we are back in a class instance, but running in new thread.
+// All class members can be accessed like before.
+// Set the flag for a running thread. Check if the thread should get
+// detached. Set the priority of the thread. Now reset the stop flag and
+// execute the thread. After the thread stopped it's execution reset the
+// running flag and exit.
+//
+void *MThread::RunThread()
+{
+    fIsRunning = true;
+
+    if (fIsDetached)
+        pthread_detach(pthread_self());
+
+    setpriority(PRIO_PROCESS, 0, fPriority); //lowest priority
+
+    fStop = false;
+
+    void *rc = Thread();
+
+    fIsRunning = false;
+
+    return rc;
+}
+
+// ----------------------------------------------------------------------
+//
+// Get the Instance back from the thread argument and call the
+// RunThread member function, which handles all MThread bspecific stuff.
+//
+void *MThread::MapThread(void *arg)
+{
+    MThread *thread = (MThread*)arg;
+
+    return thread->RunThread();
+}
+
+// ----------------------------------------------------------------------
+//
+// A thread is created and started (MapThread).
+// As an argument the actual instance is used.
+//
+void MThread::Start()
+{
+    fThread = new pthread_t;
+    pthread_create(fThread, NULL, MapThread, this);
+}
+
+// ----------------------------------------------------------------------
+//
+// Check if a thread is existing and running.
+// If the thread is detached, cancel the thread. Otherwise set the stop
+// flag and wait for the thread to exit.
+//
+void MThread::Stop()
+{
+    if (!fThread || !fIsRunning)
+        return;
+
+    if (fIsDetached)
+    {
+        pthread_cancel(*fThread);
+        fIsRunning = false;
+    }
+    else
+    {
+        fStop = true;
+        pthread_join(*fThread, &fReturn);
+    }
+
+    delete fThread;
+    fThread = NULL;
+}
Index: trunk/MagicSoft/Cosy/base/MThread.h
===================================================================
--- trunk/MagicSoft/Cosy/base/MThread.h	(revision 910)
+++ trunk/MagicSoft/Cosy/base/MThread.h	(revision 910)
@@ -0,0 +1,37 @@
+#ifndef MTHREAD_H
+#define MTHREAD_H
+
+#include <pthread.h>
+
+class MThread 
+{
+private:
+    bool fIsRunning;
+    bool fIsDetached;
+    bool fStop;
+
+    pthread_t *fThread;
+
+    void *fReturn;
+
+    int fPriority;
+
+    static void *MapThread(void *arg);
+    void *RunThread();
+    virtual void *Thread() = 0;
+
+public:
+    MThread(bool start=true);
+    virtual ~MThread();
+
+    bool SetPriority(int prio);
+
+    void Detach();
+
+    void Start();
+    void Stop();
+
+    bool HasStopFlag() const { return fStop; }
+};
+
+#endif
Index: trunk/MagicSoft/Cosy/base/MTimeout.h
===================================================================
--- trunk/MagicSoft/Cosy/base/MTimeout.h	(revision 910)
+++ trunk/MagicSoft/Cosy/base/MTimeout.h	(revision 910)
@@ -0,0 +1,29 @@
+#ifndef MTIMEOUT_H
+#define MTIMEOUT_H
+
+#include <TTimer.h>
+
+class MTimeout : public TTimer
+{
+    Bool_t Notify()
+    {
+        TurnOff(); // remove from system list
+        return kFALSE;
+    }
+
+public:
+    MTimeout(Long_t ms=500) : TTimer(ms, kFALSE)
+    {
+        // Use SetTime to change the timing
+        if (ms) TurnOn(); // Add to system list
+    }
+
+    void Start()
+    {
+        Reset();  // reset before adding
+        TurnOn(); // Add to system list
+    }
+};
+
+
+#endif
Index: trunk/MagicSoft/Cosy/base/Makefile
===================================================================
--- trunk/MagicSoft/Cosy/base/Makefile	(revision 910)
+++ trunk/MagicSoft/Cosy/base/Makefile	(revision 910)
@@ -0,0 +1,55 @@
+##################################################################
+#
+#   makefile
+# 
+#   for the MARS software
+#
+##################################################################
+# @maintitle
+
+# @code
+
+#
+#  please change all system depend values in the 
+#  config.mk.${OSTYPE} file 
+#
+#
+include ../Makefile.conf.$(OSTYPE)
+include ../Makefile.conf.general
+
+# @endcode 
+
+INCLUDES = -I. -I..
+
+# @code 
+
+CINT     = Base
+LIB      = base.a
+
+#------------------------------------------------------------------------------
+
+.SUFFIXES: .c .cc .cxx .h .hxx .o 
+
+SRCFILES = File.cc \
+	   MStopwatch.cc \
+           MThread.cc \
+	   MTimeout.cc \
+           msgqueue.cc \
+           timer.cc 
+
+SRCS    = $(SRCFILES)
+HEADERS = $(SRCFILES:.cc=.h)
+OBJS    = $(SRCFILES:.cc=.o) 
+
+############################################################
+
+all: $(LIB)
+
+include ../Makefile.rules
+
+clean:	rmlib rmcint rmobjs rmcore
+
+mrproper:	clean rmbak
+
+# @endcode
+
