diff --git a/modules/b2b_logic/b2b_logic.c b/modules/b2b_logic/b2b_logic.c index 62c7d82c7e9..20729969b53 100644 --- a/modules/b2b_logic/b2b_logic.c +++ b/modules/b2b_logic/b2b_logic.c @@ -704,12 +704,10 @@ static void term_entity(b2bl_entity_id_t *entity, int hash_index, str *key) rpl_data.text = &requestTimeout; } - b2bl_htable[hash_index].locked_by = process_no; if(b2b_api.send_reply(&rpl_data) < 0) LM_ERR("Sending reply failed - %d, [%.*s]\n", rpl_data.code, entity->key.len, entity->key.s); - b2bl_htable[hash_index].locked_by = -1; } else { if ( key && ( !push_new_global_context() || (ctx=b2b_api.get_context())==NULL || @@ -721,9 +719,7 @@ static void term_entity(b2bl_entity_id_t *entity, int hash_index, str *key) memset(&req_data, 0, sizeof(b2b_req_data_t)); PREP_REQ_DATA(entity); req_data.method =&bye; - b2bl_htable[hash_index].locked_by = process_no; b2b_api.send_request(&req_data); - b2bl_htable[hash_index].locked_by = -1; if (key) pop_pushed_global_context(); } @@ -740,7 +736,7 @@ void b2bl_clean(unsigned int ticks, void* param) for(i = 0; i< b2bl_hsize; i++) { - lock_get(&b2bl_htable[i].lock); + B2BL_LOCK_GET(i); tuple = b2bl_htable[i].first; while(tuple) { @@ -761,7 +757,7 @@ void b2bl_clean(unsigned int ticks, void* param) } tuple = tuple_next; } - lock_release(&b2bl_htable[i].lock); + B2BL_LOCK_RELEASE(i); } } @@ -1205,12 +1201,12 @@ static mi_response_t *mi_b2b_terminate_call(const mi_params_t *params, if (b2bl_get_tuple_key(&key, &hash_index, &local_index) < 0) return init_mi_error(404, MI_SSTR("B2B session not found")); - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); if(tuple == NULL) { - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return init_mi_error(404, MI_SSTR("B2B session not found")); } @@ -1228,7 +1224,7 @@ static mi_response_t *mi_b2b_terminate_call(const mi_params_t *params, } b2b_mark_todel(tuple); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return init_mi_result_ok(); } @@ -1358,7 +1354,7 @@ static mi_response_t *mi_b2b_list(const mi_params_t *params, for(i = 0; i< b2bl_hsize; i++) { - lock_get(&b2bl_htable[i].lock); + B2BL_LOCK_GET(i); tuple = b2bl_htable[i].first; while(tuple) { @@ -1449,12 +1445,12 @@ static mi_response_t *mi_b2b_list(const mi_params_t *params, } tuple = tuple->next; } - lock_release(&b2bl_htable[i].lock); + B2BL_LOCK_RELEASE(i); } return resp; error: - lock_release(&b2bl_htable[i].lock); + B2BL_LOCK_RELEASE(i); LM_ERR("Unable to create reply\n"); free_mi_response(resp); return NULL; @@ -1465,14 +1461,12 @@ static b2bl_tuple_t *ctx_search_tuple(struct b2b_context *ctx, int *locked) b2bl_tuple_t *tuple; *locked = 1; - if (b2bl_htable[ctx->hash_index].locked_by != process_no) - lock_get(&b2bl_htable[ctx->hash_index].lock); + B2BL_LOCK_GET_AUX(ctx->hash_index); tuple = b2bl_search_tuple_safe(ctx->hash_index, ctx->local_index); if (!tuple) { LM_ERR("Tuple [%u, %u] not found\n", ctx->hash_index, ctx->local_index); - if (b2bl_htable[ctx->hash_index].locked_by != process_no) - lock_release(&b2bl_htable[ctx->hash_index].lock); + B2BL_LOCK_RELEASE_AUX(ctx->hash_index); locked = 0; return NULL; } @@ -1555,8 +1549,8 @@ int pv_get_b2bl_key(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) res->flags = PV_VAL_STR; res->rs = *tuple->key; - if (locked && b2bl_htable[tuple->hash_index].locked_by != process_no) - lock_release(&b2bl_htable[tuple->hash_index].lock); + if (locked) + B2BL_LOCK_RELEASE_AUX(tuple->hash_index); return 0; } @@ -1575,8 +1569,8 @@ int pv_get_scenario(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) res->flags = PV_VAL_STR; res->rs = *tuple->scenario_id; - if (locked && b2bl_htable[tuple->hash_index].locked_by != process_no) - lock_release(&b2bl_htable[tuple->hash_index].lock); + if (locked) + B2BL_LOCK_RELEASE_AUX(tuple->hash_index); return 0; } @@ -1651,8 +1645,8 @@ int pv_get_entity(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) return pv_get_null(msg, param, res); } - if (!locked && b2bl_htable[tuple->hash_index].locked_by != process_no) - lock_get(&b2bl_htable[tuple->hash_index].lock); + if (!locked) + B2BL_LOCK_GET_AUX(tuple->hash_index); curr_entities[0] = tuple->bridge_entities[0]; curr_entities[1] = tuple->bridge_entities[1]; @@ -1784,14 +1778,12 @@ int pv_get_entity(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) res->flags = PV_VAL_STR; - if (b2bl_htable[tuple->hash_index].locked_by != process_no) - lock_release(&b2bl_htable[tuple->hash_index].lock); + B2BL_LOCK_RELEASE_AUX(tuple->hash_index); return 0; ret_null: - if (b2bl_htable[tuple->hash_index].locked_by != process_no) - lock_release(&b2bl_htable[tuple->hash_index].lock); + B2BL_LOCK_RELEASE_AUX(tuple->hash_index); return pv_get_null(msg, param, res); } @@ -1963,17 +1955,17 @@ int pv_get_ctx(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) return pv_get_null(msg, param, res); } - if (tuple && !locked && b2bl_htable[tuple->hash_index].locked_by != process_no) - lock_get(&b2bl_htable[tuple->hash_index].lock); + if (tuple && !locked) + B2BL_LOCK_GET_AUX(tuple->hash_index); if (fetch_ctx_value(*vals, ¶m->pvn.u.isname.name.s, ¶m->pvv) != 0) { - if (tuple && b2bl_htable[tuple->hash_index].locked_by != process_no) - lock_release(&b2bl_htable[tuple->hash_index].lock); + if (tuple) + B2BL_LOCK_RELEASE_AUX(tuple->hash_index); return pv_get_null(msg, param, res); } - if (tuple && b2bl_htable[tuple->hash_index].locked_by != process_no) - lock_release(&b2bl_htable[tuple->hash_index].lock); + if (tuple) + B2BL_LOCK_RELEASE_AUX(tuple->hash_index); res->flags = PV_VAL_STR; res->rs = param->pvv; @@ -1996,8 +1988,8 @@ int pv_set_ctx(struct sip_msg* msg, pv_param_t *param, int op, pv_value_t *val) return -1; } - if (tuple && !locked && b2bl_htable[tuple->hash_index].locked_by != process_no) - lock_get(&b2bl_htable[tuple->hash_index].lock); + if (tuple && !locked) + B2BL_LOCK_GET_AUX(tuple->hash_index); if (val==NULL || val->flags&(PV_VAL_NONE|PV_VAL_NULL|PV_VAL_EMPTY)) { /* delete value */ @@ -2019,14 +2011,15 @@ int pv_set_ctx(struct sip_msg* msg, pv_param_t *param, int op, pv_value_t *val) } } - if (tuple && b2bl_htable[tuple->hash_index].locked_by != process_no) - lock_release(&b2bl_htable[tuple->hash_index].lock); + + if (tuple) + B2BL_LOCK_RELEASE_AUX(tuple->hash_index); return 0; error: - if (tuple && b2bl_htable[tuple->hash_index].locked_by != process_no) - lock_release(&b2bl_htable[tuple->hash_index].lock); + if (tuple) + B2BL_LOCK_RELEASE_AUX(tuple->hash_index); return -1; } @@ -2055,8 +2048,7 @@ int b2bl_register_cb(str* key, b2bl_cback_f cbf, void* cb_param, return -1; } - if (b2bl_htable[hash_index].locked_by != process_no) - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET_AUX(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); if(tuple == NULL) @@ -2072,8 +2064,7 @@ int b2bl_register_cb(str* key, b2bl_cback_f cbf, void* cb_param, ret = 0; error: - if (b2bl_htable[hash_index].locked_by != process_no) - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE_AUX(hash_index); return ret; } @@ -2085,8 +2076,8 @@ static str *b2bl_get_key(void) b2bl_tuple_t *tuple = get_ctx_tuple(&locked); if (!tuple) { - if (locked && b2bl_htable[tuple->hash_index].locked_by != process_no) - lock_release(&b2bl_htable[tuple->hash_index].lock); + if (locked) + B2BL_LOCK_RELEASE_AUX(tuple->hash_index); return NULL; } @@ -2096,8 +2087,8 @@ static str *b2bl_get_key(void) ret.len = tuple->key->len; memcpy(ret.s, tuple->key->s, ret.len); - if (locked && b2bl_htable[tuple->hash_index].locked_by != process_no) - lock_release(&b2bl_htable[tuple->hash_index].lock); + if (locked) + B2BL_LOCK_RELEASE_AUX(tuple->hash_index); return &ret; } @@ -2123,9 +2114,8 @@ static int b2bl_get_entity_info(str *key, struct sip_msg *msg, int entity, struc } else { tuple = get_ctx_tuple(&locked); - if (tuple && !locked && - b2bl_htable[tuple->hash_index].locked_by != process_no) - lock_get(&b2bl_htable[tuple->hash_index].lock); + if (tuple && !locked) + B2BL_LOCK_GET_AUX(tuple->hash_index); } if (!tuple) return -2; @@ -2190,8 +2180,8 @@ static int b2bl_get_entity_info(str *key, struct sip_msg *msg, int entity, struc rc = 0; end: - if (locked && b2bl_htable[tuple->hash_index].locked_by != process_no) - lock_release(&b2bl_htable[tuple->hash_index].lock); + if (locked) + B2BL_LOCK_RELEASE_AUX(tuple->hash_index); return rc; } @@ -2266,18 +2256,18 @@ int b2bl_restore_upper_info(str* b2bl_key, b2bl_cback_f cbf, void* param, } LM_DBG("hi= %d, li=%d\n", hash_index, local_index); - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); if(tuple == NULL) { LM_ERR("B2B logic record not found\n"); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return -1; } tuple->cb.f = cbf; tuple->cb.mask = cb_mask; tuple->cb.param = param; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return 0; } diff --git a/modules/b2b_logic/b2b_logic.h b/modules/b2b_logic/b2b_logic.h index 950caf3d620..8c37aad0e24 100644 --- a/modules/b2b_logic/b2b_logic.h +++ b/modules/b2b_logic/b2b_logic.h @@ -200,6 +200,31 @@ static inline int b2b_get_request_id(str* request) #define get_tracer(_tuple) \ ( (_tuple)->tracer.f ? &((_tuple)->tracer) : NULL ) + +#define B2BL_LOCK_GET(hash_index) \ + do { \ + lock_get(&b2bl_htable[hash_index].lock); \ + b2bl_htable[hash_index].locked_by = process_no; \ + } while (0) + +#define B2BL_LOCK_RELEASE(hash_index) \ + do { \ + b2bl_htable[hash_index].locked_by = -1; \ + lock_release(&b2bl_htable[hash_index].lock); \ + } while (0) + +#define B2BL_LOCK_GET_AUX(hash_index) \ + do { \ + if (b2bl_htable[hash_index].locked_by != process_no) \ + lock_get(&b2bl_htable[hash_index].lock); \ + } while (0) + +#define B2BL_LOCK_RELEASE_AUX(hash_index) \ + do { \ + if (b2bl_htable[hash_index].locked_by != process_no) \ + lock_release(&b2bl_htable[hash_index].lock); \ + } while (0) + int b2b_add_dlginfo(str* key, str* entity_key,int src, b2b_dlginfo_t* info, void *param); int b2b_server_notify(struct sip_msg* msg, str* key, int type, str *logic_key, void* param, int flags); diff --git a/modules/b2b_logic/b2b_logic_ctx.c b/modules/b2b_logic/b2b_logic_ctx.c index 3574b744732..14fa2742c2f 100644 --- a/modules/b2b_logic/b2b_logic_ctx.c +++ b/modules/b2b_logic/b2b_logic_ctx.c @@ -34,7 +34,7 @@ static b2bl_tuple_t *b2bl_ctx_get_tuple(str *key) static void b2bl_ctx_release_tuple(b2bl_tuple_t *tuple) { - lock_release(&b2bl_htable[tuple->hash_index].lock); + B2BL_LOCK_RELEASE_AUX(tuple->hash_index); } diff --git a/modules/b2b_logic/b2bl_db.c b/modules/b2b_logic/b2bl_db.c index aebdd5342ee..95ab7c6cf0b 100644 --- a/modules/b2b_logic/b2bl_db.c +++ b/modules/b2b_logic/b2bl_db.c @@ -199,7 +199,7 @@ void b2b_logic_dump(int no_lock) for(i = 0; i< b2bl_hsize; i++) { if(!no_lock) - lock_get(&b2bl_htable[i].lock); + B2BL_LOCK_GET(i); tuple = b2bl_htable[i].first; while(tuple) { @@ -272,7 +272,7 @@ void b2b_logic_dump(int no_lock) if (!cdb_key) { LM_ERR("Failed to build map key\n"); if(!no_lock) - lock_release(&b2bl_htable[i].lock); + B2BL_LOCK_RELEASE(i); return; } @@ -300,7 +300,7 @@ void b2b_logic_dump(int no_lock) { LM_ERR("Sql insert failed\n"); if(!no_lock) - lock_release(&b2bl_htable[i].lock); + B2BL_LOCK_RELEASE(i); return; } } @@ -314,7 +314,7 @@ void b2b_logic_dump(int no_lock) if (!cdb_key) { LM_ERR("Failed to build map key\n"); if(!no_lock) - lock_release(&b2bl_htable[i].lock); + B2BL_LOCK_RELEASE(i); return; } @@ -332,7 +332,7 @@ void b2b_logic_dump(int no_lock) { LM_ERR("Sql update failed\n"); if(!no_lock) - lock_release(&b2bl_htable[i].lock); + B2BL_LOCK_RELEASE(i); return; } } @@ -342,7 +342,7 @@ void b2b_logic_dump(int no_lock) tuple = tuple->next; } if(!no_lock) - lock_release(&b2bl_htable[i].lock); + B2BL_LOCK_RELEASE(i); } } @@ -380,7 +380,7 @@ static int b2bl_add_tuple(b2bl_tuple_t* tuple) return -1; } shm_tuple->lifetime = tuple->lifetime; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); shm_tuple->state= tuple->state; /* add entities */ diff --git a/modules/b2b_logic/bridging.c b/modules/b2b_logic/bridging.c index 7f649215857..a033fcff10e 100644 --- a/modules/b2b_logic/bridging.c +++ b/modules/b2b_logic/bridging.c @@ -133,8 +133,7 @@ mi_response_t *mi_b2b_bridge(const mi_params_t *params, goto free; } - lock_get(&b2bl_htable[hash_index].lock); - b2bl_htable[hash_index].locked_by = process_no; + B2BL_LOCK_GET(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); if(tuple == NULL) @@ -229,9 +228,7 @@ mi_response_t *mi_b2b_bridge(const mi_params_t *params, memset(&req_data, 0, sizeof(b2b_req_data_t)); PREP_REQ_DATA(bridging_entity); req_data.method =&meth_inv; - b2bl_htable[hash_index].locked_by = process_no; b2b_api.send_request(&req_data); - b2bl_htable[hash_index].locked_by = -1; } else { if (bridging_start_new_ent(tuple, bridging_entity, entity, NULL, NULL, 0) < 0) { LM_ERR("Failed to start bridging with new entity\n"); @@ -245,8 +242,7 @@ mi_response_t *mi_b2b_bridge(const mi_params_t *params, local_ctx_tuple = NULL; - b2bl_htable[hash_index].locked_by = -1;; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return init_mi_result_ok(); @@ -254,8 +250,7 @@ mi_response_t *mi_b2b_bridge(const mi_params_t *params, if(tuple) b2b_mark_todel(tuple); local_ctx_tuple = NULL; - b2bl_htable[hash_index].locked_by = -1; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); free: if (prov_entity) shm_free(prov_entity); @@ -456,12 +451,12 @@ int process_bridge_negreply(b2bl_tuple_t* tuple, cb_params.entity = entity_no; cb_params.key = tuple->key; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); ret = cbf(&cb_params, B2B_REJECT_CB); LM_DBG("ret = %d\n", ret); - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); /* must search the tuple again * you can't know what might have happened with it */ if (0!=post_cb_sanity_check(&tuple, hash_index, local_index, @@ -526,14 +521,11 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers, req_data.b2b_key =&bentity0->key; req_data.method =&method_ack; req_data.dlginfo =bentity0->dlginfo; - b2bl_htable[hash_index].locked_by = process_no; if(b2b_api.send_request(&req_data) < 0) { LM_ERR("Failed to send ACK in bridging state [%d]\n", tuple->state); - b2bl_htable[hash_index].locked_by = -1; return -1; } - b2bl_htable[hash_index].locked_by = -1; if (tuple->bridge_flags & B2BL_BR_FLAG_RENEW_SDP) { if (tuple->bridge_entities[2]) { @@ -597,14 +589,11 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers, req_data.b2b_key =&bentity1->key; req_data.method =&method_ack; req_data.dlginfo =bentity1->dlginfo; - b2bl_htable[hash_index].locked_by = process_no; if(b2b_api.send_request(&req_data) < 0) { LM_ERR("Failed to send second ACK in bridging scenario\n"); - b2bl_htable[hash_index].locked_by = -1; return -1; } - b2bl_htable[hash_index].locked_by = -1; if (bridging_start_old_ent(tuple, bentity0, bentity1, NULL, NULL) < 0) { @@ -643,11 +632,9 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers, req_data.extra_headers =extra_headers; req_data.body = body; req_data.dlginfo =bentity1->dlginfo; - b2bl_htable[hash_index].locked_by = process_no; if(b2b_api.send_request(&req_data) < 0) { LM_ERR("Failed to send first ACK in bridging scenario\n"); - b2bl_htable[hash_index].locked_by = -1; return -1; } @@ -660,10 +647,8 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers, if(b2b_api.send_request(&req_data) < 0) { LM_ERR("Failed to send second ACK in bridging scenario\n"); - b2bl_htable[hash_index].locked_by = -1; return -1; } - b2bl_htable[hash_index].locked_by = -1; if (shm_str_sync(&bentity0->in_sdp, body) < 0) { LM_ERR("Failed to save SDP\n"); @@ -725,15 +710,12 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers, req_data.extra_headers =extra_headers; req_data.body = body; req_data.dlginfo =bentity1->dlginfo; - b2bl_htable[hash_index].locked_by = process_no; if(b2b_api.send_request(&req_data) < 0) { LM_ERR("Failed to send reINVITE in bridging state [%d]\n", tuple->state); - b2bl_htable[hash_index].locked_by = -1; return -1; } - b2bl_htable[hash_index].locked_by = -1; bentity1->sdp_type = B2BL_SDP_NORMAL; bentity1->state = B2BL_ENT_NEW; } else if (bentity1->type == B2B_SERVER) { @@ -749,14 +731,11 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers, req_data.extra_headers =extra_headers; req_data.body =body; req_data.dlginfo =bentity1->dlginfo; - b2bl_htable[hash_index].locked_by = process_no; if(b2b_api.send_request(&req_data) < 0) { LM_ERR("Failed to send second INVITE in bridging scenario\n"); - b2bl_htable[hash_index].locked_by = -1; return -1; } - b2bl_htable[hash_index].locked_by = -1; bentity1->sdp_type = B2BL_SDP_NORMAL; bentity1->state = B2BL_ENT_NEW; } else { @@ -794,9 +773,7 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers, req_data.extra_headers = NULL; req_data.client_headers = &bentity0->hdrs; req_data.body = body; - b2bl_htable[hash_index].locked_by = process_no; b2b_api.send_request(&req_data); - b2bl_htable[hash_index].locked_by = -1; bentity0->state = B2BL_ENT_NEW; bentity0->sdp_type = B2BL_SDP_NORMAL; @@ -832,11 +809,9 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers, req_data.extra_headers =extra_headers; req_data.body = (bentity0->sdp_type == B2BL_SDP_LATE) ? body : 0; req_data.dlginfo =bentity0->dlginfo; - b2bl_htable[hash_index].locked_by = process_no; if(b2b_api.send_request(&req_data) < 0) { LM_ERR("Failed to send first ACK in bridging scenario\n"); - b2bl_htable[hash_index].locked_by = -1; return -1; } @@ -849,10 +824,8 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers, if(b2b_api.send_request(&req_data) < 0) { LM_ERR("Failed to send second ACK in bridging scenario\n"); - b2bl_htable[hash_index].locked_by = -1; return -1; } - b2bl_htable[hash_index].locked_by = -1; tuple->bridge_entities[1]->peer = tuple->bridge_entities[0]; tuple->bridge_entities[0]->peer = tuple->bridge_entities[1]; @@ -909,14 +882,11 @@ int process_bridge_200OK(struct sip_msg* msg, str* extra_headers, req_data.extra_headers =extra_headers; req_data.body =body; req_data.dlginfo =bentity0->dlginfo; - b2bl_htable[hash_index].locked_by = process_no; if(b2b_api.send_request(&req_data) < 0) { LM_ERR("Failed to send second Invite in bridging scenario\n"); - b2bl_htable[hash_index].locked_by = -1; return -1; } - b2bl_htable[hash_index].locked_by = -1; bentity0->state = B2BL_ENT_NEW; if (shm_str_sync(&bentity1->in_sdp, body) < 0) { @@ -978,13 +948,10 @@ int send_bridge_notify(b2bl_entity_id_t *entity, unsigned int hash_index, } req_data.extra_headers = &hdrs; req_data.body = &body; - b2bl_htable[hash_index].locked_by = process_no; if (b2b_api.send_request(&req_data) < 0) { LM_ERR("Failed to send NOTIFY\n"); - b2bl_htable[hash_index].locked_by = -1; return -1; } - b2bl_htable[hash_index].locked_by = -1; return 0; } @@ -1074,7 +1041,8 @@ int b2b_script_bridge(struct sip_msg *msg, str *br_ent1_str, str *br_ent2_str, return -1; } - lock_get(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_GET(cur_route_ctx.hash_index); + tuple = b2bl_search_tuple_safe(cur_route_ctx.hash_index, cur_route_ctx.local_index); if(tuple == NULL) @@ -1150,7 +1118,7 @@ int b2b_script_bridge(struct sip_msg *msg, str *br_ent1_str, str *br_ent2_str, rc = 1; done: - lock_release(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_RELEASE(cur_route_ctx.hash_index); return rc; } @@ -1171,7 +1139,7 @@ int b2b_script_bridge_retry(struct sip_msg *msg, str *new_ent_str) return -1; } - lock_get(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_GET(cur_route_ctx.hash_index); tuple = b2bl_search_tuple_safe(cur_route_ctx.hash_index, cur_route_ctx.local_index); @@ -1268,13 +1236,13 @@ int b2b_script_bridge_retry(struct sip_msg *msg, str *new_ent_str) local_ctx_tuple = NULL; - lock_release(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_RELEASE(cur_route_ctx.hash_index); return 1; error: local_ctx_tuple = NULL; - lock_release(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_RELEASE(cur_route_ctx.hash_index); return -1; } @@ -1391,9 +1359,7 @@ static int bridging_start_old_ent(b2bl_tuple_t* tuple, b2bl_entity_id_t *old_ent req_data.extra_headers = NULL; req_data.client_headers = &old_entity->hdrs; req_data.body = body; - b2bl_htable[tuple->hash_index].locked_by = process_no; b2b_api.send_request(&req_data); - b2bl_htable[tuple->hash_index].locked_by = -1; old_entity->state = B2BL_ENT_NEW; if (body) { if (!body->s) { @@ -1703,7 +1669,7 @@ int b2bl_api_bridge(str* key, str* new_dst, str *new_proxy, str* new_from_dname, return -1; } - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); if(tuple == NULL) @@ -1727,7 +1693,7 @@ int b2bl_api_bridge(str* key, str* new_dst, str *new_proxy, str* new_from_dname, } local_ctx_tuple = NULL; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return 0; } @@ -1789,7 +1755,7 @@ int b2bl_api_bridge(str* key, str* new_dst, str *new_proxy, str* new_from_dname, local_ctx_tuple = NULL; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return 0; @@ -1797,7 +1763,7 @@ int b2bl_api_bridge(str* key, str* new_dst, str *new_proxy, str* new_from_dname, if(entity) shm_free(entity); local_ctx_tuple = NULL; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return -1; } @@ -1823,7 +1789,7 @@ int b2bl_bridge_2calls(str* key1, str* key2) } /* extract the entity and delete the tuple */ - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); if(tuple == NULL) @@ -1917,7 +1883,7 @@ int b2bl_bridge_2calls(str* key1, str* key2) } b2bl_delete(tuple, hash_index, 1, 1); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); /* must restore the b2bl_key for this entity in b2b_entities */ @@ -1930,7 +1896,7 @@ int b2bl_bridge_2calls(str* key1, str* key2) } /* extract the entity and delete the tuple */ - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); if(tuple == NULL) @@ -1990,14 +1956,11 @@ int b2bl_bridge_2calls(str* key1, str* key2) req_data.method =&method_invite; req_data.extra_headers = NULL; req_data.client_headers = &e1->hdrs; - b2bl_htable[hash_index].locked_by = process_no; if(b2b_api.send_request(&req_data) < 0) { - b2bl_htable[hash_index].locked_by = -1; LM_ERR("Failed to send reInvite\n"); goto error; } - b2bl_htable[hash_index].locked_by = -1; e1->sdp_type = B2BL_SDP_LATE; e1->state = 0; tuple->state = B2B_BRIDGING_STATE; @@ -2006,7 +1969,7 @@ int b2bl_bridge_2calls(str* key1, str* key2) else tuple->lifetime = 0; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); local_ctx_tuple = NULL; @@ -2015,7 +1978,7 @@ int b2bl_bridge_2calls(str* key1, str* key2) error: if(tuple) b2b_mark_todel(tuple); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); local_ctx_tuple = NULL; return -1; } @@ -2061,7 +2024,7 @@ int b2bl_bridge_msg(struct sip_msg* msg, str* key, int entity_no, str *adv_ct) } /* extract the entity and delete the tuple */ - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); if(tuple == NULL) @@ -2155,9 +2118,7 @@ int b2bl_bridge_msg(struct sip_msg* msg, str* key, int entity_no, str *adv_ct) PREP_REQ_DATA(old_entity); req_data.method =&method_bye; req_data.no_cb = 1; - b2bl_htable[hash_index].locked_by = process_no; b2b_api.send_request(&req_data); - b2bl_htable[hash_index].locked_by = -1; } else { @@ -2192,10 +2153,8 @@ int b2bl_bridge_msg(struct sip_msg* msg, str* key, int entity_no, str *adv_ct) } /* destroy the old_entity */ - b2bl_htable[hash_index].locked_by = process_no; b2b_api.entity_delete(old_entity->type, &old_entity->key, old_entity->dlginfo, 1, 1); - b2bl_htable[hash_index].locked_by = -1; b2bl_free_entity(old_entity); old_entity = NULL; @@ -2282,14 +2241,11 @@ int b2bl_bridge_msg(struct sip_msg* msg, str* key, int entity_no, str *adv_ct) /* Decrement Max-Forwards value */ if ((maxfwd = b2b_msg_get_maxfwd(msg)) > 0) req_data.maxfwd = maxfwd; - b2bl_htable[hash_index].locked_by = process_no; if(b2b_api.send_request(&req_data) < 0) { - b2bl_htable[hash_index].locked_by = -1; LM_ERR("Failed to send Update/reInvite\n"); goto error; } - b2bl_htable[hash_index].locked_by = -1; bridging_entity->sdp_type = B2BL_SDP_NORMAL; bridging_entity->state = 0; if(max_duration) @@ -2304,7 +2260,7 @@ int b2bl_bridge_msg(struct sip_msg* msg, str* key, int entity_no, str *adv_ct) local_ctx_tuple = NULL; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); if(new_body.s) pkg_free(new_body.s); @@ -2313,7 +2269,7 @@ int b2bl_bridge_msg(struct sip_msg* msg, str* key, int entity_no, str *adv_ct) error: if(tuple) b2b_mark_todel(tuple); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); if(new_body.s) pkg_free(new_body.s); local_ctx_tuple = NULL; diff --git a/modules/b2b_logic/entity_storage.c b/modules/b2b_logic/entity_storage.c index 33f0f471f54..59a19bdb4b0 100644 --- a/modules/b2b_logic/entity_storage.c +++ b/modules/b2b_logic/entity_storage.c @@ -170,8 +170,7 @@ void entity_event_trigger(enum b2b_entity_type etype, str *entity_key, return; } - if (b2bl_htable[hash_index].locked_by != process_no) - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET_AUX(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); @@ -185,13 +184,11 @@ void entity_event_trigger(enum b2b_entity_type etype, str *entity_key, pack_context_vals(tuple, storage); } else if (event_type != B2B_EVENT_DELETE) { LM_ERR("Tuple [%.*s] not found\n", b2bl_key->len, b2bl_key->s); - if (b2bl_htable[hash_index].locked_by != process_no) - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE_AUX(hash_index); return; } - if (b2bl_htable[hash_index].locked_by != process_no) - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE_AUX(hash_index); return; } @@ -202,8 +199,7 @@ void entity_event_trigger(enum b2b_entity_type etype, str *entity_key, case B2B_EVENT_UPDATE: if (!tuple) { LM_ERR("Tuple [%.*s] not found\n", b2bl_key->len, b2bl_key->s); - if (b2bl_htable[hash_index].locked_by != process_no) - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE_AUX(hash_index); return; } pack_tuple(tuple, storage, tuple_repl_new); @@ -212,8 +208,7 @@ void entity_event_trigger(enum b2b_entity_type etype, str *entity_key, case B2B_EVENT_ACK: if (!tuple) { LM_ERR("Tuple [%.*s] not found\n", b2bl_key->len, b2bl_key->s); - if (b2bl_htable[hash_index].locked_by != process_no) - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE_AUX(hash_index); return; } pack_tuple(tuple, storage, tuple_repl_new); @@ -230,8 +225,7 @@ void entity_event_trigger(enum b2b_entity_type etype, str *entity_key, LM_ERR("Bad entity callback event type!\n"); } - if (b2bl_htable[hash_index].locked_by != process_no) - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE_AUX(hash_index); } static void receive_entity_create(enum b2b_entity_type entity_type, @@ -257,7 +251,7 @@ static void receive_entity_create(enum b2b_entity_type entity_type, return; } - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); old_tuple = b2bl_search_tuple_safe(hash_index, local_index); @@ -332,7 +326,7 @@ static void receive_entity_create(enum b2b_entity_type entity_type, entity = b2bl_search_entity(tuple, entity_key, entity_type, &entity_head); if (entity) { LM_DBG("Entity [%.*s] already exists\n", entity_key->len, entity_key->s); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return; } @@ -425,13 +419,13 @@ static void receive_entity_create(enum b2b_entity_type entity_type, UPDATE_DBFLAG(tuple); } - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return; error: if (tuple && !old_tuple) b2bl_delete(tuple, hash_index, 0, 0); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); if (entity) b2bl_free_entity(entity); @@ -457,7 +451,7 @@ static void receive_entity_update(enum b2b_entity_type entity_type, return; } - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); if (!tuple) { @@ -519,11 +513,11 @@ static void receive_entity_update(enum b2b_entity_type entity_type, else UPDATE_DBFLAG(tuple); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return; error: - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); LM_ERR("Failed to process received entity [%.*s]\n", entity_key->len, entity_key->s); } @@ -544,19 +538,19 @@ static void receive_entity_ack(enum b2b_entity_type entity_type, return; } - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); if (!tuple) { LM_ERR("Tuple [%.*s] not found\n", b2bl_key->len, b2bl_key->s); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return; } bin_pop_int(storage, &tuple_repl_type); if (tuple_repl_type != REPL_TUPLE_UPDATE) { LM_ERR("Bad tuple replication type: %d\n", tuple_repl_type); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return; } @@ -568,7 +562,7 @@ static void receive_entity_ack(enum b2b_entity_type entity_type, if (unpack_context_vals(tuple, storage) < 0) LM_ERR("Failed to unpack context values\n"); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); } static void receive_entity_delete(enum b2b_entity_type entity_type, @@ -589,14 +583,14 @@ static void receive_entity_delete(enum b2b_entity_type entity_type, return; } - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); if (!tuple) { /* tuple might have already expired locally */ LM_DBG("Tuple [%.*s] not found, discarding entity [%.*s] delete\n", b2bl_key->len, b2bl_key->s, entity_key->len, entity_key->s); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return; } @@ -611,7 +605,7 @@ static void receive_entity_delete(enum b2b_entity_type entity_type, if (unpack_context_vals(tuple, storage) < 0) { LM_ERR("Failed to unpack context values\n"); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return; } break; @@ -620,7 +614,7 @@ static void receive_entity_delete(enum b2b_entity_type entity_type, break; default: LM_ERR("Bad tuple replication type: %d\n", tuple_repl_type); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return; } @@ -635,7 +629,7 @@ static void receive_entity_delete(enum b2b_entity_type entity_type, /* no other bridge entities remaining, delete the tuple */ b2bl_delete(tuple, hash_index, 1, 0); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); } void entity_event_received(enum b2b_entity_type etype, str *entity_key, @@ -655,12 +649,12 @@ void entity_event_received(enum b2b_entity_type etype, str *entity_key, return; } - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); if (!tuple) { LM_ERR("Tuple [%.*s] not found\n", b2bl_key->len, b2bl_key->s); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return; } @@ -686,7 +680,7 @@ void entity_event_received(enum b2b_entity_type etype, str *entity_key, LM_ERR("Bad tuple replication type: %d\n", tuple_storage_type); } - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return; } diff --git a/modules/b2b_logic/logic.c b/modules/b2b_logic/logic.c index ed808e25b53..546473e5d4a 100644 --- a/modules/b2b_logic/logic.c +++ b/modules/b2b_logic/logic.c @@ -147,13 +147,14 @@ int b2b_add_dlginfo(str* key, str* entity_key, int src, b2b_dlginfo_t* dlginfo, LM_ERR("Failed to parse key\n"); return -1; } - lock_get(&b2bl_htable[hash_index].lock); + + B2BL_LOCK_GET(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); if(tuple == NULL) { LM_ERR("No entity found\n"); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return -1; } /* a connected call */ @@ -165,7 +166,7 @@ int b2b_add_dlginfo(str* key, str* entity_key, int src, b2b_dlginfo_t* dlginfo, if(entity == NULL) { LM_ERR("No b2b_key match found\n"); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return -1; } @@ -177,7 +178,7 @@ int b2b_add_dlginfo(str* key, str* entity_key, int src, b2b_dlginfo_t* dlginfo, if(entity_add_dlginfo(entity, dlginfo) < 0) { LM_ERR("Failed to add dialoginfo\n"); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return -1; } @@ -189,7 +190,7 @@ int b2b_add_dlginfo(str* key, str* entity_key, int src, b2b_dlginfo_t* dlginfo, dlginfo->callid.len, dlginfo->callid.s); } - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return 0; } @@ -450,9 +451,7 @@ void b2b_end_dialog(b2bl_entity_id_t* bentity, b2bl_tuple_t* tuple, memset(&req_data, 0, sizeof(b2b_req_data_t)); PREP_REQ_DATA(bentity); req_data.method =method; - b2bl_htable[hash_index].locked_by = process_no; b2b_api.send_request(&req_data); - b2bl_htable[hash_index].locked_by = -1; bentity->disconnected = 1; } @@ -535,13 +534,9 @@ b2bl_entity_id_t *b2bl_new_client(client_info_t *ci, b2bl_tuple_t *tuple, } } - b2bl_htable[tuple->hash_index].locked_by = process_no; - client_id = b2b_api.client_new(ci, b2b_client_notify, b2b_add_dlginfo, &b2bl_mod_name, tuple->key, get_tracer(tuple), NULL, NULL); - b2bl_htable[tuple->hash_index].locked_by = -1; - if(client_id == NULL) { LM_ERR("Failed to create client id\n"); @@ -678,12 +673,12 @@ int run_init_negreply_cb(struct sip_msg *msg, b2bl_tuple_t *tuple, cb_params.entity = entity_no; cb_params.key = tuple->key; - lock_release(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_RELEASE(cur_route_ctx.hash_index); ret = cbf(&cb_params, B2B_REJECT_CB); LM_DBG("ret = %d\n", ret); - lock_get(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_GET(cur_route_ctx.hash_index); /* must search the tuple again * you can't know what might have happened with it */ if (0!=post_cb_sanity_check(&tuple, cur_route_ctx.hash_index, @@ -753,14 +748,9 @@ int retry_init_bridge(struct sip_msg *msg, b2bl_tuple_t* tuple, } } - b2bl_htable[tuple->hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, &b2bl_mod_name, tuple->key, get_tracer(tuple), NULL, NULL); - - b2bl_htable[tuple->hash_index].locked_by = -1; - if(client_id == NULL) { LM_ERR("failed to create new b2b client instance\n"); @@ -810,15 +800,12 @@ do{ \ rpl_data.extra_headers = \ cur_route_ctx.extra_headers->s?cur_route_ctx.extra_headers:NULL;\ rpl_data.dlginfo =peer->dlginfo; \ - b2bl_htable[cur_route_ctx.hash_index].locked_by = process_no; \ if(b2b_api.send_reply(&rpl_data) < 0) \ { \ - b2bl_htable[cur_route_ctx.hash_index].locked_by = -1; \ LM_ERR("Sending reply failed - %d, [%.*s]\n", \ statuscode, peer->key.len, peer->key.s);\ goto done; \ } \ - b2bl_htable[cur_route_ctx.hash_index].locked_by = -1; \ }while(0) static int ack_and_term_entity(b2bl_tuple_t *tuple, b2bl_entity_id_t *entity, @@ -830,17 +817,13 @@ static int ack_and_term_entity(b2bl_tuple_t *tuple, b2bl_entity_id_t *entity, memset(&req_data, 0, sizeof(b2b_req_data_t)); PREP_REQ_DATA(entity); req_data.method = &str_init("ACK"); - b2bl_htable[tuple->hash_index].locked_by = process_no; b2b_api.send_request(&req_data); - b2bl_htable[tuple->hash_index].locked_by = -1; } memset(&req_data, 0, sizeof(b2b_req_data_t)); PREP_REQ_DATA(entity); req_data.method = &str_init("BYE"); - b2bl_htable[tuple->hash_index].locked_by = process_no; b2b_api.send_request(&req_data); - b2bl_htable[tuple->hash_index].locked_by = -1; entity->disconnected = 1; @@ -864,7 +847,7 @@ int _b2b_handle_reply(struct sip_msg *msg, b2bl_tuple_t *tuple, int do_unlock = 0; if (!tuple) { - lock_get(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_GET(cur_route_ctx.hash_index); do_unlock = 1; tuple = b2bl_search_tuple_safe(cur_route_ctx.hash_index, cur_route_ctx.local_index); @@ -1046,7 +1029,6 @@ int _b2b_handle_reply(struct sip_msg *msg, b2bl_tuple_t *tuple, PREP_REQ_DATA(e); req_data.method =&method_cancel; req_data.extra_headers = &cancel_reason_hdr; - b2bl_htable[tuple->hash_index].locked_by = process_no; if(b2b_api.send_request(&req_data) < 0) { LM_ERR("Sending request" @@ -1055,7 +1037,6 @@ int _b2b_handle_reply(struct sip_msg *msg, b2bl_tuple_t *tuple, } b2b_api.entity_delete(e->type, &e->key, e->dlginfo, 0, 1); - b2bl_htable[tuple->hash_index].locked_by = -1; LM_DBG("destroying dlginfo=[%p]\n", e->dlginfo); ent = e->next; @@ -1076,14 +1057,11 @@ int _b2b_handle_reply(struct sip_msg *msg, b2bl_tuple_t *tuple, rpl_data.text = &requestTerminated; rpl_data.body = NULL; - b2bl_htable[cur_route_ctx.hash_index].locked_by = process_no; if(b2b_api.send_reply(&rpl_data) < 0) { - b2bl_htable[cur_route_ctx.hash_index].locked_by = -1; LM_ERR("Sending reply failed - %d, [%.*s]\n", rpl_data.code, peer->key.len, peer->key.s); goto done; } - b2bl_htable[cur_route_ctx.hash_index].locked_by = -1; LM_DBG("Sent 487 reply to peer after terminating entity " "[%.*s]\n", entity->key.len, entity->key.s); @@ -1129,9 +1107,11 @@ int _b2b_handle_reply(struct sip_msg *msg, b2bl_tuple_t *tuple, cb_params.entity = entity->no; cb_params.key = tuple->key; - lock_release(&b2bl_htable[tuple->hash_index].lock); + B2BL_LOCK_RELEASE(tuple->hash_index); + ret = cbf(&cb_params, B2B_CONFIRMED_CB); - lock_get(&b2bl_htable[tuple->hash_index].lock); + + B2BL_LOCK_GET(tuple->hash_index); /* must search the tuple again * you can't know what might have happened with it */ @@ -1213,12 +1193,14 @@ int _b2b_handle_reply(struct sip_msg *msg, b2bl_tuple_t *tuple, if (tuple) cur_route_ctx.flags |= B2BL_RT_DO_UPDATE; done1: - if (do_unlock) - lock_release(&b2bl_htable[cur_route_ctx.hash_index].lock); + if (do_unlock) { + B2BL_LOCK_RELEASE(cur_route_ctx.hash_index); + } return 0; error: - if (do_unlock) - lock_release(&b2bl_htable[cur_route_ctx.hash_index].lock); + if (do_unlock) { + B2BL_LOCK_RELEASE(cur_route_ctx.hash_index); + } return -1; } @@ -1238,7 +1220,7 @@ int b2b_logic_notify_reply(int src, struct sip_msg* msg, str* key, str* body, st return -1; } - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); locked = 1; tuple = b2bl_search_tuple_safe(hash_index, local_index); @@ -1317,7 +1299,7 @@ int b2b_logic_notify_reply(int src, struct sip_msg* msg, str* key, str* body, st routeid = tuple->reply_route->idx; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); locked = 0; cur_route_ctx.flags |= B2BL_RT_RPL_CTX; @@ -1330,13 +1312,13 @@ int b2b_logic_notify_reply(int src, struct sip_msg* msg, str* key, str* body, st done: if (tuple && cur_route_ctx.flags & B2BL_RT_DO_UPDATE) { if (b2bl_db_mode != NO_DB && !locked) { - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); locked = 1; tuple = b2bl_search_tuple_safe(hash_index, local_index); if(!tuple) { LM_DBG("B2B logic record not found anymore\n"); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return 0; } } @@ -1347,10 +1329,10 @@ int b2b_logic_notify_reply(int src, struct sip_msg* msg, str* key, str* body, st UPDATE_DBFLAG(tuple); } if (locked) - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return 0; error: - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return -1; } @@ -1367,7 +1349,7 @@ int _b2b_pass_request(struct sip_msg *msg, b2bl_tuple_t *tuple, int maxfwd; if (!tuple) { - lock_get(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_GET(cur_route_ctx.hash_index); do_unlock = 1; tuple = b2bl_search_tuple_safe(cur_route_ctx.hash_index, cur_route_ctx.local_index); @@ -1435,12 +1417,10 @@ int _b2b_pass_request(struct sip_msg *msg, b2bl_tuple_t *tuple, /* Decrement Max-Forwards value */ if ((maxfwd = b2b_msg_get_maxfwd(msg)) > 0) req_data.maxfwd = maxfwd; - b2bl_htable[cur_route_ctx.hash_index].locked_by = process_no; if(b2b_api.send_request(&req_data) < 0) { LM_ERR("Sending request failed [%.*s]\n", peer->key.len, peer->key.s); } - b2bl_htable[cur_route_ctx.hash_index].locked_by = -1; if (request_id != B2B_ACK) peer->flags &= ~ENTITY_FL_REPLY_RECEIVED; peer = peer->next; @@ -1450,11 +1430,11 @@ int _b2b_pass_request(struct sip_msg *msg, b2bl_tuple_t *tuple, if (tuple) cur_route_ctx.flags |= B2BL_RT_DO_UPDATE; if (do_unlock) - lock_release(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_RELEASE(cur_route_ctx.hash_index); return 0; error: if (do_unlock) - lock_release(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_GET(cur_route_ctx.hash_index); return -1; } @@ -1477,7 +1457,7 @@ int b2b_logic_notify_request(int src, struct sip_msg* msg, str* key, str* body, int locked = 0; int routeid; - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); locked = 1; tuple = b2bl_search_tuple_safe(hash_index, local_index); @@ -1508,7 +1488,7 @@ int b2b_logic_notify_request(int src, struct sip_msg* msg, str* key, str* body, avp_val.s = *b2bl_key; if(add_avp(AVP_VAL_STR|b2bl_key_avp_type, b2bl_key_avp_name, avp_val)!=0) { - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); LM_ERR("failed to build b2bl_key avp\n"); return -1; } @@ -1621,13 +1601,13 @@ int b2b_logic_notify_request(int src, struct sip_msg* msg, str* key, str* body, cb_params.entity = entity->no; cb_params.key = tuple->key; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); LM_DBG("entity->no = %d\n", entity->no); ret = cbf(&cb_params, B2B_BYE_CB); LM_DBG("ret = %d, peer= %p\n", ret, peer); pkg_free(stats.key.s); - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); /* must search the tuple again * you can't know what might have happened with it */ if (0!=post_cb_sanity_check(&tuple, hash_index, local_index, @@ -1708,13 +1688,13 @@ int b2b_logic_notify_request(int src, struct sip_msg* msg, str* key, str* body, cb_params.msg = msg; cb_params.entity = entity->no; cb_params.key = tuple->key; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); LM_DBG("entity->no = %d\n", entity->no); ret = cbf(&cb_params, B2B_RE_INVITE_CB); LM_DBG("ret = %d, peer= %p\n", ret, peer); - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); /* must search the tuple again * you can't know what might have happened with it */ if (0!=post_cb_sanity_check(&tuple, hash_index, local_index, @@ -1803,7 +1783,7 @@ int b2b_logic_notify_request(int src, struct sip_msg* msg, str* key, str* body, routeid = tuple->req_route->idx; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); locked = 0; cur_route_ctx.flags = B2BL_RT_REQ_CTX; @@ -1825,13 +1805,13 @@ int b2b_logic_notify_request(int src, struct sip_msg* msg, str* key, str* body, if(tuple && cur_route_ctx.flags & B2BL_RT_DO_UPDATE) { if (b2bl_db_mode != NO_DB && !locked) { - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); locked = 1; tuple = b2bl_search_tuple_safe(hash_index, local_index); if(!tuple) { LM_DBG("B2B logic record not found anymore\n"); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return 0; } } @@ -1841,11 +1821,11 @@ int b2b_logic_notify_request(int src, struct sip_msg* msg, str* key, str* body, UPDATE_DBFLAG(tuple); } if (locked) - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return 0; error: - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return -1; } @@ -1885,7 +1865,7 @@ int b2b_send_reply(struct sip_msg *msg, int *code, str *reason, str *headers, st return -1; } - lock_get(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_GET(cur_route_ctx.hash_index); tuple = b2bl_search_tuple_safe(cur_route_ctx.hash_index, cur_route_ctx.local_index); if(tuple == NULL) @@ -1918,16 +1898,14 @@ int b2b_send_reply(struct sip_msg *msg, int *code, str *reason, str *headers, st rpl_data.extra_headers = headers; rpl_data.body = body; - b2bl_htable[cur_route_ctx.hash_index].locked_by = process_no; b2b_api.send_reply(&rpl_data); - b2bl_htable[cur_route_ctx.hash_index].locked_by = -1; LM_DBG("Send reply with code [%d] and text [%.*s]\n", *code, reason->len, reason->s); - lock_release(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_RELEASE(cur_route_ctx.hash_index); return 1; error: - lock_release(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_RELEASE(cur_route_ctx.hash_index); return -1; } @@ -1943,7 +1921,7 @@ int b2b_delete_entity(struct sip_msg *msg) return -1; } - lock_get(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_GET(cur_route_ctx.hash_index); tuple = b2bl_search_tuple_safe(cur_route_ctx.hash_index, cur_route_ctx.local_index); if(tuple == NULL) @@ -1972,10 +1950,10 @@ int b2b_delete_entity(struct sip_msg *msg) cur_route_ctx.flags |= B2BL_RT_DO_UPDATE; - lock_release(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_RELEASE(cur_route_ctx.hash_index); return 1; error: - lock_release(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_RELEASE(cur_route_ctx.hash_index); return -1; } @@ -1992,7 +1970,7 @@ int b2b_end_dlg_leg(struct sip_msg *msg) return -1; } - lock_get(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_GET(cur_route_ctx.hash_index); tuple = b2bl_search_tuple_safe(cur_route_ctx.hash_index, cur_route_ctx.local_index); if(tuple == NULL) @@ -2021,19 +1999,17 @@ int b2b_end_dlg_leg(struct sip_msg *msg) memset(&req_data, 0, sizeof(b2b_req_data_t)); PREP_REQ_DATA(entity); req_data.method =&method_bye; - b2bl_htable[cur_route_ctx.hash_index].locked_by = process_no; b2b_api.send_request(&req_data); - b2bl_htable[cur_route_ctx.hash_index].locked_by = -1; if(entity->peer) entity->peer->peer = NULL; entity->peer = NULL; cur_route_ctx.flags |= B2BL_RT_DO_UPDATE; - lock_release(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_RELEASE(cur_route_ctx.hash_index); return 1; error: - lock_release(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_RELEASE(cur_route_ctx.hash_index); return -1; } @@ -2211,12 +2187,12 @@ int b2b_logic_notify(int src, struct sip_msg* msg, str* key, int type, str* b2bl &entity_key, &hash_idx, &local_idx)==0 ) { /* There is a "replaces" info and it matches a local dialog */ - lock_get(&b2bl_htable[hash_idx].lock); + B2BL_LOCK_GET(hash_idx); tuple=b2bl_search_tuple_safe(hash_idx, local_idx); if(tuple == NULL) { LM_ERR("B2B logic record not found\n"); - lock_release(&b2bl_htable[hash_idx].lock); + B2BL_LOCK_RELEASE(hash_idx); goto done; } b2bl_print_tuple(tuple, L_ERR); @@ -2231,7 +2207,7 @@ int b2b_logic_notify(int src, struct sip_msg* msg, str* key, int type, str* b2bl break; } } - lock_release(&b2bl_htable[hash_idx].lock); + B2BL_LOCK_RELEASE(hash_idx); if(!r_peer) { @@ -2541,13 +2517,9 @@ str* create_top_hiding_entities(struct sip_msg* msg, b2bl_cback_f cbf, if ((maxfwd = b2b_msg_get_maxfwd(msg)) > 0) ci.maxfwd = maxfwd; - b2bl_htable[hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, &b2bl_mod_name, b2bl_key, get_tracer(tuple), NULL, NULL); - b2bl_htable[hash_index].locked_by = -1; - if(client_id == NULL) { LM_ERR("failed to create new b2b client instance\n"); @@ -2588,13 +2560,9 @@ str* create_top_hiding_entities(struct sip_msg* msg, b2bl_cback_f cbf, ci.req_uri = uri; ci.avps = clone_avp_list( *get_avp_list() ); - b2bl_htable[hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, &b2bl_mod_name, b2bl_key, get_tracer(tuple), NULL, NULL); - b2bl_htable[hash_index].locked_by = -1; - if(client_id == NULL) { LM_ERR("failed to create new b2b client instance\n"); @@ -2635,7 +2603,7 @@ str* create_top_hiding_entities(struct sip_msg* msg, b2bl_cback_f cbf, b2bl_db_insert(tuple); } - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); local_ctx_tuple = NULL; @@ -2648,7 +2616,7 @@ str* create_top_hiding_entities(struct sip_msg* msg, b2bl_cback_f cbf, pkg_free(new_body.s); return b2bl_key; error: - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); if(server_id) pkg_free(server_id); if(client_id) @@ -2781,8 +2749,6 @@ str* b2bl_init_extern(struct b2b_params *init_params, tuple->vals = local_ctx_vals; local_ctx_vals = NULL; - b2bl_htable[hash_index].locked_by = process_no; - memset(&e1, 0, sizeof e1); memset(&e2, 0, sizeof e1); @@ -2806,15 +2772,13 @@ str* b2bl_init_extern(struct b2b_params *init_params, local_ctx_tuple = NULL; - b2bl_htable[hash_index].locked_by = -1; + B2BL_LOCK_RELEASE(hash_index); - lock_release(&b2bl_htable[hash_index].lock); return b2bl_key; error: if(tuple) { - b2bl_htable[hash_index].locked_by = -1; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); } local_ctx_tuple = NULL; return 0; @@ -2997,16 +2961,12 @@ str* b2b_process_scenario_init(struct sip_msg* msg, b2bl_cback_f cbf, goto error; } - b2bl_htable[hash_index].locked_by = process_no; - client_id = b2b_api.client_new(&ci, b2b_client_notify, b2b_add_dlginfo, &b2bl_mod_name, b2bl_key, get_tracer(tuple), NULL, NULL); pkg_free(to_uri.s); to_uri.s = 0; - b2bl_htable[hash_index].locked_by = -1; - if(client_id == NULL) { LM_ERR("failed to create new b2b client instance\n"); @@ -3049,7 +3009,7 @@ str* b2b_process_scenario_init(struct sip_msg* msg, b2bl_cback_f cbf, b2bl_htable[hash_index].flags = init_params->flags; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return b2bl_key; @@ -3057,7 +3017,7 @@ str* b2b_process_scenario_init(struct sip_msg* msg, b2bl_cback_f cbf, if(tuple) { b2bl_delete(tuple, hash_index, 1, 1); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); } if(to_uri.s) pkg_free(to_uri.s); @@ -3488,7 +3448,7 @@ int script_trigger_scenario(struct sip_msg* msg, str *id, str * params, tuple->bridge_flags = 0; } else { /* extract the entity and delete the tuple */ - lock_get(&b2bl_htable[remote_tuple_hash_index].lock); + B2BL_LOCK_GET(remote_tuple_hash_index); cur_tuple = b2bl_search_tuple_safe(remote_tuple_hash_index, local_index); if(cur_tuple == NULL) @@ -3510,10 +3470,10 @@ int script_trigger_scenario(struct sip_msg* msg, str *id, str * params, send_bridge_notify(cur_tuple->bridge_entities[remote_tuple_party], remote_tuple_hash_index, NULL); } } - lock_release(&b2bl_htable[remote_tuple_hash_index].lock); + B2BL_LOCK_RELEASE(remote_tuple_hash_index); } } else { - lock_get(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_GET(cur_route_ctx.hash_index); cur_tuple = b2bl_search_tuple_safe(cur_route_ctx.hash_index, cur_route_ctx.local_index); if(cur_tuple == NULL) { @@ -3529,7 +3489,7 @@ int script_trigger_scenario(struct sip_msg* msg, str *id, str * params, send_bridge_notify(entity, cur_route_ctx.hash_index, NULL); } } - lock_release(&b2bl_htable[cur_route_ctx.hash_index].lock); + B2BL_LOCK_RELEASE(cur_route_ctx.hash_index); } } LM_DBG("Flags: %u (NOTIFY: %u)\n", tuple->bridge_flags, B2BL_BR_FLAG_NOTIFY); @@ -3540,15 +3500,13 @@ int script_trigger_scenario(struct sip_msg* msg, str *id, str * params, goto error; } - b2bl_htable[hash_index].locked_by = -1; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); rc = 1; goto end; error: if(tuple) { - b2bl_htable[hash_index].locked_by = -1; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); } local_ctx_tuple = NULL; end: @@ -3728,13 +3686,13 @@ int b2bl_terminate_call(str* key) return -1; } - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); if(tuple == NULL) { LM_DBG("No entity found [%.*s]\n", key->len, key->s); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return -1; } @@ -3747,7 +3705,7 @@ int b2bl_terminate_call(str* key) local_ctx_tuple = NULL; - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return 0; } @@ -3763,13 +3721,13 @@ int b2bl_get_stats(str* key, b2bl_dlg_stat_t* stat) return -1; } - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); if(tuple == NULL) { LM_ERR("No entity found\n"); - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return -1; } @@ -3781,7 +3739,7 @@ int b2bl_get_stats(str* key, b2bl_dlg_stat_t* stat) stat->key.s = NULL; stat->key.len = 0; } - lock_release(&b2bl_htable[hash_index].lock); + B2BL_LOCK_RELEASE(hash_index); return 0; } diff --git a/modules/b2b_logic/records.c b/modules/b2b_logic/records.c index 9463c9c7d0c..944c1f08e31 100644 --- a/modules/b2b_logic/records.c +++ b/modules/b2b_logic/records.c @@ -246,8 +246,9 @@ b2bl_tuple_t* b2bl_insert_new(struct sip_msg* msg, unsigned int hash_index, tuple->state = B2B_INIT_BRIDGING_STATE; - if (repl_flag != TUPLE_REPL_RECV) - lock_get(&b2bl_htable[hash_index].lock); + if (repl_flag != TUPLE_REPL_RECV) { + B2BL_LOCK_GET(hash_index); + } if(local_index>= 0) /* a local index specified */ { @@ -359,8 +360,9 @@ b2bl_tuple_t* b2bl_insert_new(struct sip_msg* msg, unsigned int hash_index, shm_free(tuple); } - if (repl_flag != TUPLE_REPL_RECV) - lock_release(&b2bl_htable[hash_index].lock); + if (repl_flag != TUPLE_REPL_RECV) { + B2BL_LOCK_RELEASE(hash_index); + } return 0; } @@ -503,9 +505,7 @@ void b2bl_remove_single_entity(b2bl_entity_id_t *entity, b2bl_entity_id_t **head unsigned int hash_index) { unchain_ent(entity, head); - b2bl_htable[hash_index].locked_by = process_no; b2b_api.entity_delete(entity->type, &entity->key, entity->dlginfo, 0, 1); - b2bl_htable[hash_index].locked_by = -1; LM_DBG("destroying dlginfo=[%p]\n", entity->dlginfo); b2bl_free_entity(entity); @@ -532,9 +532,7 @@ void b2bl_delete_entity(b2bl_entity_id_t* entity, b2bl_tuple_t* tuple, LM_DBG("delete entity [%p]->[%.*s] from tuple [%.*s]\n", entity, entity->key.len, entity->key.s, tuple->key->len, tuple->key->s); if (b2be_del) { - b2bl_htable[hash_index].locked_by = process_no; b2b_api.entity_delete(entity->type, &entity->key, entity->dlginfo, 1, 1); - b2bl_htable[hash_index].locked_by = -1; } } else if (entity->key.len) @@ -682,9 +680,7 @@ void b2bl_delete(b2bl_tuple_t* tuple, unsigned int hash_index, if (e) { if (e->key.s && e->key.len && del_entities) { - b2bl_htable[hash_index].locked_by = process_no; b2b_api.entity_delete(e->type, &e->key, e->dlginfo, 0, 1); - b2bl_htable[hash_index].locked_by = -1; } b2bl_free_entity(e); } @@ -692,9 +688,7 @@ void b2bl_delete(b2bl_tuple_t* tuple, unsigned int hash_index, if (e) { if (e->key.s && e->key.len && del_entities) { - b2bl_htable[hash_index].locked_by = process_no; b2b_api.entity_delete(e->type, &e->key, e->dlginfo, 0, 1); - b2bl_htable[hash_index].locked_by = -1; } b2bl_free_entity(e); } @@ -996,11 +990,12 @@ b2bl_tuple_t *b2bl_get_tuple(str *key) if (b2bl_parse_key(key, &hash_index, &local_index) < 0) return NULL; - lock_get(&b2bl_htable[hash_index].lock); + B2BL_LOCK_GET_AUX(hash_index); tuple = b2bl_search_tuple_safe(hash_index, local_index); - if (!tuple) - lock_release(&b2bl_htable[hash_index].lock); + if (!tuple) { + B2BL_LOCK_RELEASE_AUX(hash_index); + } return tuple; }