Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Apr 2024 20:35:49 GMT
From:      Christos Margiolis <christos@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 4d2be7be3837 - main - sound: Get rid of snddev_info->devcount
Message-ID:  <202404182035.43IKZnKG056676@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by christos:

URL: https://cgit.FreeBSD.org/src/commit/?id=4d2be7be3837d66ba242a0a7fd51632c3f89285d

commit 4d2be7be3837d66ba242a0a7fd51632c3f89285d
Author:     Christos Margiolis <christos@FreeBSD.org>
AuthorDate: 2024-04-18 20:35:06 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2024-04-18 20:35:41 +0000

    sound: Get rid of snddev_info->devcount
    
    snddev_info->devcount keeps track of the total number of channels for a
    given device. However, it is redundant to have it, since it is only used
    in sound_oss_sysinfo() to populate the "numaudios" field, and we also
    keep track of the channel counts in the playcount, pvchancount, reccount
    and rvchancount fields anyway. We can simply sum those fields together
    instead of updating a separate variable upon every channel
    addition/deletion.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D44852
---
 sys/dev/sound/pcm/sound.c | 7 +------
 sys/dev/sound/pcm/sound.h | 5 ++++-
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/sys/dev/sound/pcm/sound.c b/sys/dev/sound/pcm/sound.c
index 4b5c2573239c..e88ccb1f25a6 100644
--- a/sys/dev/sound/pcm/sound.c
+++ b/sys/dev/sound/pcm/sound.c
@@ -602,8 +602,6 @@ pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch)
 		break;
 	}
 
-	d->devcount++;
-
 	return (0);
 }
 
@@ -644,8 +642,6 @@ pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch)
 		break;
 	}
 
-	d->devcount--;
-
 	return (0);
 }
 
@@ -947,7 +943,6 @@ pcm_register(device_t dev, void *devinfo, int numplay, int numrec)
 		d->flags |= SD_F_BITPERFECT;
 
 	d->devinfo = devinfo;
-	d->devcount = 0;
 	d->reccount = 0;
 	d->playcount = 0;
 	d->pvchancount = 0;
@@ -1116,7 +1111,7 @@ sound_oss_sysinfo(oss_sysinfo *si)
 		PCM_UNLOCKASSERT(d);
 		PCM_LOCK(d);
 
-		si->numaudios += d->devcount;
+		si->numaudios += PCM_CHANCOUNT(d);
 		++ncards;
 
 		CHN_FOREACH(c, d, channels.pcm) {
diff --git a/sys/dev/sound/pcm/sound.h b/sys/dev/sound/pcm/sound.h
index b48aed7c2d6e..3b725603ee2b 100644
--- a/sys/dev/sound/pcm/sound.h
+++ b/sys/dev/sound/pcm/sound.h
@@ -175,6 +175,9 @@ struct snd_mixer;
 
 #define	PCM_DETACHING(x)	((x)->flags & SD_F_DETACHING)
 
+#define	PCM_CHANCOUNT(d)	\
+	(d->playcount + d->pvchancount + d->reccount + d->rvchancount)
+
 /* many variables should be reduced to a range. Here define a macro */
 #define RANGE(var, low, high) (var) = \
 	(((var)<(low))? (low) : ((var)>(high))? (high) : (var))
@@ -367,7 +370,7 @@ struct snddev_info {
 			} opened;
 		} pcm;
 	} channels;
-	unsigned devcount, playcount, reccount, pvchancount, rvchancount ;
+	unsigned playcount, reccount, pvchancount, rvchancount;
 	unsigned flags;
 	unsigned int bufsz;
 	void *devinfo;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202404182035.43IKZnKG056676>