File:  [OS/2 SDKs] / os2sdk / demos / examples / timer / timer.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:26:09 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: os2sdk-1988, HEAD
Microsoft OS/2 SDK 03-01-1988

/* This example illustrates the use of the following MS OS/2 functions:
 *	DosTimerStart, DosTimerAsync, DosTimerStop, DosSleep
 *
 * Created by Microsoft Corp. 1986
 */

#define INCL_DOSPROCESS
#define INCL_DOSDATETIME
#define INCL_DOSSEMAPHORES

#include <os2def.h>
#include <bsedos.h>

#define SEMNAME	"\\SEM\\SOMESEM"  /* name of semaphore */
#define TIMERINTERVAL 1000L	/* timer interval */
#define ASYNCINTERVAL 2000	/* asynchronous timer interval */
#define NOTIMEOUT -1		/* no timeout */
#define BEEPFREQUENCY 400	/* frequency parameter to DosBeep */
#define BEEPDURATION  50	/* duration parameter to DosBeep */

main ()
{
	HSEM   SemHandle;	  /* storage for semaphore handle */
	HTIMER	  TimerHandle;	  /* handle returned by DosTimerStart*/

	/* create a system semaphore */
	DosCreateSem (CSEM_PUBLIC, &SemHandle, SEMNAME);

	/*
	 * DosTimerStart/Stop - these functions provide a repetitive
	 * asynchronous timer which clear a semaphore at a specified interval.
	 */

	DosSemSet (SemHandle);		/* set the system semaphore */

	/* set the interval timer */
	DosTimerStart (TIMERINTERVAL, SemHandle, &TimerHandle);

	/* normally, application would do some work in here */

	DosSemWait (SemHandle, (long) NOTIMEOUT); /* wait on the semaphore */
	DosBeep (BEEPFREQUENCY, BEEPDURATION);	  /* beep when done */
	DosTimerStop (TimerHandle);		  /* stop the interval timer */

	/*
	 * DosTimerAsync example. This function provides a one-shot
	 * asynchronous timer which clears a specified semaphore after
	 * a specified time delay.
	 */

	DosSemSet (SemHandle);		/* set the system semaphore */

	/* start the asynchronous timer */
	DosTimerAsync ((long) ASYNCINTERVAL, SemHandle, &TimerHandle);

	/* normally, application would do some work in here */

	DosSemWait (SemHandle,	(long) NOTIMEOUT); /* wait on the semaphore */
	DosBeep (BEEPFREQUENCY, BEEPDURATION);	  /* beep when done */

	/*
	 * DosTimerStop is used to cancel either type of timer. After using
	 * this function you must put the semaphore back into a known state
	 * if you need to use it again. Example of cancelling a timer:
	 */

	DosSemSet (SemHandle);		/* set the system semaphore */

	/* start the asynchronous timer (specify a long time) */
	DosTimerAsync ((long) (10*ASYNCINTERVAL), SemHandle, &TimerHandle);

	DosTimerStop (TimerHandle);	/* stop the asynchronous timer */
	DosSemClear (SemHandle);	/* clear the system semaphore */
	DosCloseSem (SemHandle);	/* close the system semaphore */

	/*
	 * DosSleep - simple synchronous suspend for specified interval.
	 */
	DosSleep(TIMERINTERVAL);
	DosBeep (BEEPFREQUENCY, BEEPDURATION);	  /* beep when done */
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.