home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / listpm4.zip / source / winthr.cpp < prev    next >
C/C++ Source or Header  |  1998-04-22  |  3KB  |  92 lines

  1. /*
  2.     listPM list files under Presentation Manager. Uses Open Class Libarary.
  3.     Copyright (C) 1998  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.     11900 Metric Blvd #J-181
  21.     Austin Tx 78758-3117
  22. */
  23. #include "winthr.hpp"
  24.  
  25. #include <icritsec.hpp>
  26.  
  27. Boolean WindowThread::ICom::command( ICommandEvent& event )
  28. {
  29.  
  30.      // if the event id matches
  31.      if  ( ( event.commandId() == win_thread.eventid ) &&
  32.            ( event.controlWindow() == &win_thread.window  ) )
  33.      {
  34.         // have we been notified??
  35.         Boolean notified;
  36.         {
  37.           ICritSec lock;                   // lock befor checking notifing
  38.           notified = win_thread.notifing;  // we are being notified.
  39.  
  40.           win_thread.notifing = false;     // have been notified, no more.
  41.  
  42.         };
  43.         // if this thread is / has beeen notified.
  44.         if (notified)
  45.         {
  46.  
  47.           // call the finish code.
  48.           win_thread.finish() ;    // finish processing
  49.  
  50.          };
  51.      };
  52.      return false;
  53. };
  54.  
  55. // This thread code runs the window thread run code.
  56. void WindowThread::WinThrFn::run ()
  57. {
  58.      wt.run();
  59. };
  60.       // constructor remembers IWindow and eveint id #
  61. WindowThread::WindowThread(IWindow& window,const long eventid) :
  62.      eventid(eventid), window(window), thread_hand( *this), notifing(false)
  63. {
  64.  
  65. };
  66. // start thread user call.
  67. void WindowThread::win_th_start( Boolean auto_init )
  68. {
  69.     // first call begin on current thread.
  70.     begin();
  71.  
  72.  
  73.     // run thread to run thread code.
  74.     IThread doit( new WinThrFn(*this) , auto_init );
  75.     doit.adjustPriority(-17);
  76. };
  77. void WindowThread::run()
  78. {
  79.  
  80.     // call the thread code.
  81.     thread();
  82.  
  83.     // we are now notifing the original thread thru a command event.
  84.     {
  85.       ICritSec lock;
  86.       notifing = true;
  87.     };
  88.  
  89.     // post to declare completion.
  90.     window.postEvent( IWindow::command, eventid );
  91. };
  92.