Introduce mutex checks

Switched off unless thread debugging is on, but still useful for static
analysis.
This commit is contained in:
Ondřej Kuzník 2018-12-05 13:54:37 +00:00
parent 62a806b243
commit 68b163fca9
7 changed files with 38 additions and 0 deletions

View File

@ -284,6 +284,8 @@ backend_select( LloadOperation *op, int *res )
checked_unlock( &b->b_mutex );
*res = LDAP_SUCCESS;
CONNECTION_ASSERT_LOCKED(c);
assert_locked( &c->c_io_mutex );
return c;
}
CONNECTION_UNLOCK(c);
@ -311,6 +313,7 @@ backend_retry( LloadBackend *b )
"shutting down\n" );
return;
}
assert_locked( &b->b_mutex );
requested = b->b_numconns;
#ifdef LDAP_API_FEATURE_VERIFY_CREDENTIALS
@ -323,6 +326,7 @@ backend_retry( LloadBackend *b )
if ( b->b_active + b->b_bindavail + b->b_opening >= requested ) {
Debug( LDAP_DEBUG_CONNS, "backend_retry: "
"no more connections needed for this backend\n" );
assert_locked( &b->b_mutex );
return;
}
@ -330,6 +334,7 @@ backend_retry( LloadBackend *b )
Debug( LDAP_DEBUG_CONNS, "backend_retry: "
"retry in progress already\n" );
assert( b->b_opening == 1 );
assert_locked( &b->b_mutex );
return;
}
@ -343,6 +348,7 @@ backend_retry( LloadBackend *b )
"scheduling a retry in %d ms\n",
b->b_retry_timeout );
event_add( b->b_retry_event, &b->b_retry_tv );
assert_locked( &b->b_mutex );
return;
}
@ -359,6 +365,7 @@ backend_retry( LloadBackend *b )
b->b_failed++;
event_add( b->b_retry_event, &b->b_retry_tv );
}
assert_locked( &b->b_mutex );
}
void
@ -517,6 +524,7 @@ backend_connect_task( void *ctx, void *arg )
void
backend_reset( LloadBackend *b, int gentle )
{
assert_locked( &b->b_mutex );
if ( b->b_cookie ) {
if ( ldap_pvt_thread_pool_retract( b->b_cookie ) ) {
b->b_cookie = NULL;
@ -582,6 +590,7 @@ backend_reset( LloadBackend *b, int gentle )
connections_walk_last( &b->b_mutex, &b->b_conns, b->b_last_conn,
lload_connection_close, &gentle );
assert( gentle || b->b_active == 0 );
assert_locked( &b->b_mutex );
}
void

View File

@ -37,6 +37,7 @@ bind_mech_external(
char *ptr, *message = "";
int result = LDAP_SUCCESS;
CONNECTION_ASSERT_LOCKED(client);
client->c_state = LLOAD_C_READY;
client->c_type = LLOAD_C_OPEN;
@ -370,6 +371,7 @@ request_bind( LloadConnection *client, LloadOperation *op )
assert( client->c_pin_id == 0 );
goto done;
}
assert_locked( &upstream->c_io_mutex );
/*
* At this point, either:
* - upstream is READY and pin == 0
@ -524,6 +526,7 @@ finish_sasl_bind(
ber_int_t msgid;
int rc;
CONNECTION_ASSERT_LOCKED(upstream);
removed = tavl_delete( &upstream->c_ops, op, operation_upstream_cmp );
if ( !removed ) {
assert( upstream->c_state != LLOAD_C_BINDING );

View File

@ -102,6 +102,8 @@ request_process( LloadConnection *client, LloadOperation *op )
operation_send_reject( op, res, "no connections available", 1 );
goto fail;
}
CONNECTION_ASSERT_LOCKED(upstream);
assert_locked( &upstream->c_io_mutex );
op->o_upstream = upstream;
op->o_upstream_connid = upstream->c_connid;
op->o_res = LLOAD_OP_FAILED;
@ -481,6 +483,7 @@ client_reset( LloadConnection *c )
TAvlnode *root;
long freed = 0, executing;
CONNECTION_ASSERT_LOCKED(c);
root = c->c_ops;
c->c_ops = NULL;
executing = c->c_n_ops_executing;
@ -505,6 +508,7 @@ client_reset( LloadConnection *c )
assert( freed == executing );
CONNECTION_LOCK(c);
CONNECTION_ASSERT_LOCKED(c);
}
void
@ -517,6 +521,7 @@ client_unlink( LloadConnection *c )
"removing client connid=%lu\n",
c->c_connid );
CONNECTION_ASSERT_LOCKED(c);
assert( c->c_state != LLOAD_C_INVALID );
assert( c->c_state != LLOAD_C_DYING );
@ -543,6 +548,7 @@ client_unlink( LloadConnection *c )
CONNECTION_LOCK(c);
client_reset( c );
CONNECTION_ASSERT_LOCKED(c);
}
void

View File

@ -332,6 +332,7 @@ connection_destroy( LloadConnection *c )
"destroying connection connid=%lu\n",
c->c_connid );
CONNECTION_ASSERT_LOCKED(c);
assert( c->c_live == 0 );
assert( c->c_refcnt == 0 );
assert( c->c_state == LLOAD_C_INVALID );
@ -394,12 +395,15 @@ connections_walk_last(
if ( LDAP_CIRCLEQ_EMPTY( cq ) ) {
return;
}
assert_locked( cq_mutex );
last_connid = c->c_connid;
c = LDAP_CIRCLEQ_LOOP_NEXT( cq, c, c_next );
while ( !acquire_ref( &c->c_refcnt ) ) {
c = LDAP_CIRCLEQ_LOOP_NEXT( cq, c, c_next );
if ( c->c_connid >= last_connid ) {
assert_locked( cq_mutex );
return;
}
}
@ -432,10 +436,12 @@ connections_walk_last(
LloadConnection *old = c;
c = LDAP_CIRCLEQ_LOOP_NEXT( cq, c, c_next );
if ( c->c_connid <= old->c_connid || c->c_connid > last_connid ) {
assert_locked( cq_mutex );
return;
}
} while ( !acquire_ref( &c->c_refcnt ) );
} while ( c->c_connid <= last_connid );
assert_locked( cq_mutex );
}
void

View File

@ -91,6 +91,13 @@ LDAP_BEGIN_DECL
#define checked_unlock( mutex ) \
if ( ldap_pvt_thread_mutex_unlock( mutex ) != 0 ) assert(0)
#ifdef LDAP_THREAD_DEBUG
#define assert_locked( mutex ) \
if ( ldap_pvt_thread_mutex_trylock( mutex ) == 0 ) assert(0)
#else
#define assert_locked( mutex ) ( (void)0 )
#endif
typedef struct LloadBackend LloadBackend;
typedef struct LloadPendingConnection LloadPendingConnection;
typedef struct LloadConnection LloadConnection;
@ -302,6 +309,7 @@ struct LloadConnection {
CONNECTION_DESTROY_CB c_unlink;
CONNECTION_DESTROY_CB c_destroy;
CONNECTION_PDU_CB c_pdu_cb;
#define CONNECTION_ASSERT_LOCKED(c) assert_locked( &(c)->c_mutex )
#define CONNECTION_LOCK(c) \
do { \
checked_lock( &(c)->c_mutex ); \

View File

@ -146,6 +146,7 @@ operation_init( LloadConnection *c, BerElement *ber )
goto fail;
}
CONNECTION_ASSERT_LOCKED(c);
rc = tavl_insert( &c->c_ops, op, operation_client_cmp, avl_dup_error );
if ( rc ) {
Debug( LDAP_DEBUG_PACKETS, "operation_init: "

View File

@ -117,6 +117,7 @@ forward_final_response(
static int
handle_unsolicited( LloadConnection *c, BerElement *ber )
{
CONNECTION_ASSERT_LOCKED(c);
if ( c->c_state != LLOAD_C_PREPARING ) {
c->c_state = LLOAD_C_CLOSING;
}
@ -605,6 +606,8 @@ upstream_finish( LloadConnection *c )
LloadBackend *b = c->c_private;
int is_bindconn = 0;
assert_locked( &b->b_mutex );
CONNECTION_ASSERT_LOCKED(c);
assert( c->c_live );
c->c_pdu_cb = handle_one_response;
@ -975,6 +978,7 @@ upstream_unlink( LloadConnection *c )
Debug( LDAP_DEBUG_CONNS, "upstream_unlink: "
"removing upstream connid=%lu\n",
c->c_connid );
CONNECTION_ASSERT_LOCKED(c);
assert( c->c_state != LLOAD_C_INVALID );
assert( c->c_state != LLOAD_C_DYING );
@ -1042,6 +1046,7 @@ upstream_unlink( LloadConnection *c )
checked_unlock( &b->b_mutex );
CONNECTION_LOCK(c);
CONNECTION_ASSERT_LOCKED(c);
}
void