From alsa-devel-owner@alsa.jcu.cz  Sun Feb 21 14:07:02 1999
Received: from post.mail.demon.net (finch-post-11.mail.demon.net [194.217.242.39])
	by marvin.jcu.cz (8.9.1a/8.9.1) with ESMTP id OAA12244
	for <alsa-devel@alsa.jcu.cz>; Sun, 21 Feb 1999 14:05:31 +0100
Received: from [212.228.182.246] (helo=ariel.sr.home)
	by post.mail.demon.net with esmtp (Exim 2.12 #1)
	id 10EYZZ-0001En-00
	for alsa-devel@alsa.jcu.cz; Sun, 21 Feb 1999 13:05:26 +0000
Received: (from steve@localhost)
	by ariel.sr.home (8.8.7/8.8.7) id NAA03165
	for alsa-devel@alsa.jcu.cz; Sun, 21 Feb 1999 13:03:24 GMT
Date: Sun, 21 Feb 1999 13:03:24 GMT
From: Steve Ratcliffe <steve@parabola.demon.co.uk>
Message-Id: <199902211303.NAA03165@ariel.sr.home>
To: alsa-devel@alsa.jcu.cz
Subject: Timers
Reply-To: alsa-devel@alsa.jcu.cz
Sender: alsa-devel-owner@alsa.jcu.cz
Precedence: list


A few questions about the timer code.

1. I'm not sure what global_timer_ticks is being used for in seq_timer.c.
It looks like it is being used for two different purposes, first as
a count of ticks to initialise the timer with on open and as a scaling
factor for resolution.  I don't understand the second use and suggest
the following patch:

--- kernel/seq/seq_timer.c.orig	Sun Feb 21 00:52:29 1999
+++ kernel/seq/seq_timer.c	Sun Feb 21 00:53:39 1999
@@ -104,7 +104,7 @@
 	queue_t *q;
 	timer_t *tmr;
 
-	resolution = snd_timer_resolution(timer) * global_timer_ticks;
+	resolution = snd_timer_resolution(timer);
 	period.tv_sec = 0;
 	period.tv_nsec = resolution % 1000000000;
 
@@ -312,7 +312,7 @@
 	snd_mutex_down_static(global_timer);
 	snd_iprintf(buffer, "Timer       : %s\n", global_timer ? global_timer->name : "None");
 	if (global_timer) {
-		resolution = snd_timer_resolution(global_timer) * global_timer_ticks;
+		resolution = snd_timer_resolution(global_timer);
 		snd_iprintf(buffer, "Period time : %d.%09d\n", resolution / 1000000000, resolution % 1000000000);
  	}
 	snd_mutex_up_static(global_timer);
 


2. Is the purpose of snd_timer_open to find a timer with a resolution
that is as good as or better than that requested?  If so a test is the
wrong way round.  The code should also use snd_timer_resolution() to cope
with the case that hw.c_resolution() is being used and not hw.resolution.

3. How should timers work that are not specific to an audio card?
Should they just pass in a NULL card_t when registering?  If so there
are a couple of places where timer->card should be tested before use.

--- kernel/timer.c.orig	Sat Feb 20 23:59:33 1999
+++ kernel/timer.c	Sun Feb 21 10:48:08 1999
@@ -45,7 +45,7 @@
 		if (timer == NULL)
 			continue;
 		if (!(timer->flags & SND_TIMER_FLG_USED) &&
-		    timer->hw.resolution <= resolution) {
+		    snd_timer_resolution(timer) >= resolution) {
 			if (timer->hw.open) {
 				if (!timer->hw.open(timer))
 					break;
@@ -78,7 +78,8 @@
 	timer->flags |= SND_TIMER_FLG_USED;
 	timer->owner = snd_malloc_strdup(owner);
 	MOD_INC_USE_COUNT;
-	timer->card->use_inc(timer->card);
+	if (timer->card)
+		timer->card->use_inc(timer->card);
 	snd_mutex_up_static(open);
 	return timer;
 }
@@ -95,7 +96,8 @@
 	timer->owner = NULL;
 	MOD_DEC_USE_COUNT;
 	snd_mutex_up_static(open);
-	timer->card->use_dec(timer->card);
+	if (timer->card)
+		timer->card->use_dec(timer->card);
 	return 0;
 }
 
..Steve

