Changeset 4479


Ignore:
Timestamp:
08/04/04 16:30:15 (20 years ago)
Author:
merck
Message:
MMerck: Added some code to synchronize the shutdown in a multithreaded
environment.
Location:
trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/amcframegrabber.cpp

    r3401 r4479  
    77{
    88        m_pMutex = new QMutex();
     9  m_zActive = false;
    910
    1011        m_iOffset = 0;
     
    8990AMCFrameGrabber::~AMCFrameGrabber()
    9091{
     92        delete m_pMutex;
    9193        //closing the device and freeing allocated memory.
    9294        close(m_iVid);
     
    100102int AMCFrameGrabber::grabFrame(u_char *data)
    101103{
     104        m_pMutex->lock();
     105        m_zActive = true;
     106        m_pMutex->unlock();
     107
    102108  fd_set rfds;
    103109  FD_ZERO(&rfds);
     
    107113  tv.tv_usec = 1000;
    108114  int retval = select(m_iVid+1, &rfds, NULL, NULL, &tv);
    109   if( ! retval )
    110     qDebug("Timed out waiting for frame");
     115//  if( ! retval )
     116//    qDebug("Timed out waiting for frame");
    111117
    112118  int n;
     
    115121  //one can do a tricky thing with pointers.
    116122   
     123        m_pMutex->lock();
     124        m_zActive = false;
     125        m_pMutex->unlock();
     126
    117127        if (n < 0)
    118128        {
     
    277287        return stCtrl.value;
    278288}
     289
     290/**
     291 * If we are still grabbing a video frame, wait until we are done.
     292 * In case we are active in grabbing a frame we sleep for 20ms (should be
     293 * enough time to grab an NTSC frame) to unload the system.
     294 */
     295void AMCFrameGrabber::waitTillInactive()
     296{
     297        for(;;)
     298        {
     299                m_pMutex->lock();
     300                if( ! m_zActive )
     301                {
     302                        m_pMutex->unlock();
     303                        return;
     304                }
     305                m_pMutex->unlock();
     306                usleep(20000);
     307        }
     308  return;
     309}
  • trunk/MagicSoft/AMC/activemirrorcontrol/activemirrorcontrol/amcframegrabber.h

    r3401 r4479  
    7878        /** */
    7979        virtual QMutex* getMutex() { return( m_pMutex ); };
     80  /** No descriptions */
     81  void waitTillInactive();
    8082
    8183protected: // Protected methods
     
    125127        struct v4l2_standard            m_stStdNTSC;
    126128        QMutex*                                                                 m_pMutex;
     129        bool                                                                            m_zActive;
    127130};
    128131
Note: See TracChangeset for help on using the changeset viewer.