Ignore:
Timestamp:
Oct 13, 2003, 11:18:38 AM (22 years ago)
Author:
sandervl
Message:

Make sure the timer object is not deleted inside the timer callback handler

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/winmm/os2timer.cpp

    r9916 r10269  
    1 /* $Id: os2timer.cpp,v 1.21 2003-03-06 15:42:33 sandervl Exp $ */
     1/* $Id: os2timer.cpp,v 1.22 2003-10-13 09:18:37 sandervl Exp $ */
    22
    33/*
     
    239239OS2Timer::OS2Timer() : TimerSem(0), TimerHandle(0), hTimerThread(0),
    240240                  clientCallback(NULL), TimerStatus(Stopped), fFatal(FALSE),
    241                   next(NULL), timerID(0)
     241                  next(NULL), timerID(0), refCount(0)
    242242{
    243243  dprintf(("WINMM:OS2Timer: OS2Timer::OS2Timer(%08xh)\n",
     
    266266    return; // terminate thread
    267267  }
    268  
    269  
    270   //hTimerThread = _beginthread(TimerHlpHandler, NULL, 0x4000, (void *)this);
     268 
     269  //increase reference count for creation
     270  addRef();
     271
     272  //increase reference count since the thread will access the object
     273  addRef(); 
    271274  hTimerThread = CreateThread(NULL,
    272275                              0x4000,
     
    392395  TimerStatus = InActive;
    393396}
     397//******************************************************************************
     398//******************************************************************************
     399#ifdef DEBUG
     400LONG OS2Timer::addRef()
     401{
     402////  dprintf2(("addRef %x -> refcount %x", this, refCount+1));
     403    return InterlockedIncrement(&refCount);
     404};
     405#endif
     406/******************************************************************************/
     407//******************************************************************************
     408LONG OS2Timer::release()
     409{
     410#ifdef DEBUG
     411  if(refCount-1 < 0) {
     412      DebugInt3();
     413  }
     414#endif
     415  if(InterlockedDecrement(&refCount) == 0) {
     416      dprintf2(("marked for deletion -> delete now"));
     417      delete this;
     418      return 0;
     419  }
     420  return refCount;
     421}
    394422/******************************************************************************/
    395423//******************************************************************************
     
    414442            clientCallback));
    415443   
    416     DosWaitEventSem(TimerSem, SEM_INDEFINITE_WAIT);
    417     DosResetEventSem(TimerSem, &Count);
     444    rc = DosWaitEventSem(TimerSem, SEM_INDEFINITE_WAIT);
     445    if(rc) {
     446        dprintf(("DosWaitEventSem failed with %d", rc));
     447        DebugInt3();
     448    }
     449    rc = DosResetEventSem(TimerSem, &Count);
     450    if(rc) {
     451        dprintf(("DosResetEventSem failed with %d", rc));
     452        DebugInt3();
     453    }
    418454    if(!fFatal)
    419455    {
     
    434470              if (clientCallback != NULL)
    435471              {
    436                 selTIB = SetWin32TIB();
    437                 clientCallback((UINT)timerID, 0, userData, 0, 0);
    438                 SetFS(selTIB);
     472                  clientCallback((UINT)timerID, 0, userData, 0, 0);
    439473              }
    440474              break;
     
    462496 
    463497  DosCloseEventSem(TimerSem);
     498
     499  //release object
     500  release();
    464501 
    465502  // mark this thread as terminated
     
    474511  return 0;
    475512}
    476 
    477 
    478513//******************************************************************************
    479514//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.