Index: /trunk/SophyaLib/SysTools/objlist.list
===================================================================
--- /trunk/SophyaLib/SysTools/objlist.list	(revision 1611)
+++ /trunk/SophyaLib/SysTools/objlist.list	(revision 1612)
@@ -5,2 +5,3 @@
 psighand.o
 timing.o
+zthread.o
Index: /trunk/SophyaLib/SysTools/zthread.cc
===================================================================
--- /trunk/SophyaLib/SysTools/zthread.cc	(revision 1612)
+++ /trunk/SophyaLib/SysTools/zthread.cc	(revision 1612)
@@ -0,0 +1,101 @@
+// Interface C++ aux Thread POSIX  -   R. Ansari 02/2001
+// LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA
+
+#include "zthread.h"
+#include <stdlib.h>
+#include <stdio.h>
+
+#define CheckSt(st_, strg_)  if (st_ != 0)  perror(strg_); 
+
+/*
+extern "C" {
+  void * zthr_run( void * xthr);
+}
+*/
+
+static void * zthr_run(void * xthr)
+{
+  ZThread * thr = (ZThread *)xthr;
+  thr->run();
+  pthread_exit(NULL);
+  return NULL;
+}
+
+
+/* ------ Classe ZThread  -------  */
+
+ZThread::ZThread(size_t stacksize)
+{
+  _initok = false;
+  _ssize = 0;
+  _act = NULL;
+  _usp = NULL;
+  _rc = -99;
+}
+
+ZThread::~ZThread()
+{
+  // Que faut-il faire ?
+}
+
+void ZThread::start()
+{
+  if (_initok) throw ZThreadExc("ZThread::Start() - Already started thread !");
+  int rc;
+  pthread_attr_t tha;
+  rc = pthread_attr_init(&tha);
+  CheckSt(rc,"ZThread::start() - Pb creating tha attribute object");
+  if (_ssize > 0) 
+    rc = pthread_attr_setstacksize(&tha, _ssize);
+  rc = pthread_create(&_thr, &tha, zthr_run, this);
+  CheckSt(rc,"ZThread::start() - Pb creating the thread object");     
+  _initok = true;
+  setRC(rc);      
+}
+
+
+void ZThread::cancel()
+{
+  if (!_initok) throw ZThreadExc("ZThread::cancel() - thread not started !");
+  int rc = pthread_cancel(_thr);
+  CheckSt(rc,"ZThread::cancel() - Pb pthread_cancel() ");  
+  setRC(-77);      
+}
+
+
+void ZThread::join()
+{
+  if (!_initok) throw ZThreadExc("ZThread::join() - thread not started !");
+  void * x;
+  int rc = pthread_join(_thr, &x);
+  CheckSt(rc,"ZThread::Join() - Pb pthread_join() ");
+  return;  
+}
+
+void ZThread::run()
+{
+  if (_act)  _act(_usp);
+  setRC(0);      
+  return;
+}
+
+
+/* ------ Classe ZMutex -------  */
+
+ZMutex::ZMutex()
+{
+  _mutx = new pthread_mutex_t;
+  _condv = new pthread_cond_t;
+  int rc;
+  rc = pthread_mutex_init(_mutx, NULL);
+  CheckSt(rc,"ZMutex::ZMutex() Pb pthread_mutex_init");
+  rc = pthread_cond_init(_condv, NULL);
+  CheckSt(rc,"ZMutex::ZMutex() Pb pthread_cond_init");
+}
+
+ZMutex::~ZMutex()
+{
+  delete _mutx;
+  delete _condv;
+}
+
Index: /trunk/SophyaLib/SysTools/zthread.h
===================================================================
--- /trunk/SophyaLib/SysTools/zthread.h	(revision 1612)
+++ /trunk/SophyaLib/SysTools/zthread.h	(revision 1612)
@@ -0,0 +1,93 @@
+// This may look like C code, but it is really -*- C++ -*-
+// Interface C++ aux Thread POSIX  -   R. Ansari 02/2001
+// LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA
+
+#ifndef ZTHREAD_SEEN
+#define ZTHREAD_SEEN
+
+#include "machdefs.h"
+#include <pthread.h>
+#include "pexceptions.h"
+
+
+namespace SOPHYA {
+
+typedef void (* ZThreadAction) (void *);
+  
+class ZThreadExc : public PException {
+public:
+  explicit ZThreadExc(const string& m, int id=0) : PException(m,id) {}
+};
+
+class ZThread {
+public:
+  explicit	ZThread(size_t stacksize=0);
+  virtual	~ZThread();
+  void		start();
+  void		cancel();
+  inline void   stop() { cancel(); }
+
+  void          join();
+  virtual void  run();
+
+  inline void   setRC(int rc) { _rc = rc; }
+  inline int    getRC(int rc) { return(_rc);
+ }
+  inline void	setAction(ZThreadAction act, void * usp=NULL)
+       {  _act = act;  _usp = usp; }
+
+
+  static inline void setCancelState(int st= PTHREAD_CANCEL_ENABLE) 
+       { int ocs; pthread_setcancelstate(st, &ocs); }
+  // PTHREAD_CANCEL_ENABLE  ou PTHREAD_CANCEL_DISABLE
+  static inline void setCancelType(int ct= PTHREAD_CANCEL_DEFERRED) 
+       { int oct; pthread_setcanceltype(ct, &oct); }
+  // PTHREAD_CANCEL_DEFERRED  ou  PTHREAD_CANCEL_ASYNCHRONOUS
+
+
+  // ---- Attribute variables ----
+  pthread_t _thr;
+  size_t _ssize;
+  int _rc;
+  bool _initok;
+
+  ZThreadAction _act;
+  void * _usp;
+};
+
+
+class ZMutex {
+public:
+  explicit	ZMutex();
+  virtual	~ZMutex();
+  inline void	lock()
+    { pthread_mutex_lock(_mutx); } 
+  inline void	unlock()
+    { pthread_mutex_unlock(_mutx); } 
+  inline void	wait()
+    { pthread_cond_wait(_condv, _mutx); }
+  inline void	signal()
+  { pthread_cond_signal(_condv); }
+  inline void	broadcast()
+  { pthread_cond_broadcast(_condv); }
+
+  // Attributes
+  pthread_mutex_t * _mutx;
+  pthread_cond_t * _condv;
+};
+
+
+class ZSync {
+public:
+  explicit inline  ZSync(ZMutex & mtx) {_mtx = &mtx; mtx.lock(); }
+  inline	   ~ZSync() { _mtx->unlock(); }
+
+private:
+  ZMutex * _mtx;
+  inline	ZSync() {_mtx = NULL; }
+
+};
+
+} // namespace SOPHYA
+
+#endif
