Changeset 2492 in Sophya for trunk/SophyaPI/PIext


Ignore:
Timestamp:
Jan 6, 2004, 6:05:25 PM (22 years ago)
Author:
ansari
Message:

Suite debug piapp multithread : on ne peut pas utiliser ZSync() ds un if (destructeur appele de suite) - Reza 06/01/2004

Location:
trunk/SophyaPI/PIext
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/nobjmgr.cc

    r2491 r2492  
    321321if (myImgApp)  {
    322322  string str = '/' + dirname;
    323   if ( !_fgimgapp )  ZSync(myImgApp->getMutex(),2);
     323  if ( !_fgimgapp )  myImgApp->LockMutex();
    324324  (myImgApp->ObjMgrW())->AddDirectory(str.c_str(), myDirId);
    325   }
     325  if ( !_fgimgapp )  myImgApp->UnlockMutex(true);
     326}
    326327if (verbeux) cout << "NamedObjMgr::CreateDir() " << dirname << " Created " << endl;
    327328return(true);
     
    355356
    356357if (myImgApp) {
    357   if ( !_fgimgapp )  ZSync(myImgApp->getMutex(),2);
     358  if ( !_fgimgapp )  myImgApp->LockMutex();
    358359  (myImgApp->ObjMgrW())->DelDirectory((*it).second.id);
     360  if ( !_fgimgapp )  myImgApp->UnlockMutex(true);
    359361}
    360362myDirs->erase(it);
     
    497499for(ii=odel.begin(); ii != odel.end(); ii++)  DelObj(*ii,true);
    498500if (myImgApp) {
    499   if ( !_fgimgapp )  ZSync(myImgApp->getMutex(),2);
     501  if ( !_fgimgapp )  myImgApp->LockMutex();
    500502  (myImgApp->ObjMgrW())->UpdateList(did);
     503  if ( !_fgimgapp )  myImgApp->UnlockMutex(true);
    501504}
    502505}
     
    607610
    608611if (myImgApp != NULL) {
    609   if ( !_fgimgapp )  ZSync(myImgApp->getMutex(),2);
     612  if ( !_fgimgapp )  myImgApp->LockMutex();
    610613  if ( (myImgApp->ObjMgrW())->Visible() ) {
    611614    string oln = nobj + "  (T= " + no.obja->GetDataObjType() + ")" ;
    612615    (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid);
    613616  }
     617  if ( !_fgimgapp )  myImgApp->UnlockMutex(true);
    614618}
    615619if (verbeux) cout << "NamedObjMgr::AddObj()  Object " << nom << " ( " 
     
    689693
    690694if (myImgApp != NULL) {
    691   if ( !_fgimgapp )  ZSync(myImgApp->getMutex(),2);
     695  if ( !_fgimgapp )  myImgApp->LockMutex();
    692696  if ( (myImgApp->ObjMgrW())->Visible() ) {
    693697    (myImgApp->ObjMgrW())->DelObjList(dids, no.oid);
     
    695699    (myImgApp->ObjMgrW())->AddObjList(did, oln.c_str(), no.oid);
    696700  }
     701  if ( !_fgimgapp )  myImgApp->UnlockMutex(true);
    697702}
    698703if (verbeux)
     
    741746if (myImgApp) {
    742747//DBG  cerr << " *DBG* NamedObjMgr::DelObj Sz= " << (*it).second.wrsid.size() << endl;
     748// Si appel venant de PIStdImgApp, il ne faut pas locker le Mutex global de la boucle d'evts
     749  bool fglock = (_fgimgapp) ? false : true;
     750  if (fglock) myImgApp->LockMutex();
    743751  for(ii=(*it).second.wrsid.begin(); ii != (*it).second.wrsid.end(); ii++)
    744752      myImgApp->DelWRsId((*ii));
     753  if (fglock) myImgApp->UnlockMutex(true);
    745754}
    746755delete (*it).second.obja;  // destruction de l'adaptateur
     
    748757
    749758if (myImgApp != NULL) {
    750   if ( !_fgimgapp )  ZSync(myImgApp->getMutex(),2);
     759  if ( !_fgimgapp )  myImgApp->LockMutex();
    751760  if ( (myImgApp->ObjMgrW())->Visible() ) {
    752761    int olid = (*it).second.oid;
    753762    (myImgApp->ObjMgrW())->DelObjList(did, olid);
    754763  }
     764  if ( !_fgimgapp )  myImgApp->UnlockMutex(true);
    755765}
    756766myObjs->erase(it);
     
    15931603if (!myImgApp)  return;
    15941604ZSync(*myMutex);
    1595 if ( !_fgimgapp )  ZSync(myImgApp->getMutex(),2);
     1605if ( !_fgimgapp )  myImgApp->LockMutex();
    15961606
    15971607(myImgApp->ObjMgrW())->ClearObjList();
     
    16061616  (myImgApp->ObjMgrW())->AddObj(cn.c_str(), (*it).second.oid);
    16071617  }
     1618
     1619if ( !_fgimgapp )  myImgApp->UnlockMutex(true);
    16081620}
    16091621
  • trunk/SophyaPI/PIext/pistdimgapp.cc

    r2491 r2492  
    22#include <stdlib.h>
    33#include <stdio.h>
     4#include <unistd.h>
    45#include <string.h>
    56
     
    406407  {
    407408    while (!_fgstop) {
    408       usleep(1000);
     409      usleep(2000);
    409410      _app->getMutex().broadcast();
    410411    }
     
    443444
    444445thr_glsyn.lock(); //  <ZThread>
    445 //DBG int klp = 0;
     446//DEL-DBG int klp = 0;
    446447while (mStop) {
    447448  fg_glsynlock = true;
     
    451452    XtDispatchEvent(&evt);
    452453    nevtproc++;
    453     if (nevtproc >= 50)  break;
     454    if (nevtproc >= 200)  break;
    454455  }
    455456  fg_glsynlock = false;
     457  //DBG cout << " "DBG-Run:: Going to wait ... " << klp << endl;
    456458  thr_glsyn.wait();  //  <ZThread>
    457   //  cout << "DBG-Run:: Out of wait " << ++klp << endl; 
     459  //DBG cout << "DBG-Run:: Out of wait " << ++klp << endl; 
    458460    //  usleep(1000);
    459461}
     
    626628}
    627629
     630class SyncPIS {
     631public:
     632  explicit SyncPIS(ZMutex & mtx, bool fglock=true, int sigbr=0)
     633  {
     634  _mtx = &mtx; _sigbr = sigbr;
     635  _fglock = fglock;
     636  if (_fglock)  mtx.lock();
     637  }
     638  ~SyncPIS()
     639  {
     640    if (_fglock && (_mtx != NULL) ) {
     641      if (_sigbr == 1) _mtx->signal();
     642      else  if (_sigbr == 2) _mtx->broadcast();
     643      _mtx->unlock();
     644    }
     645  }
     646
     647private:
     648  ZMutex * _mtx;
     649  int _sigbr;
     650  bool _fglock;
     651  inline        SyncPIS() {_mtx = NULL; _sigbr = 0; _fglock = false; }
     652};
     653
    628654
    629655/* --Methode-- */
     
    656682
    657683// <ZThread> global PIApplication event loop synchronisation
    658 if (fglock) ZSync zs(thr_glsyn, 2); 
     684SyncPIS zs(getMutex(), fglock, 2);
    659685
    660686// Choix de la taille de fenetre
     
    726752
    727753// <ZThread> global PIApplication event loop synchronisation
    728 if (fglock) ZSync zs(thr_glsyn, 2); 
     754SyncPIS zs(getMutex(), fglock, 2);
    729755
    730756// Trace en superpoistion
     
    830856
    831857// <ZThread> global PIApplication event loop synchronisation
    832 if (fglock) ZSync zs(thr_glsyn, 2); 
     858SyncPIS zs(getMutex(), fglock, 2);
    833859
    834860// Trace en superpoistion
  • trunk/SophyaPI/PIext/pistdimgapp.h

    r2491 r2492  
    5858     virtual void   Run();
    5959     inline ZMutex &   getMutex() { return thr_glsyn; }
     60     inline void       LockMutex() { thr_glsyn.lock(); }
     61     inline void       UnlockMutex(bool fgbr=false)
     62        { thr_glsyn.broadcast(); thr_glsyn.unlock(); }
    6063     inline bool       isGlSyncLocked() { return fg_glsynlock; }
    6164
Note: See TracChangeset for help on using the changeset viewer.