Changeset 756 for trunk/src


Ignore:
Timestamp:
Aug 31, 1999, 5:06:17 PM (26 years ago)
Author:
phaller
Message:

Add: added timeBeginPeriod and timeEndPeriod

Location:
trunk/src/winmm
Files:
2 added
3 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/winmm/makefile

    r604 r756  
    1 # $Id: makefile,v 1.8 1999-08-21 12:29:32 sandervl Exp $
     1# $Id: makefile,v 1.9 1999-08-31 15:04:10 phaller Exp $
    22
    33#
     
    2121TARGET = winmm
    2222
    23 OBJS =  winmm.obj os2timer.obj waveout.obj dwaveout.obj timegettime.obj \
     23OBJS =  os2timer.obj waveout.obj dwaveout.obj time.obj \
    2424        wavein.obj aux.obj auxos2.obj mixer.obj \
    2525        midi.obj irtmidi.obj midistrm.obj initterm.obj mci.obj joy.obj \
     
    4646
    4747driver.obj:     driver.cpp
    48 winmm.obj:      winmm.cpp
    49 os2timer.obj:   os2timer.h wintimer.h
     48os2timer.obj:   os2timer.cpp os2timer.h time.h
    5049waveout.obj:    waveout.cpp  dwaveout.h
    5150wavein.obj:     wavein.cpp
     
    6059irtmidi.obj:    irtmidi.cpp irtmidi.hpp
    6160dwaveout.obj:   dwaveout.cpp dwaveout.h $(PDWIN32_INCLUDE)\vmutex.h
    62 timegettime.obj: timegettime.cpp
     61time.obj:       time.cpp
    6362initterm.obj:   initterm.cpp aux.h
    6463playsound.obj:  playsound.cpp
  • trunk/src/winmm/os2timer.cpp

    r668 r756  
    1 /* $Id: os2timer.cpp,v 1.7 1999-08-24 21:21:11 phaller Exp $ */
     1/* $Id: os2timer.cpp,v 1.8 1999-08-31 15:04:10 phaller Exp $ */
    22
    33/*
     
    55 *
    66 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
     7 * Copyright 1999 Patrick Haller     (phaller@gmx.net)
    78 *
    89 * Project Odin Software License can be found in LICENSE.TXT
     
    2021#include <os2wrap.h>      //Odin32 OS/2 api wrappers
    2122#include <process.h>
    22 #include "win32type.h"
    23 #include "wintimer.h"
     23#include <win32type.h>
    2424#include <wprocess.h>
     25#include <misc.h>
     26
     27#include "time.h"
    2528#include "os2timer.h"
    26 #include "misc.h"
    2729
    2830
     
    3234 ****************************************************************************/
    3335
    34 #if 0
    35 //@@@PH started new implementation
    36 typedef struct _MMTIMEREVENT
    37 {
    38   struct _MMTIMEREVENT* prev;
    39   struct _MMTIMEREVENT* next;
    40 
    41   DWORD           id;                    // event id
    42   DWORD           timeScheduled;         // system time to fire event
    43   DWORD           timePeriod;            // period if periodic event
    44   TID             tidCaller;             // thread ID of caller thread
    45   DWORD           dwUser;                // user supplied value
    46   LPTIMERCALLBACK lpCallback;            // address to call
    47   DWORD           dwFlags;               // event flags
    48 } MMTIMEREVENT, *PMMTIMEREVENT, *LPTIMEREVENT;
    49 
    50 typedef struct _MMTIMERRESOLUTION
    51 {
    52   struct _MMTIMERRESOLUTION* prev;
    53   struct _MMTIMERRESOLUTION* next;
    54 
    55   DWORD  dwResolution;                   // requested resolution for block
    56 } MMTIMERRESOLUTION, *PMMTIMERRESOLUTION, *LPMMTIMERRESOLUTION;
    57 
    58 /*
    59   enterResolutionScope
    60   leaveResolutionScope
    61 
    62   addEvent
    63   removeEvent
    64   rescheduleEvent
    65   callbackCaller
    66 */
    67 #endif
    6836
    6937/****************************************************************************
     
    7644
    7745
     46/****************************************************************************
     47 * Class: OS2TimerResolution                                                *
     48 ****************************************************************************/
     49
     50
     51/*****************************************************************************
     52 * Name      : OS2TimerResolution::OS2TimerResolution
     53 * Purpose   : create a new entry in the resolution stack
     54 * Parameters: -
     55 * Variables :
     56 * Result    :
     57 * Remark    :
     58 * Status    : UNTESTED STUB
     59 *
     60 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     61 *****************************************************************************/
     62
     63OS2TimerResolution::OS2TimerResolution(int dwPeriod)
     64{
     65  // add to linked list
     66  OS2TimerResolution *timeRes = OS2TimerResolution::sTimerResolutions;
     67
     68  if(timeRes != NULL)
     69  {
     70    while(timeRes->next != NULL)
     71    {
     72      timeRes = timeRes->next;
     73    }
     74    timeRes->next = this;
     75  }
     76  else
     77    OS2TimerResolution::sTimerResolutions = this;
     78
     79  this->dwPeriod = dwPeriod;
     80}
     81
     82
     83/*****************************************************************************
     84 * Name      : OS2TimerResolution::~OS2TimerResolution
     85 * Purpose   : remove entry from the linked list
     86 * Parameters:
     87 * Variables :
     88 * Result    :
     89 * Remark    :
     90 * Status    : UNTESTED STUB
     91 *
     92 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     93 *****************************************************************************/
     94
     95OS2TimerResolution::~OS2TimerResolution()
     96{
     97  // remove from linked list
     98  OS2TimerResolution *timeRes = OS2TimerResolution::sTimerResolutions;
     99
     100  // leaveResolutionScope() if still entered???
     101
     102  if(timeRes != this)
     103  {
     104    while(timeRes->next != this)
     105    {
     106      timeRes = timeRes->next;
     107    }
     108    timeRes->next = this->next;
     109  }
     110  else
     111    OS2TimerResolution::sTimerResolutions = timeRes->next;
     112}
     113
     114
     115/*****************************************************************************
     116 * Name      : OS2TimerResolution::enterResolutionScope
     117 * Purpose   : set the currently requested timer resolution for this entry
     118 * Parameters:
     119 * Variables :
     120 * Result    :
     121 * Remark    :
     122 * Status    : UNTESTED STUB
     123 *
     124 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     125 *****************************************************************************/
     126
     127BOOL OS2TimerResolution::enterResolutionScope(int dwPeriod)
     128{
     129  OS2TimerResolution* timeRes = new OS2TimerResolution(dwPeriod);
     130  if (timeRes != NULL)
     131    return TRUE;
     132  else
     133    return FALSE;
     134}
     135
     136
     137/*****************************************************************************
     138 * Name      : OS2TimerResolution::leaveResolutionScope
     139 * Purpose   : remove specified entry from the list if periods match
     140 * Parameters: int dwPeriod
     141 * Variables :
     142 * Result    : TRUE or FALSE
     143 * Remark    :
     144 * Status    : UNTESTED STUB
     145 *
     146 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     147 *****************************************************************************/
     148
     149BOOL OS2TimerResolution::leaveResolutionScope(int dwPeriod)
     150{
     151  OS2TimerResolution* timeRes = OS2TimerResolution::sTimerResolutions;
     152
     153  if (timeRes != NULL)
     154  {
     155    for(;                           // walk to the end of the list
     156        timeRes->next != NULL;
     157        timeRes = timeRes->next)
     158      ;
     159
     160    if (timeRes->dwPeriod == dwPeriod) // do the requested period match?
     161    {
     162      delete timeRes;              // so delete that object
     163      return TRUE;                 // OK, can remove the entry
     164    }
     165 }
     166 return FALSE;                     // nope, mismatch !
     167}
     168
     169
     170/*****************************************************************************
     171 * Name      : OS2TimerResolution::queryCurrentResolution
     172 * Purpose   : determine the maximum resolution currently requested
     173 * Parameters:
     174 * Variables :
     175 * Result    :
     176 * Remark    :
     177 * Status    : UNTESTED STUB
     178 *
     179 * Author    : Patrick Haller [Tue, 1998/06/16 23:00]
     180 *****************************************************************************/
     181
     182int OS2TimerResolution::queryCurrentResolution()
     183{
     184  OS2TimerResolution *timeRes = OS2TimerResolution::sTimerResolutions;
     185  int                iMax = -1;
     186
     187  if (timeRes != NULL)              // do we have an entry yet?
     188    for (;                          // walk the linked list
     189         timeRes->next != NULL;
     190         timeRes = timeRes->next)
     191    {
     192      if (timeRes->dwPeriod < iMax) // determine minimum time period
     193        iMax = timeRes->dwPeriod;
     194    }
     195
     196  return iMax;
     197}
     198
     199
     200
     201
     202
    78203/******************************************************************************/
    79204/******************************************************************************/
    80205OS2Timer::OS2Timer() : TimerSem(0), TimerHandle(0), TimerThreadID(0),
    81                        clientCallback(NULL), TimerStatus(Stopped), fFatal(FALSE)
     206                  clientCallback(NULL), TimerStatus(Stopped), fFatal(FALSE)
    82207{
    83208 OS2Timer *timer = OS2Timer::timers;
    84209
    85   if(timer != NULL) {
    86     while(timer->next != NULL) {
    87         timer = timer->next;
     210  if(timer != NULL)
     211  {
     212    while(timer->next != NULL)
     213    {
     214      timer = timer->next;
    88215    }
    89216    timer->next = this;
    90217  }
    91   else  timers      = this;
     218  else
     219    timers = this;
    92220
    93221  TimerThreadID = _beginthread(TimerHlpHandler, NULL, 0x4000, (void *)this);
    94   DosSleep(100);
     222  //@@@PH: why the wait? DosSleep(100);
    95223}
    96224/******************************************************************************/
     
    98226OS2Timer::~OS2Timer()
    99227{
    100  OS2Timer *timer = OS2Timer::timers;
     228  OS2Timer *timer = OS2Timer::timers;
    101229
    102230  KillTimer();
    103231
    104   if(timer != this) {
    105     while(timer->next != this) {
    106         timer = timer->next;
     232  if(timer != this)
     233  {
     234    while(timer->next != this)
     235    {
     236      timer = timer->next;
    107237    }
    108238    timer->next = this->next;
    109239  }
    110   else  timers = timer->next;
    111 }
    112 /******************************************************************************/
    113 /******************************************************************************/
    114 BOOL OS2Timer::StartTimer(int period, int resolution, LPTIMECALLBACK lptc,
    115                           int dwUser, int fuEvent)
    116 {
    117  APIRET rc;
    118 
    119   if(TimerThreadID == -1) {
     240  else
     241    timers = timer->next;
     242}
     243/******************************************************************************/
     244/******************************************************************************/
     245BOOL OS2Timer::StartTimer(int period,
     246                          int resolution,
     247                          LPTIMECALLBACK lptc,
     248                          int dwUser,
     249                          int fuEvent)
     250{
     251  APIRET rc;
     252
     253  if(TimerThreadID == -1)
     254  {
    120255    return(FALSE);
    121256  }
    122   if(TimerStatus == Stopped) {
     257
     258  if(TimerStatus == Stopped)
     259  {
    123260    clientCallback = lptc;
    124261    userData       = dwUser;
    125         if(fuEvent == TIME_PERIODIC)
    126             rc = DosStartTimer(period, (HSEM)TimerSem, &TimerHandle);
    127     else    rc = DosAsyncTimer(period, (HSEM)TimerSem, &TimerHandle);
    128     if(rc) {
     262
     263    if(fuEvent == TIME_PERIODIC)
     264      rc = DosStartTimer(period, (HSEM)TimerSem, &TimerHandle);
     265    else
     266      rc = DosAsyncTimer(period, (HSEM)TimerSem, &TimerHandle);
     267
     268    if(rc)
     269    {
     270
    129271#ifdef DEBUG
    130         if(fuEvent == TIME_PERIODIC)
    131             WriteLog("DosStartTimer failed %d\n", rc);
    132         else    WriteLog("DosAsyncTimer failed %d\n", rc);
     272      if(fuEvent == TIME_PERIODIC)
     273        WriteLog("DosStartTimer failed %d\n", rc);
     274      else
     275        WriteLog("DosAsyncTimer failed %d\n", rc);
    133276#endif
    134         return(FALSE);
    135     }
    136         TimerStatus = Running;
    137   }
    138   else  return(FALSE);  //already running (must use timeKillEvent first)
     277
     278      return(FALSE);
     279    }
     280
     281    TimerStatus = Running;
     282  }
     283  else
     284    return(FALSE);  //already running (must use timeKillEvent first)
     285
    139286  return(TRUE);
    140287}
     
    143290void OS2Timer::StopTimer()
    144291{
    145   if(TimerStatus == Running) {
    146         DosStopTimer(TimerHandle);
    147         TimerStatus = Stopped;
     292  if(TimerStatus == Running)
     293  {
     294    DosStopTimer(TimerHandle);
     295    TimerStatus = Stopped;
    148296  }
    149297}
     
    154302  fFatal = TRUE;
    155303  DosStopTimer(TimerHandle);
    156   if(DosPostEventSem(TimerSem)) {//something went wrong
    157         DosKillThread(TimerThreadID);
    158         DosCloseEventSem(TimerSem);
     304  if(DosPostEventSem(TimerSem))
     305  {  //something went wrong
     306     DosKillThread(TimerThreadID);
     307     DosCloseEventSem(TimerSem);
    159308  }
    160309  TimerStatus = InActive;
     
    192341        // @@@PH: we're calling the client with PRTYC_TIMECRITICAL !!!
    193342        //        It'd be much nicer to call with original priority!
    194         // @@@PH: plus the original thread is supposed to stop while the
    195         //        time event is scheduled (DosSuspendThread()) ? It's
    196         //        much like raising a signal (SIGALARM)
    197343
    198344        selTIB = SetWin32TIB();
     
    211357  _endthread();
    212358}
    213 //******************************************************************************
    214 //******************************************************************************
    215 OS2Timer *OS2Timer::timers      = NULL;
    216 int       OS2Timer::timerPeriod = 0;
    217 
     359
     360
     361//******************************************************************************
     362//******************************************************************************
     363OS2TimerResolution *OS2TimerResolution::sTimerResolutions = NULL;
     364OS2Timer           *OS2Timer::timers                      = NULL;
     365int                 OS2Timer::timerPeriod                 = 0;
     366
  • trunk/src/winmm/os2timer.h

    r95 r756  
    1 /* $Id: os2timer.h,v 1.3 1999-06-10 16:24:34 phaller Exp $ */
     1/* $Id: os2timer.h,v 1.4 1999-08-31 15:04:11 phaller Exp $ */
    22
    33#ifndef __OS2TIMER_H__
     
    77 *
    88 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
     9 * Copyright 1999 Patrick Haller     (phaller@gmx.net)
    910 *
    1011 * Project Odin Software License can be found in LICENSE.TXT
     
    1617 #define HTIMER int
    1718#endif
     19
     20
     21/****************************************************************************
     22 * Structures                                                               *
     23 ****************************************************************************/
     24
     25#if 0
     26typedef struct _MMTIMEREVENT
     27{
     28  struct _MMTIMEREVENT* prev;
     29  struct _MMTIMEREVENT* next;
     30
     31  DWORD           id;                    // event id
     32  DWORD           timeScheduled;         // system time to fire event
     33  DWORD           timePeriod;            // period if periodic event
     34  TID             tidCaller;             // thread ID of caller thread
     35  DWORD           dwUser;                // user supplied value
     36  LPTIMERCALLBACK lpCallback;            // address to call
     37  DWORD           dwFlags;               // event flags
     38} MMTIMEREVENT, *PMMTIMEREVENT, *LPTIMEREVENT;
     39#endif
     40
     41/*
     42  addEvent
     43  removeEvent
     44  rescheduleEvent
     45  callbackCaller
     46*/
     47
     48
     49/****************************************************************************
     50 * Class: OS2TimerResolution                                                *
     51 ****************************************************************************/
     52
     53class OS2TimerResolution
     54{
     55  public:
     56    // public entries
     57    static BOOL enterResolutionScope(int dwPeriod); // request timer resolution
     58    static BOOL leaveResolutionScope(int dwPeriod); // release resolution request
     59    static int  queryCurrentResolution();           // query maximum resolution
     60
     61    // public variables
     62    int dwPeriod;
     63
     64  protected:
     65    // constructors and destructors
     66    OS2TimerResolution(void);
     67    OS2TimerResolution(int dwPeriod);
     68    ~OS2TimerResolution();
     69
     70    // simple linked list
     71    static OS2TimerResolution* sTimerResolutions; // list of resolution scoped
     72           OS2TimerResolution* next;              // link to next entry
     73};
     74
     75
     76/****************************************************************************
     77 * Class: OS2Timer                                                          *
     78 ****************************************************************************/
    1879
    1980class OS2Timer
Note: See TracChangeset for help on using the changeset viewer.