home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / listpm7.zip / winthr.cpp < prev    next >
C/C++ Source or Header  |  1999-06-12  |  3KB  |  93 lines

  1. /*
  2.     listPM list files under Presentation Manager. Uses Open Class Libarary.
  3.     Copyright (C) 1998, 1999  Paul Elliott
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     Paul Elliott
  20.     PMB # 181
  21.     11900 Metric Blvd Ste. J
  22.     Austin Tx 78758-3117
  23. */
  24. #include "winthr.hpp"
  25.  
  26. #include <icritsec.hpp>
  27.  
  28. Boolean WindowThread::ICom::command( ICommandEvent& event )
  29. {
  30.  
  31.      // if the event id matches
  32.      if  ( ( event.commandId() == win_thread.eventid ) &&
  33.            ( event.controlWindow() == &win_thread.window  ) )
  34.      {
  35.         // have we been notified??
  36.         Boolean notified;
  37.         {
  38.           ICritSec lock;                   // lock befor checking notifing
  39.           notified = win_thread.notifing;  // we are being notified.
  40.  
  41.           win_thread.notifing = false;     // have been notified, no more.
  42.  
  43.         };
  44.         // if this thread is / has beeen notified.
  45.         if (notified)
  46.         {
  47.  
  48.           // call the finish code.
  49.           win_thread.finish() ;    // finish processing
  50.  
  51.          };
  52.      };
  53.      return false;
  54. };
  55.  
  56. // This thread code runs the window thread run code.
  57. void WindowThread::WinThrFn::run ()
  58. {
  59.      wt.run();
  60. };
  61.       // constructor remembers IWindow and eveint id #
  62. WindowThread::WindowThread(IWindow& window,const long eventid) :
  63.      eventid(eventid), window(window), thread_hand( *this), notifing(false)
  64. {
  65.  
  66. };
  67. // start thread user call.
  68. void WindowThread::win_th_start( Boolean auto_init )
  69. {
  70.     // first call begin on current thread.
  71.     begin();
  72.  
  73.  
  74.     // run thread to run thread code.
  75.     IThread doit( new WinThrFn(*this) , auto_init );
  76.     doit.adjustPriority(-17);
  77. };
  78. void WindowThread::run()
  79. {
  80.  
  81.     // call the thread code.
  82.     thread();
  83.  
  84.     // we are now notifing the original thread thru a command event.
  85.     {
  86.       ICritSec lock;
  87.       notifing = true;
  88.     };
  89.  
  90.     // post to declare completion.
  91.     window.postEvent( IWindow::command, eventid );
  92. };
  93.