Changeset 2486 in Sophya


Ignore:
Timestamp:
Dec 26, 2003, 12:17:41 PM (22 years ago)
Author:
ansari
Message:

Debut d'implementation piapp multi-thread - (avec des pb lors de l'execution de demo.pic) Reza 26 Dec 2003

Location:
trunk/SophyaPI/PIext
Files:
4 edited

Legend:

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

    r2474 r2486  
    180180
    181181InitializeHelpWindowMenu();
     182// <ZThread>  Thread control attributes
     183fg_thrstop = false;
     184fg_threxe = false;
    182185}
    183186
     
    195198}
    196199
     200
     201/* --Methode-- */
     202void PIACmd::AddInputLine(string const & line)
     203{
     204  mutx_inps.lock();
     205  inputlines.push(line);
     206  mutx_inps.unlock();
     207  mutx_inps.broadcast();
     208}
     209
     210/* --Methode-- */
     211void PIACmd::StopThread()
     212{
     213  fg_thrstop = true;
     214  mutx_inps.broadcast();
     215}
     216
     217/* --Methode-- */
     218void PIACmd::run()
     219{
     220  cout << " DBG-PIACmd::run() -- DEBUT " << endl;
     221  while (!fg_thrstop) {
     222    mutx_inps.lock();
     223    while (inputlines.empty()) {
     224      fg_threxe = false;
     225      mutx_inps.wait();
     226    }
     227    string line = inputlines.top();
     228    inputlines.pop();
     229    fg_threxe = true;
     230    mutx_inps.unlock();
     231    Interpret(line);
     232  }
     233}
    197234
    198235/* --Methode-- */
  • trunk/SophyaPI/PIext/piacmd.h

    r2474 r2486  
    1111#include <string>
    1212#include <vector>
     13#include <stack>
     14#include "zthread.h"
    1315
    1416#include "dlftypes.h"
     
    2931
    3032
    31 class PIACmd : public Commander  {
     33class PIACmd : public Commander, public ZThread  {
    3234public:
    3335  //  static PIACmd*    GetInterpreter();
     
    3638  virtual               ~PIACmd();
    3739
     40  // Thread execution  <ZThread>
     41  virtual void          run();
     42  void                  AddInputLine(string const & line);
     43  void                  StopThread();
     44  inline  bool          isRunning(int& ninp)
     45    { ninp = inputlines.size(); return fg_threxe; }
     46  // ---- FIN ---- Thread execution  <ZThread>
    3847
    3948  void                   ShowHelpWindow();
     
    7786  CxxExecWind* cxxexwin;
    7887  CxxOptionWind* cxxoptwin;
     88
     89// Stack d'entree et controle de thread
     90  stack<string> inputlines;
     91  bool fg_thrstop;
     92  ZMutex mutx_inps;
     93  bool fg_threxe;
     94
    7995};
    8096
  • trunk/SophyaPI/PIext/pistdimgapp.cc

    r2427 r2486  
    9090/* --Methode-- */
    9191PIStdImgApp::PIStdImgApp(int narg, char* arg[])
    92 : PIApplication(420, 320, narg, arg)
     92  : PIApplication(420, 320, narg, arg) , resusg(ResourceUsage::RU_All)
    9393{
    9494
     
    188188// le widget zoom, colormap, stats, ...
    189189
    190 int bss = 100+mFgScSz*15;
     190int bss = 105+mFgScSz*15;
    191191
    192192int statc_szy = bss+10+14+mFgScSz*2+5;
     
    202202
    203203// Widget pour affichage des stats / ressources
    204 lab_mem = new PILabel(statcont, "memlab", msx-2*(bss+20), 20, 2*bss+20, 10);
     204lab_mem = new PILabel(statcont, "memlab", msx-2*(bss+20), 20, 2*bss+20, 5);
    205205lab_mem->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free);
    206206lab_mem->SetLabel("MemoryUsage");
    207207lab_mem->SetForegroundColor(PI_Red);
    208208lab_mem->SetBorderWidth(1);
    209 therm_mem = new PIThermometer(statcont, "memtherm", msx-2*(bss+20), 20, 2*bss+20, 35);
     209therm_mem = new PIThermometer(statcont, "memtherm", msx-2*(bss+20), 15, 2*bss+20, 30);
    210210therm_mem->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free);
    211211therm_mem->SetThreshold(0.5, 0.75);
    212212
    213 lab_cpu = new PILabel(statcont, "cpulab", msx-2*(bss+20), 20, 2*bss+20, 60);
     213lab_cpu = new PILabel(statcont, "cpulab", msx-2*(bss+20), 20, 2*bss+20, 50);
    214214lab_cpu->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free);
    215215lab_cpu->SetLabel("CPUUsage");
    216216lab_cpu->SetForegroundColor(PI_Black);
    217217lab_cpu->SetBorderWidth(1);
    218 therm_cpu = new PIThermometer(statcont, "cputherm", msx-2*(bss+20), 20, 2*bss+20, 85);
     218therm_cpu = new PIThermometer(statcont, "cputherm", msx-2*(bss+20), 15, 2*bss+20, 75);
    219219therm_cpu->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free);
    220220therm_cpu->SetThreshold(0.75, 0.90);
    221 
    222  fg_exc_cmd = false;
     221lab_thrcmd = new PILabel(statcont, "thrcmdlab", msx-2*(bss+20), 20, 2*bss+20, 95);
     222lab_thrcmd->SetBinding(PIBK_fixed,PIBK_fixed,PIBK_fixed, PIBK_free);
     223lab_thrcmd->SetLabel("CommandThread");
     224lab_thrcmd->SetForegroundColor(PI_Green);
     225lab_thrcmd->SetBorderWidth(1);
     226
     227fg_exc_cmd = false;
     228mCmd = NULL;  // Avant d'appeler UpdateStatResource() si PIACmd non cree
    223229UpdateStatResourceInfo();
    224230resupd_periodic = new SIA_RU__Periodic(this);
     
    347353delete lab_cpu;
    348354delete therm_cpu;
     355delete lab_thrcmd;
    349356
    350357delete statcont;
     
    372379
    373380
     381
     382/* --Methode-- */
     383void PIStdImgApp::Run()
     384{
     385XEvent evt;
     386int szx, szy, szf;
     387XtAppContext * appctx = PIXtAppCtx(szx, szy, szf);
     388// Pour appeler FinishCreate() des objets dans la fenetre principale
     389if (mStop) { // C'est la premiere fois
     390  topcont->SetSize(topcont->XSize(), topcont->YSize());
     391  MBCont()->FinishCreate();   
     392  }
     393else mStop = true;   // On rerentre apres un stop
     394
     395mCmd->start();
     396
     397while (mStop) {
     398  thr_glsyn.lock(); //  <ZThread>
     399  if (XtAppPending(*appctx) != 0) {
     400    XtAppNextEvent(*appctx, &evt);
     401    XtDispatchEvent(&evt);
     402  }
     403  thr_glsyn.unlock(); // <ZThread>
     404  usleep(1000);
     405}
     406return;
     407}
    374408
    375409/* --Methode-- */
     
    479513#else
    480514  try {
    481     mCmd->Interpret(s);
     515    //    mCmd->Interpret(s);
     516    mCmd->AddInputLine(s);
    482517    } 
    483518  catch ( PThrowable & exc ) {
     
    559594// Pas de same ou inset pour DispImage
    560595if ((dwopt == Disp_Same) || (dwopt == Disp_Inset) ) dwopt = Disp_Next;
     596
     597// <ZThread> global PIApplication event loop synchronisation
     598ZSync zs(thr_glsyn); 
    561599
    562600// Choix de la taille de fenetre
     
    626664DispWinEnum dwopt = ParseDisplayOption(sop, opts);
    627665if ( (!mLastWdg) && ( (dwopt == Disp_Same) || (dwopt == Disp_Inset) ) )  dwopt = Disp_Next;
     666
     667// <ZThread> global PIApplication event loop synchronisation
     668ZSync zs(thr_glsyn); 
     669
    628670// Trace en superpoistion
    629671if ( (dwopt == Disp_Same) && (mLastWdg) ) { 
     
    726768
    727769if ( (!mLastWdg) && ( (dwopt == Disp_Same) || (dwopt == Disp_Inset) ) )  dwopt = Disp_Next;
     770
     771// <ZThread> global PIApplication event loop synchronisation
     772ZSync zs(thr_glsyn); 
     773
    728774// Trace en superpoistion
    729775if ( (dwopt == Disp_Same) && (mLastWdg) ) {
     
    13591405  else
    13601406    therm_cpu->SetValue(resusg.getAverageCPULoad());
     1407  int nlx = 0;
     1408  bool fgx = false;
     1409  if (mCmd) fgx = mCmd->isRunning(nlx);
     1410  if (!fgx) {
     1411    lab = "PIACmdThread Idle";
     1412    lab_thrcmd->SetLabel(lab);
     1413    lab_thrcmd->SetForegroundColor(PI_Green);
     1414  }
     1415  else {
     1416    sprintf(buff, "PIACmdThread Running - NL=%d" , nlx);
     1417    lab = buff;
     1418    lab_thrcmd->SetLabel(lab);
     1419    if (nlx < 3)     lab_thrcmd->SetForegroundColor(PI_Yellow);
     1420    else     lab_thrcmd->SetForegroundColor(PI_Red);   
     1421  }
    13611422}
    13621423
  • trunk/SophyaPI/PIext/pistdimgapp.h

    r2265 r2486  
    3434#include "pitherm.h"
    3535
     36#include "zthread.h"
    3637#include "resusage.h"
    3738
     
    5354     virtual void   SetBlocked();
    5455
     56  // <ZThread>  Multithread execution
     57  // On redefinit la methode Run pour gestion multithread
     58     virtual void   Run();
     59     inline ZMutex &   getMutex() { return thr_glsyn; }
     60
     61  // Methodes d'Affichage generique
    5562     int  DispImage(P2DArrayAdapter* nouv, string const & name, string const & opt, int oid=0);
    5663     int  DispScDrawer(PIDrawer* scd, string const & name, string const & opt,
     
    171178    PIPixmap* gimv;
    172179    PICMapView* cmapv;
    173   // Pour afficher des stats
     180  // Pour afficher des stats et etat thread command
    174181    PILabel* lab_mem;
    175182    PIThermometer* therm_mem;
    176183    PILabel* lab_cpu;
    177184    PIThermometer* therm_cpu;
     185    PILabel* lab_thrcmd;
    178186
    179187    PIFileChooser * pfc_fits;   // Pour les fichiers FITS
     
    224232    string exc_command;
    225233    bool fg_exc_cmd;
     234  // Attributs pour controle de thread
     235    ZMutex thr_glsyn;
    226236};
    227237
Note: See TracChangeset for help on using the changeset viewer.