|
|
1.1.1.2 ! root 1: /* This example illustrates the use of the following MS OS/2 functions: ! 2: * DosTimerStart, DosTimerAsync, DosTimerStop, DosSleep 1.1 root 3: * 1.1.1.2 ! root 4: * Created by Microsoft Corp. 1986 1.1 root 5: */ 6: 1.1.1.2 ! root 7: #define INCL_DOSPROCESS ! 8: #define INCL_DOSDATETIME ! 9: #define INCL_DOSSEMAPHORES ! 10: ! 11: #include <os2def.h> ! 12: #include <bsedos.h> 1.1 root 13: 14: #define SEMNAME "\\SEM\\SOMESEM" /* name of semaphore */ 15: #define TIMERINTERVAL 1000L /* timer interval */ 16: #define ASYNCINTERVAL 2000 /* asynchronous timer interval */ 17: #define NOTIMEOUT -1 /* no timeout */ 1.1.1.2 ! root 18: #define BEEPFREQUENCY 400 /* frequency parameter to DosBeep */ ! 19: #define BEEPDURATION 50 /* duration parameter to DosBeep */ 1.1 root 20: 21: main () 22: { 1.1.1.2 ! root 23: HSEM SemHandle; /* storage for semaphore handle */ ! 24: HTIMER TimerHandle; /* handle returned by DosTimerStart*/ 1.1 root 25: 26: /* create a system semaphore */ 1.1.1.2 ! root 27: DosCreateSem (CSEM_PUBLIC, &SemHandle, SEMNAME); 1.1 root 28: 29: /* 1.1.1.2 ! root 30: * DosTimerStart/Stop - these functions provide a repetitive 1.1 root 31: * asynchronous timer which clear a semaphore at a specified interval. 32: */ 33: 1.1.1.2 ! root 34: DosSemSet (SemHandle); /* set the system semaphore */ 1.1 root 35: 36: /* set the interval timer */ 1.1.1.2 ! root 37: DosTimerStart (TIMERINTERVAL, SemHandle, &TimerHandle); 1.1 root 38: 39: /* normally, application would do some work in here */ 40: 1.1.1.2 ! root 41: DosSemWait (SemHandle, (long) NOTIMEOUT); /* wait on the semaphore */ ! 42: DosBeep (BEEPFREQUENCY, BEEPDURATION); /* beep when done */ ! 43: DosTimerStop (TimerHandle); /* stop the interval timer */ 1.1 root 44: 45: /* 1.1.1.2 ! root 46: * DosTimerAsync example. This function provides a one-shot 1.1 root 47: * asynchronous timer which clears a specified semaphore after 48: * a specified time delay. 49: */ 50: 1.1.1.2 ! root 51: DosSemSet (SemHandle); /* set the system semaphore */ 1.1 root 52: 53: /* start the asynchronous timer */ 1.1.1.2 ! root 54: DosTimerAsync ((long) ASYNCINTERVAL, SemHandle, &TimerHandle); 1.1 root 55: 56: /* normally, application would do some work in here */ 57: 1.1.1.2 ! root 58: DosSemWait (SemHandle, (long) NOTIMEOUT); /* wait on the semaphore */ ! 59: DosBeep (BEEPFREQUENCY, BEEPDURATION); /* beep when done */ 1.1 root 60: 61: /* 1.1.1.2 ! root 62: * DosTimerStop is used to cancel either type of timer. After using 1.1 root 63: * this function you must put the semaphore back into a known state 64: * if you need to use it again. Example of cancelling a timer: 65: */ 66: 1.1.1.2 ! root 67: DosSemSet (SemHandle); /* set the system semaphore */ 1.1 root 68: 69: /* start the asynchronous timer (specify a long time) */ 1.1.1.2 ! root 70: DosTimerAsync ((long) (10*ASYNCINTERVAL), SemHandle, &TimerHandle); 1.1 root 71: 1.1.1.2 ! root 72: DosTimerStop (TimerHandle); /* stop the asynchronous timer */ ! 73: DosSemClear (SemHandle); /* clear the system semaphore */ ! 74: DosCloseSem (SemHandle); /* close the system semaphore */ 1.1 root 75: 76: /* 1.1.1.2 ! root 77: * DosSleep - simple synchronous suspend for specified interval. 1.1 root 78: */ 1.1.1.2 ! root 79: DosSleep(TIMERINTERVAL); ! 80: DosBeep (BEEPFREQUENCY, BEEPDURATION); /* beep when done */ 1.1 root 81: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.