Changeset 10269 for trunk/src


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

Location:
trunk/src/winmm
Files:
5 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//******************************************************************************
  • trunk/src/winmm/os2timer.h

    r9901 r10269  
    1 /* $Id: os2timer.h,v 1.12 2003-03-05 14:48:45 sandervl Exp $ */
     1/* $Id: os2timer.h,v 1.13 2003-10-13 09:18:37 sandervl Exp $ */
    22
    33#ifndef __OS2TIMER_H__
     
    4040 ****************************************************************************/
    4141
    42 #if 0
    43 typedef struct _MMTIMEREVENT
    44 {
    45   struct _MMTIMEREVENT* prev;
    46   struct _MMTIMEREVENT* next;
    47 
    48   DWORD           id;                    // event id
    49   DWORD           timeScheduled;         // system time to fire event
    50   DWORD           timePeriod;            // period if periodic event
    51   TID             tidCaller;             // thread ID of caller thread
    52   DWORD           dwUser;                // user supplied value
    53   LPTIMERCALLBACK lpCallback;            // address to call
    54   DWORD           dwFlags;               // event flags
    55 } MMTIMEREVENT, *PMMTIMEREVENT, *LPTIMEREVENT;
    56 #endif
    57 
    5842/*
    5943  addEvent
     
    7559    static BOOL leaveResolutionScope(int dwPeriod); // release resolution request
    7660    static int  queryCurrentResolution();           // query maximum resolution
    77 
     61   
    7862    // public variables
    7963    int dwPeriod;
     
    10791        void          KillTimer();
    10892
    109 
    11093        DWORD         getTimerID()         { return timerID; };
    11194        void          setTimerID(DWORD id) { timerID = id; };
     95
     96#ifdef DEBUG
     97        LONG          addRef();
     98#else
     99        LONG          addRef()         { return InterlockedIncrement(&refCount); };
     100#endif
     101        LONG          getRefCount()    { return refCount; };
     102        LONG          release();
    112103
    113104protected:
     
    130121                Stopped
    131122        };
     123
     124        LONG           refCount;
     125
    132126        static  int    timerPeriod;
    133127
  • trunk/src/winmm/time.cpp

    r9901 r10269  
    1 /* $Id: time.cpp,v 1.17 2003-03-05 14:48:45 sandervl Exp $ */
     1/* $Id: time.cpp,v 1.18 2003-10-13 09:18:38 sandervl Exp $ */
    22
    33/*
     
    145145  }
    146146  HMHandleFree(IDEvent);
    147   // return OS2Timer::killEvent(UINT IDEvent)
    148 
    149   delete os2timer;
     147
     148  os2timer->KillTimer();
     149  os2timer->release();
    150150  return TIMERR_NOERROR;
    151151}
     
    205205  if(HMHandleAllocate(&timerID, (ULONG)timer) != NO_ERROR) {
    206206      dprintf(("HMHandleAllocate failed!!"));
    207       delete timer;
     207      timer->release();
    208208      return 0;
    209209  }
     
    213213  {
    214214    dprintf(("WINMM:timeSetEvent: couldn't start timer!\n"));
    215     delete(timer);
     215    timer->release();
    216216    return(0);
    217217  }
  • trunk/src/winmm/waveinoutbase.cpp

    r9902 r10269  
    1 /* $Id: waveinoutbase.cpp,v 1.6 2003-03-05 14:49:04 sandervl Exp $ */
     1/* $Id: waveinoutbase.cpp,v 1.7 2003-10-13 09:18:38 sandervl Exp $ */
    22
    33/*
     
    100100void WaveInOut::callback(UINT uMessage, DWORD dw1, DWORD dw2)
    101101{
    102     dprintf(("WINMM:WaveInOut::callback type %x (HDRVR h=%08xh, UINT uMessage=%08xh, DWORD dwUser=%08xh, DWORD dw1=%08xh, DWORD dw2=%08xh)\n",
    103              fdwOpen, this, uMessage, dwInstance, dw1, dw2));
     102    dprintf(("WINMM:WaveInOut::callback type %x, callback 0x%x (HDRVR h=%08xh, UINT uMessage=%08xh, DWORD dwUser=%08xh, DWORD dw1=%08xh, DWORD dw2=%08xh)",
     103             fdwOpen, dwCallback, this, uMessage, dwInstance, dw1, dw2));
    104104
    105105    switch(fdwOpen & CALLBACK_TYPEMASK) {
     
    118118        LPDRVCALLBACK mthdCallback = (LPDRVCALLBACK)dwCallback;
    119119
    120         selCallback = GetProcessTIBSel();
     120        if(selTIB == SELECTOR_OS2_FS) {
     121             selCallback = GetProcessTIBSel();
     122        }
     123        else selCallback = selTIB;
    121124
    122125        //TODO: may not be very safe. perhaps we should allocate a new TIB for the DART thread or let another thread do the actual callback
     
    125128            SetFS(selCallback);      // switch to callback win32 tib selector (stored in WaveInOutOpen)
    126129
    127             //@@@PH 1999/12/28 Shockwave Flashes seem to make assumptions on a
     130            //@@@PH 1999/12/28 Shockwave Flash seem to make assumptions on a
    128131            // specific stack layout. Do we have the correct calling convention here?
    129132            mthdCallback((HDRVR)this, uMessage, dwInstance, dw1, dw2);
  • trunk/src/winmm/waveoutdart.cpp

    r9982 r10269  
    1 /* $Id: waveoutdart.cpp,v 1.22 2003-04-03 14:04:50 sandervl Exp $ */
     1/* $Id: waveoutdart.cpp,v 1.23 2003-10-13 09:18:38 sandervl Exp $ */
    22
    33/*
Note: See TracChangeset for help on using the changeset viewer.