Date: Thu, 28 Apr 2011 00:14:49 +0200 From: Bartosz Fabianowski <freebsd@chillt.de> To: Kostik Belousov <kostikbel@gmail.com> Cc: freebsd-hackers@freebsd.org, Hans Petter Selasky <hselasky@c2i.net> Subject: Re: Is there some implicit locking of device methods? Message-ID: <4DB89559.3080008@chillt.de> In-Reply-To: <20110427215228.GY48734@deviant.kiev.zoral.com.ua> References: <4DB695DB.1080505@chillt.de> <201104271019.31844.jhb@freebsd.org> <4DB818A3.1020104@chillt.de> <201104271334.07170.jhb@freebsd.org> <4DB8873C.5020608@chillt.de> <20110427215228.GY48734@deviant.kiev.zoral.com.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
Indeed, I may have mixed up terminology. Sorry about that. What I am doing (or trying to do) is very simple: There is a single physical USB device. I have a single device node representing it. This device can be opened for reading, concurrently, any number of times. Everyone who open()s the device can read() it at their own pace. I implemented this by maintaining an individual queue of incoming data for each open() call. This queue resides in cdevpriv. So open() instantiates a queue and adds it to the driver's global list of queues. Whenever a packet arrives from the device, it is placed in all the queues (I have a linked list of all queues for that purpose). When the open() is eventually followed by a close(), the cdevpriv destructor removes the queue from the global list and frees its memory. In addition to this, I need to start the USB transfer when the first open() occurs and stop it again when the last close() occurs. I am doing this by checking the length of the global list. When the list is zero-length on open(), I start the transfer. When the list i zero-length in the cdevpriv destructor, I stop the transfer. I cannot see how else to achieve this behavior (other than device cloning which I was using before but which is more complicated and probably more error-prone). If I am doing something wrong and there is a more correct way to do it, I would love to hear about it. - Bartosz
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4DB89559.3080008>