+ ldap_pvt_thread_mutex_lock( &conn->c_write1_mutex );
+ if ( connection_state_closing( conn )) {
+ ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
+ return 0;
+ }
+ while ( conn->c_writers > 0 ) {
+ ldap_pvt_thread_cond_wait( &conn->c_write1_cv, &conn->c_write1_mutex );
+ }
+ /* connection was closed under us */
+ if ( conn->c_writers < 0 ) {
+ closing = 1;
+ /* we're the last waiter, let the closer continue */
+ if ( conn->c_writers == -1 )
+ ldap_pvt_thread_cond_signal( &conn->c_write1_cv );
+ }
+
+ conn->c_writers++;