cvs commit: projects/csup misc.c mux.c threads.c

Maxime Henrion mux at FreeBSD.org
Mon Feb 6 20:00:31 PST 2006


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


More information about the cvs-all mailing list