Ignore:
Timestamp:
May 24, 2000, 3:56:25 AM (25 years ago)
Author:
phaller
Message:

Fix: WINMM: OS2Timer stuff

File:
1 edited

Legend:

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

    r2812 r3600  
    1 /* $Id: os2timer.cpp,v 1.14 2000-02-17 14:09:32 sandervl Exp $ */
     1/* $Id: os2timer.cpp,v 1.15 2000-05-24 01:56:25 phaller Exp $ */
    22
    33/*
     
    5151                               DWORD fdwCreate,
    5252                               LPDWORD lpIDThread);
     53 
     54  VOID WIN32API ExitThread(DWORD dwExitCode);
     55 
     56  BOOL WIN32API TerminateThread(HANDLE hThread,
     57                                DWORD dwExitCode);
     58 
     59  BOOL WIN32API SetEvent   (HANDLE hEvent);
     60   
     61  BOOL WIN32API PulseEvent (HANDLE hEvent);
     62   
    5363}
    5464
     
    238248/******************************************************************************/
    239249/******************************************************************************/
    240 OS2Timer::OS2Timer() : TimerSem(0), TimerHandle(0), TimerThreadID(0),
     250OS2Timer::OS2Timer() : TimerSem(0), TimerHandle(0), hTimerThread(0),
    241251                  clientCallback(NULL), TimerStatus(Stopped), fFatal(FALSE),
    242252                  next(NULL)
     
    257267  else
    258268    timers = this;
    259 
    260   //TimerThreadID = _beginthread(TimerHlpHandler, NULL, 0x4000, (void *)this);
     269 
     270  //hTimerThread = _beginthread(TimerHlpHandler, NULL, 0x4000, (void *)this);
    261271  hTimerThread = CreateThread(NULL,
    262272                              0x4000,
     
    266276                              &TimerThreadID);
    267277
    268 
    269278  //@@@PH: CreateThread() should be used instead
    270279  //@@@PH: logic sux ... waits for creation of semaphores
    271   DosSleep(100);
     280  DosSleep(10);
    272281}
    273282/******************************************************************************/
     
    310319
    311320  APIRET rc;
    312 
    313   if(TimerThreadID == -1)
     321 
     322  // has the thread been created properly?
     323  if(hTimerThread == NULLHANDLE)
    314324    return(FALSE);
    315325
    316326  if(TimerStatus == Stopped)
    317327  {
    318     clientCallback = lptc;
    319     userData       = dwUser;
    320 
    321     if(fuEvent == TIME_PERIODIC)
     328    clientCallback = lptc;    // callback data (id / addr)
     329    userData       = dwUser;  // user-supplied data
     330    dwFlags        = fuEvent; // type of timer / callback
     331
     332    if(fuEvent & TIME_PERIODIC)
    322333      rc = DosStartTimer(period, (HSEM)TimerSem, &TimerHandle);
    323334    else
     
    328339
    329340#ifdef DEBUG
    330       if(fuEvent == TIME_PERIODIC)
     341      if(fuEvent & TIME_PERIODIC)
    331342        WriteLog("DosStartTimer failed %d\n", rc);
    332343      else
     
    365376
    366377  fFatal = TRUE;
    367   DosStopTimer(TimerHandle);
     378 
     379  StopTimer();
     380 
    368381  if(DosPostEventSem(TimerSem))
    369   {  //something went wrong
    370      DosKillThread(TimerThreadID);
    371      DosCloseEventSem(TimerSem);
     382  { 
     383    //something went wrong, kill the thread
     384    TerminateThread(hTimerThread, -1);
    372385  }
    373386  TimerStatus = InActive;
     
    406419        // @@@PH: we're calling the client with PRTYC_TIMECRITICAL !!!
    407420        //        It'd be much nicer to call with original priority!
    408 
    409         selTIB = SetWin32TIB();
    410         clientCallback((UINT)this, 0, userData, 0, 0);
    411         SetFS(selTIB);
    412     }
    413   }
     421     
     422        // check timer running condition
     423        if (TimerStatus == Running)
     424        {
     425          // process the event
     426          switch (dwFlags & 0x0030)
     427          {
     428            case TIME_CALLBACK_FUNCTION:
     429              if (clientCallback != NULL)
     430              {
     431                selTIB = SetWin32TIB();
     432                clientCallback((UINT)this, 0, userData, 0, 0);
     433                SetFS(selTIB);
     434              }
     435              break;
     436           
     437            case TIME_CALLBACK_EVENT_SET:
     438              SetEvent( (HANDLE)clientCallback );
     439              break;
     440           
     441            case TIME_CALLBACK_EVENT_PULSE:
     442              PulseEvent( (HANDLE)clientCallback );
     443              break;
     444           
     445            default:
     446              dprintf(("WINMM: OS2Timer %08xh: unknown type for mmtime callback(%08xh)\n",
     447                       this,
     448                       dwFlags));
     449          }
     450        }
     451    }
     452  }
     453 
     454  // last message
     455  dprintf(("WINMM: OS2Timer: Timer thread terminating (%08xh)\n",
     456           this));
     457 
    414458  DosCloseEventSem(TimerSem);
     459 
     460  // mark this thread as terminated
     461  ExitThread(0);
    415462}
    416463//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.