From owner-cvs-all@FreeBSD.ORG Tue Feb 7 04:00:31 2006 Return-Path: X-Original-To: cvs-all@FreeBSD.org Delivered-To: cvs-all@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7FF7316A420; Tue, 7 Feb 2006 04:00:31 +0000 (GMT) (envelope-from mux@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 33FC043D45; Tue, 7 Feb 2006 04:00:31 +0000 (GMT) (envelope-from mux@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k1740UXp031751; Tue, 7 Feb 2006 04:00:31 GMT (envelope-from mux@repoman.freebsd.org) Received: (from mux@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k1740Uhe031750; Tue, 7 Feb 2006 04:00:30 GMT (envelope-from mux) Message-Id: <200602070400.k1740Uhe031750@repoman.freebsd.org> From: Maxime Henrion Date: Tue, 7 Feb 2006 04:00:30 +0000 (UTC) To: projects-committers@FreeBSD.org, cvs-projects@FreeBSD.org, cvs-all@FreeBSD.org X-FreeBSD-CVS-Branch: HEAD Cc: Subject: cvs commit: projects/csup misc.c mux.c threads.c X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Feb 2006 04:00:31 -0000 mux 2006-02-07 04:00:30 UTC FreeBSD projects repository Modified files: csup misc.c mux.c threads.c Log: - Add assertions to ensure that no pthread_mutex_{lock,unlock}() call fails, wrapping them into foo_lock()/foo_unlock() functions when necessary. - Fix a few places in the multiplexer code where we were locking the channel by hand instead of using the already existing chan_lock() function. - Many more changes in the multiplexer code so that we can properly terminate the threads and close the multiplexer. This is the first step into making csup able to handle unexpected errors during the multi-threaded run. Changes: - Make the sender and receiver threads safe to terminate with pthread_cancel(). This was quite easy since those threads hold nearly no resources. Both can hold the multiplexer lock or a channel lock, but the receiver thread never holds any lock at the cancellation points, so no change was needed for this one. The sender thread however can be cancelled while blocking in a pthread_cond_timewait() call, holding the multiplexer mutex as expected, so it needs a cleanup routine, sender_cleanup() to unlock it, using the pthread_cleanup_push() and pthread_cleanup_pop() API. - Implement a mux_shutdown() function that will signal all the threads waiting for read or write on the open channels, close them, pthread_cancel() the appropriate threads and handle the error, if any. - Maintain a "closed" flag and call mux_shutdown() in mux_fini() if it's not closed already. - Have the sender and receiver threads call mux_shutdown() on error. - Remove the useless structs receiver_data and sender_data, and only pass a pointer to the socket to the threads. - Don't use static initializers for mutexes and condvars of the multiplexer, create them and destroy them in mux_init() and mux_fini(). With these changes to the multiplexer code, csup now longer stupidly hangs when it has been disconnected for instance. Revision Changes Path 1.24 +7 -4 projects/csup/misc.c 1.56 +167 -83 projects/csup/mux.c 1.5 +29 -8 projects/csup/threads.c