All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Change the for loop to read blutooth clock in MCAP CSP
@ 2010-09-17  7:52 Santiago Carot-Nemesio
  2010-09-17 11:56 ` Elvis Pfützenreuter
  0 siblings, 1 reply; 3+ messages in thread
From: Santiago Carot-Nemesio @ 2010-09-17  7:52 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Santiago Carot-Nemesio

This is only a cosmetic change. Using a do..while loop
we avoid direct manipulation of counter loop variable
when error happens reading the BT clock.
---
 health/mcap_sync.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/health/mcap_sync.c b/health/mcap_sync.c
index bc1ffcd..78cb163 100644
--- a/health/mcap_sync.c
+++ b/health/mcap_sync.c
@@ -406,18 +406,18 @@ static void initialize_caps(struct mcap_mcl *mcl)
 
 	/* Do clock read a number of times and measure latency */
 	avg = 0;
-	for (i = 0; i < 20; ++i) {
+	i = 0;
+	do {
 		clock_gettime(CLK, &t1);
-		if (!read_btclock(mcl, &btclock, &btaccuracy)) {
-			--i;
+		if (!read_btclock(mcl, &btclock, &btaccuracy))
 			continue;
-		}
 		clock_gettime(CLK, &t2);
 
 		latency = time_us(&t2) - time_us(&t1);
 		latencies[i] = latency;
 		avg += latency;
-	}
+		i++;
+	} while (i < 20);
 	avg /= 20;
 
 	/* Calculate deviation */
-- 
1.7.2.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Change the for loop to read blutooth clock in MCAP CSP
  2010-09-17  7:52 [PATCH] Change the for loop to read blutooth clock in MCAP CSP Santiago Carot-Nemesio
@ 2010-09-17 11:56 ` Elvis Pfützenreuter
  2010-09-17 12:37   ` Santiago Carot-Nemesio
  0 siblings, 1 reply; 3+ messages in thread
From: Elvis Pfützenreuter @ 2010-09-17 11:56 UTC (permalink / raw)
  To: Santiago Carot-Nemesio; +Cc: linux-bluetooth

On Sep 17, 2010, at 4:52 AM, Santiago Carot-Nemesio wrote:

> This is only a cosmetic change. Using a do..while loop
> we avoid direct manipulation of counter loop variable
> when error happens reading the BT clock.
> ---
> health/mcap_sync.c |   10 +++++-----
> 1 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/health/mcap_sync.c b/health/mcap_sync.c
> index bc1ffcd..78cb163 100644
> --- a/health/mcap_sync.c
> +++ b/health/mcap_sync.c
> @@ -406,18 +406,18 @@ static void initialize_caps(struct mcap_mcl *mcl)
> 
> 	/* Do clock read a number of times and measure latency */
> 	avg = 0;
> -	for (i = 0; i < 20; ++i) {
> +	i = 0;
> +	do {
> 		clock_gettime(CLK, &t1);
> -		if (!read_btclock(mcl, &btclock, &btaccuracy)) {
> -			--i;
> +		if (!read_btclock(mcl, &btclock, &btaccuracy))
> 			continue;
> -		}
> 		clock_gettime(CLK, &t2);
> 
> 		latency = time_us(&t2) - time_us(&t1);
> 		latencies[i] = latency;
> 		avg += latency;
> -	}
> +		i++;
> +	} while (i < 20);
> 	avg /= 20;
> 
> 	/* Calculate deviation */
> -- 
> 1.7.2.3

Looking again now, this (the logic, not the patch) may lead to an infinite loop, if for some reason the clock simply can't be read. One more thing to be fixed.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Change the for loop to read blutooth clock in MCAP CSP
  2010-09-17 11:56 ` Elvis Pfützenreuter
@ 2010-09-17 12:37   ` Santiago Carot-Nemesio
  0 siblings, 0 replies; 3+ messages in thread
From: Santiago Carot-Nemesio @ 2010-09-17 12:37 UTC (permalink / raw)
  To: Elvis Pfützenreuter; +Cc: Santiago Carot-Nemesio, linux-bluetooth

Hi Elvis,

On 09/17/10 13:56, Elvis Pfützenreuter wrote:
> On Sep 17, 2010, at 4:52 AM, Santiago Carot-Nemesio wrote:
>
>> This is only a cosmetic change. Using a do..while loop
>> we avoid direct manipulation of counter loop variable
>> when error happens reading the BT clock.
>> ---
>> health/mcap_sync.c |   10 +++++-----
>> 1 files changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/health/mcap_sync.c b/health/mcap_sync.c
>> index bc1ffcd..78cb163 100644
>> --- a/health/mcap_sync.c
>> +++ b/health/mcap_sync.c
>> @@ -406,18 +406,18 @@ static void initialize_caps(struct mcap_mcl *mcl)
>>
>> 	/* Do clock read a number of times and measure latency */
>> 	avg = 0;
>> -	for (i = 0; i<  20; ++i) {
>> +	i = 0;
>> +	do {
>> 		clock_gettime(CLK,&t1);
>> -		if (!read_btclock(mcl,&btclock,&btaccuracy)) {
>> -			--i;
>> +		if (!read_btclock(mcl,&btclock,&btaccuracy))
>> 			continue;
>> -		}
>> 		clock_gettime(CLK,&t2);
>>
>> 		latency = time_us(&t2) - time_us(&t1);
>> 		latencies[i] = latency;
>> 		avg += latency;
>> -	}
>> +		i++;
>> +	} while (i<  20);
>> 	avg /= 20;
>>
>> 	/* Calculate deviation */
>> --
>> 1.7.2.3
>
> Looking again now, this (the logic, not the patch) may lead to an infinite loop, if for some reason the clock simply can't be read. One more thing to be fixed.--

Yes, you are rigth, I saw it too but I was waiting to speak with you. It 
may be better set a maximum number of attempts and return a CSP error 
code if it is not possible synchronize with remote device.

For now I think that this patch looks better than use a for loop here :P

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-09-17 12:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-17  7:52 [PATCH] Change the for loop to read blutooth clock in MCAP CSP Santiago Carot-Nemesio
2010-09-17 11:56 ` Elvis Pfützenreuter
2010-09-17 12:37   ` Santiago Carot-Nemesio

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.