Hi, On 06/15/2013 12:03 AM, Chris Dickens wrote: > Hi, > > I have an application that prints to stderr when debugging is enabled. It is > multithreaded, so stderr gets a lot of concurrent activity. I have noticed > that libusbx output is often broken up, and looking at the usbi_log_v() > function reveals multiple separate calls to the printf functions. > > AFAIK, any modern OS will provide locking versions of the printf functions, > so that calls to the same file or stream are mutually exclusive. libusbx can > be enhanced to ensure it's debug output is never broken up. It would require > the use of a small local buffer in the usbi_log_v function to construct the > formatted log message. Once completely constructed, it can be dumped to > stderr in one *atomic* call. > > Obviously a few considerations are: > > 1) How big should this buffer be to handle all messages? A maximum length for > the header (less the function name) can be computed, but the function names > and message string will be the variable components.
I would use 256 bytes, most of our log messages fit within 80 chars (without the header), so that should leave plenty of room, while not being overly large. > 2) If the message is too long, truncation would occur. This is undesirable. Yes, but if we use a sane buffer size (so not too small), this will (allmost) never happen, so I would not worry about this. > 2) This will increase the stack size requirements of a usbi_log_v() function > call. Right, but we don'trecurse inside the usbi_log_v() function, so having some stack usage is not really a problem IMHO. > It is certainly helpful to have clean output, but is there any support for > this idea? It sounds like a useful improvement to me. Regards, Hans ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev _______________________________________________ libusbx-devel mailing list libusbx-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libusbx-devel