Index: trunk/MagicSoft/Mars/mbase/BaseLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 8805)
+++ trunk/MagicSoft/Mars/mbase/BaseLinkDef.h	(revision 8842)
@@ -31,4 +31,5 @@
 #pragma link C++ class MDirIter+;
 #pragma link C++ class MRunIter+;
+#pragma link C++ class MThread+;
 
 // Mars core
Index: trunk/MagicSoft/Mars/mbase/MThread.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MThread.cc	(revision 8842)
+++ trunk/MagicSoft/Mars/mbase/MThread.cc	(revision 8842)
@@ -0,0 +1,102 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz  1/2008 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2008
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// MThread
+//
+// Implementing a slightly simplified interface to multi-threading
+// based on TThread
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MThread.h"
+
+ClassImp(MThread);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Return the thread's state as string
+//
+TString MThread::GetThreadStateStr() const
+{
+    switch (fThread.GetState())
+    {
+    case TThread::kInvalidState:
+        return "Invalid - thread was not created properly";
+    case TThread::kNewState:
+        return "New - thread object exists but hasn't started";
+    case TThread::kRunningState:
+        return "Running - thread is running";
+    case TThread::kTerminatedState:
+        return "Terminated - thread has terminated but storage has not yet been reclaimed (i.e. waiting to be joined)";
+    case TThread::kFinishedState:
+        return "Finished - thread has finished";
+    case TThread::kCancelingState:
+        return "Canceling - thread in process of canceling";
+    case TThread::kCanceledState:
+        return "Canceled - thread has been canceled";
+    case TThread::kDeletingState:
+        return "Deleting - thread in process of deleting";
+    };
+    return "Unknown";
+}
+
+/*
+{
+    TMethodCall call(cl, "Name", 0);
+
+    if (!call.IsValid())
+        return 0;
+
+    //const char    *GetParams() const { return fParams.Data(); }
+    //const char    *GetProto() const { return fProto.Data(); }
+
+    switch (call.ReturnType())
+    {
+    case kLong:
+        break;
+    case kDouble:
+        break;
+    case kString:
+        break;
+    case kOther:
+        break;
+    case kNone:
+        break;
+    }
+
+    // NOTE execute functions are locked by a global mutex!!!
+
+   void     Execute(void *object);
+   void     Execute(void *object, Long_t &retLong);
+   void     Execute(void *object, Double_t &retDouble);
+   void     Execute(void *object, char **retText);
+
+   void     Execute();
+   void     Execute(Long_t &retLong);
+   void     Execute(Double_t &retDouble);
+}
+*/
Index: trunk/MagicSoft/Mars/mbase/MThread.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MThread.h	(revision 8842)
+++ trunk/MagicSoft/Mars/mbase/MThread.h	(revision 8842)
@@ -0,0 +1,81 @@
+#ifndef MARS_MThread
+#define MARS_MThread
+
+#ifndef ROOT_TThread
+#include <TThread.h>
+#endif
+
+class MThread // We don't want MThread to be derived from TObject
+{
+private:
+    TThread fThread;
+
+    Int_t fNumCleanups;
+
+    virtual void CleanUp() { }
+    static void MapCleanUp(void *arg)
+    {
+        MThread *th = (MThread*)arg;
+        th->CleanUp();
+    }
+
+    virtual Int_t Thread() = 0;
+    static void *MapThread(void *arg)
+    {
+        // GetPriority();     High: -1 - -20, Norm: 0, Low: 1-20
+        // pthread_setschedprio(SelfId(), priority);
+        // 0: ok,
+
+        TThread::CleanUpPush((void*)&MapCleanUp, arg);
+
+        MThread *th = (MThread*)arg;
+        return (void*)th->Thread();
+    }
+
+public:
+    MThread(TThread::EPriority pri = TThread::kNormalPriority) :
+        fThread(MapThread, this, pri), fNumCleanups(0) { }
+    MThread(const char *thname, TThread::EPriority pri = TThread::kNormalPriority) :
+        fThread(thname, MapThread, this, pri), fNumCleanups(0) { }
+    virtual ~MThread() { }
+
+    // Setter: Thread control
+    Int_t RunThread(void *arg = 0) { return fThread.Run(); }
+
+    // Send cancel request and wait for cancellation
+    // 13 is returned if thread is not running,
+    // the return code of Join otherwise
+    Int_t CancelThread(void **ret = 0) {
+        const Int_t rc = fThread.Kill();
+        if (rc==13) // Thread not running
+            return rc;
+        return fThread.Join(ret);
+    }
+
+    // Int_t            Kill() { return fThread.Kill(); }
+    // Long_t           Join(void **ret = 0) { return fThread.Join(ret); }
+
+    // void             SetPriority(EPriority pri)
+    // void             Delete(Option_t *option="") { TObject::Delete(option); }
+
+    // Getter
+    TThread::EState  GetThreadState() const { return fThread.GetState(); }
+    TString          GetThreadStateStr() const;
+    Long_t           GetThreadId() const { return fThread.GetId(); }
+    // EPriority        GetPriority() const { return fPriority; }
+
+    Bool_t IsThreadRunning()  const { return fThread.GetState()==TThread::kRunningState; }
+    Bool_t IsThreadCanceled() const { return fThread.GetState()==TThread::kCancelingState; }
+
+    // This is a version of usleep which is a cancel point
+    static void Sleep(UInt_t us)
+    {
+        TThread::SetCancelOn();
+        usleep(us);
+        TThread::SetCancelOff();
+    }
+
+    ClassDef(MThread,0)  // A simplified interface to TThread
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mbase/Makefile	(revision 8805)
+++ trunk/MagicSoft/Mars/mbase/Makefile	(revision 8842)
@@ -61,5 +61,6 @@
            MContinue.cc \
            MPrint.cc \
-           MZlib.cc
+           MZlib.cc \
+	   MThread.cc
 
 ############################################################
