[asterisk-commits] rmudgett: branch rmudgett/misdn_facility r188019 - /team/rmudgett/misdn_facil...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 10 19:26:10 CDT 2009


Author: rmudgett
Date: Fri Apr 10 19:26:07 2009
New Revision: 188019

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=188019
Log:
Converted to use the list macro's for the call completion database.

Modified:
    team/rmudgett/misdn_facility/channels/chan_misdn.c

Modified: team/rmudgett/misdn_facility/channels/chan_misdn.c
URL: http://svn.digium.com/svn-view/asterisk/team/rmudgett/misdn_facility/channels/chan_misdn.c?view=diff&rev=188019&r1=188018&r2=188019
==============================================================================
--- team/rmudgett/misdn_facility/channels/chan_misdn.c (original)
+++ team/rmudgett/misdn_facility/channels/chan_misdn.c Fri Apr 10 19:26:07 2009
@@ -152,7 +152,7 @@
 };
 
 /*! \brief Peer link guardian */
-ast_mutex_t misdn_peer_link_lock;
+AST_MUTEX_DEFINE_STATIC(misdn_peer_link_lock);
 /*! \brief mISDN peer link database */
 static struct misdn_peer_link misdn_peers[MISDN_PEER_LINKS_MAX];
 
@@ -169,8 +169,8 @@
 
 /*! \brief mISDN call completion record */
 struct misdn_cc_record {
-	/*! \brief Next record in linked list */
-	struct misdn_cc_record *next;
+	/*! \brief Call completion record linked list */
+	AST_LIST_ENTRY(misdn_cc_record) list;
 
 	/*! \brief Time the record was created. */
 	time_t time_created;
@@ -198,7 +198,7 @@
 			struct misdn_bchannel *bc;
 
 			/*!
-			 * \brief Nonzero if we requested the request retention option
+			 * \brief TRUE if we requested the request retention option
 			 * to be enabled.
 			 */
 			int requested_retention;
@@ -275,10 +275,8 @@
 	struct misdn_cc_notify b_free;
 };
 
-/*! \brief Call completion record guardian */
-ast_mutex_t misdn_cc_record_lock;
 /*! \brief mISDN call completion record database */
-static struct misdn_cc_record *misdn_cc_records;
+static AST_LIST_HEAD_STATIC(misdn_cc_records_db, misdn_cc_record);
 /*! \brief Next call completion record ID to use */
 static __u16 misdn_cc_record_id;
 /*! \brief Next invoke ID to use */
@@ -840,13 +838,13 @@
  * \retval pointer to found call completion record
  * \retval NULL if not found
  *
- * \note Assumes the misdn_cc_record_lock is already obtained.
+ * \note Assumes the misdn_cc_records_db lock is already obtained.
  */
 static struct misdn_cc_record *misdn_cc_find_by_id(long record_id)
 {
 	struct misdn_cc_record *current;
 
-	for (current = misdn_cc_records; current; current = current->next) {
+	AST_LIST_TRAVERSE(&misdn_cc_records_db, current, list) {
 		if (current->record_id == record_id) {
 			/* Found the record */
 			break;
@@ -868,13 +866,13 @@
  * \retval pointer to found call completion record
  * \retval NULL if not found
  *
- * \note Assumes the misdn_cc_record_lock is already obtained.
+ * \note Assumes the misdn_cc_records_db lock is already obtained.
  */
 static struct misdn_cc_record *misdn_cc_find_by_linkage(int port, int linkage_id)
 {
 	struct misdn_cc_record *current;
 
-	for (current = misdn_cc_records; current; current = current->next) {
+	AST_LIST_TRAVERSE(&misdn_cc_records_db, current, list) {
 		if (current->port == port
 			&& !current->ptp
 			&& current->mode.ptmp.linkage_id == linkage_id) {
@@ -898,13 +896,13 @@
  * \retval pointer to found call completion record
  * \retval NULL if not found
  *
- * \note Assumes the misdn_cc_record_lock is already obtained.
+ * \note Assumes the misdn_cc_records_db lock is already obtained.
  */
 static struct misdn_cc_record *misdn_cc_find_by_invoke(int port, int invoke_id)
 {
 	struct misdn_cc_record *current;
 
-	for (current = misdn_cc_records; current; current = current->next) {
+	AST_LIST_TRAVERSE(&misdn_cc_records_db, current, list) {
 		if (current->outstanding_message
 			&& current->invoke_id == invoke_id
 			&& current->port == port) {
@@ -928,13 +926,13 @@
  * \retval pointer to found call completion record
  * \retval NULL if not found
  *
- * \note Assumes the misdn_cc_record_lock is already obtained.
+ * \note Assumes the misdn_cc_records_db lock is already obtained.
  */
 static struct misdn_cc_record *misdn_cc_find_by_reference(int port, int reference_id)
 {
 	struct misdn_cc_record *current;
 
-	for (current = misdn_cc_records; current; current = current->next) {
+	AST_LIST_TRAVERSE(&misdn_cc_records_db, current, list) {
 		if (current->activated
 			&& current->port == port
 			&& !current->ptp
@@ -958,14 +956,14 @@
  * \retval pointer to found call completion record
  * \retval NULL if not found
  *
- * \note Assumes the misdn_cc_record_lock is already obtained.
+ * \note Assumes the misdn_cc_records_db lock is already obtained.
  */
 static struct misdn_cc_record *misdn_cc_find_by_bc(const struct misdn_bchannel *bc)
 {
 	struct misdn_cc_record *current;
 
 	if (bc) {
-		for (current = misdn_cc_records; current; current = current->next) {
+		AST_LIST_TRAVERSE(&misdn_cc_records_db, current, list) {
 			if (current->ptp
 				&& current->mode.ptp.bc == bc) {
 				/* Found the record */
@@ -989,22 +987,20 @@
  *
  * \return Nothing
  *
- * \note Assumes the misdn_cc_record_lock is already obtained.
+ * \note Assumes the misdn_cc_records_db lock is already obtained.
  */
 static void misdn_cc_delete(struct misdn_cc_record *doomed)
 {
 	struct misdn_cc_record *current;
-	struct misdn_cc_record **prev;
-
-	prev = &misdn_cc_records;
-	for (current = misdn_cc_records; current; current = current->next) {
+
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&misdn_cc_records_db, current, list) {
 		if (current == doomed) {
-			*prev = doomed->next;
-			ast_free(doomed);
+			AST_LIST_REMOVE_CURRENT(list);
+			ast_free(current);
 			return;
 		}
-		prev = &current->next;
-	}
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
 
 	/* The doomed node is not in the call completion database */
 }
@@ -1017,17 +1013,15 @@
  *
  * \return Nothing
  *
- * \note Assumes the misdn_cc_record_lock is already obtained.
+ * \note Assumes the misdn_cc_records_db lock is already obtained.
  */
 static void misdn_cc_remove_old(void)
 {
 	struct misdn_cc_record *current;
-	struct misdn_cc_record **prev;
 	time_t now;
 
 	now = time(NULL);
-	prev = &misdn_cc_records;
-	for (current = misdn_cc_records; current;) {
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&misdn_cc_records_db, current, list) {
 		if (MISDN_CC_RECORD_AGE_MAX < now - current->time_created) {
 			if (current->ptp && current->mode.ptp.bc) {
 				/* Close the old call-completion signaling link */
@@ -1037,14 +1031,11 @@
 			}
 
 			/* Remove the old call completion record */
-			*prev = current->next;
+			AST_LIST_REMOVE_CURRENT(list);
 			ast_free(current);
-			current = *prev;
-		} else {
-			prev = &current->next;
-			current = current->next;
-		}
-	}
+		}
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
 }
 #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 
@@ -1056,7 +1047,7 @@
  * \retval New record id on success.
  * \retval -1 on error.
  *
- * \note Assumes the misdn_cc_record_lock is already obtained.
+ * \note Assumes the misdn_cc_records_db lock is already obtained.
  */
 static long misdn_cc_record_id_new(void)
 {
@@ -1090,7 +1081,7 @@
  * \retval pointer to new call completion record
  * \retval NULL if failed
  *
- * \note Assumes the misdn_cc_record_lock is already obtained.
+ * \note Assumes the misdn_cc_records_db lock is already obtained.
  */
 static struct misdn_cc_record *misdn_cc_new(void)
 {
@@ -1117,8 +1108,7 @@
 		cc_record->time_created = time(NULL);
 
 		/* Insert the new record into the database */
-		cc_record->next = misdn_cc_records;
-		misdn_cc_records = cc_record;
+		AST_LIST_INSERT_HEAD(&misdn_cc_records_db, cc_record, list);
 	}
 	return cc_record;
 }
@@ -1133,10 +1123,14 @@
  */
 static void misdn_cc_destroy(void)
 {
-	ast_mutex_destroy(&misdn_cc_record_lock);
-	while (misdn_cc_records) {
-		misdn_cc_delete(misdn_cc_records);
-	}
+	struct misdn_cc_record *current;
+
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&misdn_cc_records_db, current, list) {
+		/* Do a misdn_cc_delete(current) inline */
+		AST_LIST_REMOVE_CURRENT(list);
+		ast_free(current);
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
 }
 #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 
@@ -1149,9 +1143,7 @@
  */
 static void misdn_cc_init(void)
 {
-	misdn_cc_records = NULL;
 	misdn_cc_record_id = 0;
-	ast_mutex_init(&misdn_cc_record_lock);
 }
 #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 
@@ -1170,7 +1162,7 @@
 	int not_responded;
 	struct misdn_cc_record *cc_record;
 
-	ast_mutex_lock(&misdn_cc_record_lock);
+	AST_LIST_LOCK(&misdn_cc_records_db);
 	cc_record = misdn_cc_find_by_id(*(long *) data);
 	if (cc_record) {
 		if (cc_record->outstanding_message) {
@@ -1182,7 +1174,7 @@
 		/* No record so there is no response to check. */
 		not_responded = 0;
 	}
-	ast_mutex_unlock(&misdn_cc_record_lock);
+	AST_LIST_UNLOCK(&misdn_cc_records_db);
 
 	return not_responded;
 }
@@ -6253,10 +6245,10 @@
 		struct misdn_cc_record *cc_record;
 
 		/* This is a call completion retry call */
-		ast_mutex_lock(&misdn_cc_record_lock);
+		AST_LIST_LOCK(&misdn_cc_records_db);
 		cc_record = misdn_cc_find_by_id(ch->record_id);
 		if (!cc_record) {
-			ast_mutex_unlock(&misdn_cc_record_lock);
+			AST_LIST_UNLOCK(&misdn_cc_records_db);
 			ast_log(LOG_WARNING, " --> ! misdn_call called on %s, cc_record==NULL\n", ast->name);
 			ast->hangupcause = AST_CAUSE_NORMAL_TEMPORARY_FAILURE;
 			ast_setstate(ast, AST_STATE_DOWN);
@@ -6279,7 +6271,7 @@
 			newbc->fac_out.u.CCBSCall.InvokeID = ++misdn_invoke_id;
 			newbc->fac_out.u.CCBSCall.CCBSReference = cc_record->mode.ptmp.reference_id;
 		}
-		ast_mutex_unlock(&misdn_cc_record_lock);
+		AST_LIST_UNLOCK(&misdn_cc_records_db);
 
 		ast_copy_string(ast->exten, newbc->dialed.number, sizeof(ast->exten));
 
@@ -7449,22 +7441,22 @@
 		}
 		record_id = atol(args.ext);
 
-		ast_mutex_lock(&misdn_cc_record_lock);
+		AST_LIST_LOCK(&misdn_cc_records_db);
 		cc_record = misdn_cc_find_by_id(record_id);
 		if (!cc_record) {
-			ast_mutex_unlock(&misdn_cc_record_lock);
+			AST_LIST_UNLOCK(&misdn_cc_records_db);
 			err_msg = misdn_cc_record_not_found;
 			ast_log(LOG_WARNING, " --> ! IND : Dial(%s) %s.\n", dial_str, err_msg);
 			return NULL;
 		}
 		if (!cc_record->activated) {
-			ast_mutex_unlock(&misdn_cc_record_lock);
+			AST_LIST_UNLOCK(&misdn_cc_records_db);
 			err_msg = "Call completion has not been activated";
 			ast_log(LOG_WARNING, " --> ! IND : Dial(%s) %s.\n", dial_str, err_msg);
 			return NULL;
 		}
 		port = cc_record->port;
-		ast_mutex_unlock(&misdn_cc_record_lock);
+		AST_LIST_UNLOCK(&misdn_cc_records_db);
 	}
 #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 
@@ -8294,7 +8286,7 @@
 		dummy.fac_out.u.CCBSStatusRequest.ComponentType = FacComponent_Result;
 
 		/* Answer User-A free question */
-		ast_mutex_lock(&misdn_cc_record_lock);
+		AST_LIST_LOCK(&misdn_cc_records_db);
 		cc_record = misdn_cc_find_by_reference(port, facility->u.CCBSStatusRequest.Component.Invoke.CCBSReference);
 		if (cc_record) {
 			dummy.fac_out.u.CCBSStatusRequest.Component.Result.Free = cc_record->party_a_free;
@@ -8302,7 +8294,7 @@
 			/* No record so say User-A is free */
 			dummy.fac_out.u.CCBSStatusRequest.Component.Result.Free = 1;
 		}
-		ast_mutex_unlock(&misdn_cc_record_lock);
+		AST_LIST_UNLOCK(&misdn_cc_records_db);
 
 		/* Send message */
 		print_facility(&dummy.fac_out, &dummy);
@@ -8372,7 +8364,7 @@
 	struct misdn_cc_notify notify;
 	long record_id;
 
-	ast_mutex_lock(&misdn_cc_record_lock);
+	AST_LIST_LOCK(&misdn_cc_records_db);
 	cc_record = misdn_cc_find_by_bc(bc);
 	if (cc_record) {
 		if (cc_record->party_a_free) {
@@ -8387,13 +8379,13 @@
 			notify = cc_record->b_free;
 		}
 		record_id = cc_record->record_id;
-		ast_mutex_unlock(&misdn_cc_record_lock);
+		AST_LIST_UNLOCK(&misdn_cc_records_db);
 		if (notify.context[0]) {
 			/* Party A is free or B-Free notify has been setup. */
 			misdn_cc_pbx_notify(record_id, &notify);
 		}
 	} else {
-		ast_mutex_unlock(&misdn_cc_record_lock);
+		AST_LIST_UNLOCK(&misdn_cc_records_db);
 	}
 }
 #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
@@ -8414,15 +8406,15 @@
 	struct misdn_cc_notify notify;
 	long record_id;
 
-	ast_mutex_lock(&misdn_cc_record_lock);
+	AST_LIST_LOCK(&misdn_cc_records_db);
 	cc_record = misdn_cc_find_by_reference(port, facility->u.CCBSRemoteUserFree.CCBSReference);
 	if (cc_record) {
 		notify = cc_record->remote_user_free;
 		record_id = cc_record->record_id;
-		ast_mutex_unlock(&misdn_cc_record_lock);
+		AST_LIST_UNLOCK(&misdn_cc_records_db);
 		misdn_cc_pbx_notify(record_id, &notify);
 	} else {
-		ast_mutex_unlock(&misdn_cc_record_lock);
+		AST_LIST_UNLOCK(&misdn_cc_records_db);
 	}
 }
 #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
@@ -8443,16 +8435,16 @@
 	struct misdn_cc_notify notify;
 	long record_id;
 
-	ast_mutex_lock(&misdn_cc_record_lock);
+	AST_LIST_LOCK(&misdn_cc_records_db);
 	cc_record = misdn_cc_find_by_reference(port, facility->u.CCBSBFree.CCBSReference);
 	if (cc_record && cc_record->b_free.context[0]) {
 		/* B-Free notify has been setup. */
 		notify = cc_record->b_free;
 		record_id = cc_record->record_id;
-		ast_mutex_unlock(&misdn_cc_record_lock);
+		AST_LIST_UNLOCK(&misdn_cc_records_db);
 		misdn_cc_pbx_notify(record_id, &notify);
 	} else {
-		ast_mutex_unlock(&misdn_cc_record_lock);
+		AST_LIST_UNLOCK(&misdn_cc_records_db);
 	}
 }
 #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
@@ -8716,13 +8708,13 @@
 		default:
 			break;
 		}
-		ast_mutex_lock(&misdn_cc_record_lock);
+		AST_LIST_LOCK(&misdn_cc_records_db);
 		cc_record = misdn_cc_find_by_invoke(bc->port, bc->fac_in.u.ERROR.invokeId);
 		if (cc_record) {
 			cc_record->outstanding_message = 0;
 			cc_record->error_code = bc->fac_in.u.ERROR.errorValue;
 		}
-		ast_mutex_unlock(&misdn_cc_record_lock);
+		AST_LIST_UNLOCK(&misdn_cc_records_db);
 		break;
 	case Fac_REJECT:
 		diagnostic_msg = misdn_to_str_reject_code(bc->fac_in.u.REJECT.Code);
@@ -8740,22 +8732,22 @@
 			break;
 		}
 		if (bc->fac_in.u.REJECT.InvokeIDPresent) {
-			ast_mutex_lock(&misdn_cc_record_lock);
+			AST_LIST_LOCK(&misdn_cc_records_db);
 			cc_record = misdn_cc_find_by_invoke(bc->port, bc->fac_in.u.REJECT.InvokeID);
 			if (cc_record) {
 				cc_record->outstanding_message = 0;
 				cc_record->reject_code = bc->fac_in.u.REJECT.Code;
 			}
-			ast_mutex_unlock(&misdn_cc_record_lock);
+			AST_LIST_UNLOCK(&misdn_cc_records_db);
 		}
 		break;
 	case Fac_RESULT:
-		ast_mutex_lock(&misdn_cc_record_lock);
+		AST_LIST_LOCK(&misdn_cc_records_db);
 		cc_record = misdn_cc_find_by_invoke(bc->port, bc->fac_in.u.RESULT.InvokeID);
 		if (cc_record) {
 			cc_record->outstanding_message = 0;
 		}
-		ast_mutex_unlock(&misdn_cc_record_lock);
+		AST_LIST_UNLOCK(&misdn_cc_records_db);
 		break;
 #if 0	/* We don't handle this yet */
 	case Fac_EctExecute:
@@ -8802,7 +8794,7 @@
 		case EVENT_DISCONNECT:
 			/* CCBS/CCNR is available */
 			if (ch && ch->peer) {
-				ast_mutex_lock(&misdn_cc_record_lock);
+				AST_LIST_LOCK(&misdn_cc_records_db);
 				if (ch->record_id == -1) {
 					cc_record = misdn_cc_new();
 				} else {
@@ -8880,7 +8872,7 @@
 					cc_record->redial.capability = bc->capability;
 					cc_record->redial.hdlc = bc->hdlc;
 				}
-				ast_mutex_unlock(&misdn_cc_record_lock);
+				AST_LIST_UNLOCK(&misdn_cc_records_db);
 
 				/* Set MISDN_CC_RECORD_ID in original channel */
 				if (ch->record_id != -1) {
@@ -8916,12 +8908,12 @@
 	case Fac_CCBSDeactivate:
 		switch (bc->fac_in.u.CCBSDeactivate.ComponentType) {
 		case FacComponent_Result:
-			ast_mutex_lock(&misdn_cc_record_lock);
+			AST_LIST_LOCK(&misdn_cc_records_db);
 			cc_record = misdn_cc_find_by_invoke(bc->port, bc->fac_in.u.CCBSDeactivate.InvokeID);
 			if (cc_record) {
 				cc_record->outstanding_message = 0;
 			}
-			ast_mutex_unlock(&misdn_cc_record_lock);
+			AST_LIST_UNLOCK(&misdn_cc_records_db);
 			break;
 
 		default:
@@ -8931,12 +8923,12 @@
 		}
 		break;
 	case Fac_CCBSErase:
-		ast_mutex_lock(&misdn_cc_record_lock);
+		AST_LIST_LOCK(&misdn_cc_records_db);
 		cc_record = misdn_cc_find_by_reference(bc->port, bc->fac_in.u.CCBSErase.CCBSReference);
 		if (cc_record) {
 			misdn_cc_delete(cc_record);
 		}
-		ast_mutex_unlock(&misdn_cc_record_lock);
+		AST_LIST_UNLOCK(&misdn_cc_records_db);
 		break;
 	case Fac_CCBSRemoteUserFree:
 		misdn_cc_handle_remote_user_free(bc->port, &bc->fac_in);
@@ -8948,7 +8940,7 @@
 		misdn_cc_handle_ccbs_status_request(bc->port, &bc->fac_in);
 		break;
 	case Fac_EraseCallLinkageID:
-		ast_mutex_lock(&misdn_cc_record_lock);
+		AST_LIST_LOCK(&misdn_cc_records_db);
 		cc_record = misdn_cc_find_by_linkage(bc->port,
 			bc->fac_in.u.EraseCallLinkageID.CallLinkageID);
 		if (cc_record && !cc_record->activation_requested) {
@@ -8959,7 +8951,7 @@
 			 */
 			misdn_cc_delete(cc_record);
 		}
-		ast_mutex_unlock(&misdn_cc_record_lock);
+		AST_LIST_UNLOCK(&misdn_cc_records_db);
 		break;
 	case Fac_CCBSStopAlerting:
 		/* We do not have anything to do for this message. */
@@ -8968,7 +8960,7 @@
 	case Fac_CCNRRequest:
 		switch (bc->fac_in.u.CCBSRequest.ComponentType) {
 		case FacComponent_Result:
-			ast_mutex_lock(&misdn_cc_record_lock);
+			AST_LIST_LOCK(&misdn_cc_records_db);
 			cc_record = misdn_cc_find_by_invoke(bc->port, bc->fac_in.u.CCBSRequest.InvokeID);
 			if (cc_record && !cc_record->ptp) {
 				cc_record->outstanding_message = 0;
@@ -8976,7 +8968,7 @@
 				cc_record->mode.ptmp.recall_mode = bc->fac_in.u.CCBSRequest.Component.Result.RecallMode;
 				cc_record->mode.ptmp.reference_id = bc->fac_in.u.CCBSRequest.Component.Result.CCBSReference;
 			}
-			ast_mutex_unlock(&misdn_cc_record_lock);
+			AST_LIST_UNLOCK(&misdn_cc_records_db);
 			break;
 
 		default:
@@ -9011,7 +9003,7 @@
 			if (ch && ch->peer) {
 				int set_id = 1;
 
-				ast_mutex_lock(&misdn_cc_record_lock);
+				AST_LIST_LOCK(&misdn_cc_records_db);
 				if (ch->record_id == -1) {
 					cc_record = misdn_cc_new();
 				} else {
@@ -9093,7 +9085,7 @@
 					cc_record->redial.capability = bc->capability;
 					cc_record->redial.hdlc = bc->hdlc;
 				}
-				ast_mutex_unlock(&misdn_cc_record_lock);
+				AST_LIST_UNLOCK(&misdn_cc_records_db);
 
 				/* Set MISDN_CC_RECORD_ID in original channel */
 				if (ch->record_id != -1 && set_id) {
@@ -9115,7 +9107,7 @@
 	case Fac_CCNR_T_Request:
 		switch (bc->fac_in.u.CCBS_T_Request.ComponentType) {
 		case FacComponent_Result:
-			ast_mutex_lock(&misdn_cc_record_lock);
+			AST_LIST_LOCK(&misdn_cc_records_db);
 			cc_record = misdn_cc_find_by_invoke(bc->port, bc->fac_in.u.CCBS_T_Request.InvokeID);
 			if (cc_record && cc_record->ptp) {
 				cc_record->outstanding_message = 0;
@@ -9126,7 +9118,7 @@
 					? 1 : 0
 					: 0;
 			}
-			ast_mutex_unlock(&misdn_cc_record_lock);
+			AST_LIST_UNLOCK(&misdn_cc_records_db);
 			break;
 
 		case FacComponent_Invoke:
@@ -9780,7 +9772,7 @@
 			 * We will not wait/depend on the network to tell
 			 * us to delete it.
 			 */
-			ast_mutex_lock(&misdn_cc_record_lock);
+			AST_LIST_LOCK(&misdn_cc_records_db);
 			cc_record = misdn_cc_find_by_id(ch->record_id);
 			if (cc_record) {
 				if (cc_record->ptp && cc_record->mode.ptp.bc) {
@@ -9791,7 +9783,7 @@
 				}
 				misdn_cc_delete(cc_record);
 			}
-			ast_mutex_unlock(&misdn_cc_record_lock);
+			AST_LIST_UNLOCK(&misdn_cc_records_db);
 			ch->record_id = -1;
 			if (ch->peer) {
 				pbx_builtin_setvar_helper(ch->peer, MISDN_CC_RECORD_ID, "");
@@ -9913,13 +9905,13 @@
 			 * REGISTER does not have a struct chan_list record
 			 * associated with it.
 			 */
-			ast_mutex_lock(&misdn_cc_record_lock);
+			AST_LIST_LOCK(&misdn_cc_records_db);
 			cc_record = misdn_cc_find_by_bc(bc);
 			if (cc_record) {
 				/* The call-completion signaling link is closed. */
 				misdn_cc_delete(cc_record);
 			}
-			ast_mutex_unlock(&misdn_cc_record_lock);
+			AST_LIST_UNLOCK(&misdn_cc_records_db);
 #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 		}
 
@@ -10280,7 +10272,7 @@
 		return -1;
 	}
 
-	ast_mutex_lock(&misdn_cc_record_lock);
+	AST_LIST_LOCK(&misdn_cc_records_db);
 	cc_record = misdn_cc_find_by_id(atoi(args.cc_id));
 	if (cc_record) {
 		if (!strcasecmp("a-all", args.get_name)) {
@@ -10321,12 +10313,12 @@
 		} else if (!strcasecmp("busy-notify-context", args.get_name)) {
 			ast_copy_string(buf, cc_record->b_free.context, size);
 		} else {
-			ast_mutex_unlock(&misdn_cc_record_lock);
+			AST_LIST_UNLOCK(&misdn_cc_records_db);
 			ast_log(LOG_ERROR, "Function '%s': Unknown what-to-get '%s'.\n", function_name, args.get_name);
 			return -1;
 		}
 	}
-	ast_mutex_unlock(&misdn_cc_record_lock);
+	AST_LIST_UNLOCK(&misdn_cc_records_db);
 
 	return 0;
 }
@@ -10400,7 +10392,6 @@
  	ast_free(misdn_ports);
 
 #if defined(AST_MISDN_ENHANCEMENTS)
-	ast_mutex_destroy(&misdn_peer_link_lock);
 	misdn_cc_destroy();
 #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 
@@ -10434,7 +10425,6 @@
 	g_config_initialized = 1;
 
 #if defined(AST_MISDN_ENHANCEMENTS)
-	ast_mutex_init(&misdn_peer_link_lock);
 	misdn_cc_init();
 #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 
@@ -10679,7 +10669,7 @@
 	}
 	record_id = atol(subcommand->arg[0]);
 
-	ast_mutex_lock(&misdn_cc_record_lock);
+	AST_LIST_LOCK(&misdn_cc_records_db);
 	cc_record = misdn_cc_find_by_id(record_id);
 	if (cc_record && 0 <= cc_record->port) {
 		if (cc_record->ptp) {
@@ -10709,12 +10699,12 @@
 			misdn_lib_send_event(&dummy, EVENT_FACILITY);
 		}
 	}
-	ast_mutex_unlock(&misdn_cc_record_lock);
+	AST_LIST_UNLOCK(&misdn_cc_records_db);
 
 	/* Wait for the response to the call completion deactivation request. */
 	misdn_cc_response_wait(chan, MISDN_CC_REQUEST_WAIT_MAX, record_id);
 
-	ast_mutex_lock(&misdn_cc_record_lock);
+	AST_LIST_LOCK(&misdn_cc_records_db);
 	cc_record = misdn_cc_find_by_id(record_id);
 	if (cc_record) {
 		if (cc_record->port < 0) {
@@ -10735,7 +10725,7 @@
 	} else {
 		error_str = NULL;
 	}
-	ast_mutex_unlock(&misdn_cc_record_lock);
+	AST_LIST_UNLOCK(&misdn_cc_records_db);
 	if (error_str) {
 		ast_verb(1, "%s(%s) diagnostic '%s' on channel %s\n",
 			misdn_command_name, subcommand->name, error_str, chan->name);
@@ -10785,7 +10775,7 @@
 		return -1;
 	}
 
-	ast_mutex_lock(&misdn_cc_record_lock);
+	AST_LIST_LOCK(&misdn_cc_records_db);
 	cc_record = misdn_cc_find_by_id(record_id);
 	if (cc_record && cc_record->party_a_free != party_a_free) {
 		/* User-A's status has changed */
@@ -10810,7 +10800,7 @@
 			misdn_lib_send_event(bc, EVENT_FACILITY);
 		}
 	}
-	ast_mutex_unlock(&misdn_cc_record_lock);
+	AST_LIST_UNLOCK(&misdn_cc_records_db);
 
 	return 0;
 }
@@ -10861,7 +10851,7 @@
 	exten = subcommand->arg[2];
 	priority = atoi(subcommand->arg[3]);
 
-	ast_mutex_lock(&misdn_cc_record_lock);
+	AST_LIST_LOCK(&misdn_cc_records_db);
 	cc_record = misdn_cc_find_by_id(record_id);
 	if (cc_record) {
 		/* Save User-B free information */
@@ -10869,7 +10859,7 @@
 		ast_copy_string(cc_record->b_free.exten, exten, sizeof(cc_record->b_free.exten));
 		cc_record->b_free.priority = priority;
 	}
-	ast_mutex_unlock(&misdn_cc_record_lock);
+	AST_LIST_UNLOCK(&misdn_cc_records_db);
 
 	return 0;
 }
@@ -10934,7 +10924,7 @@
 	exten = subcommand->arg[2];
 	priority = atoi(subcommand->arg[3]);
 
-	ast_mutex_lock(&misdn_cc_record_lock);
+	AST_LIST_LOCK(&misdn_cc_records_db);
 	cc_record = misdn_cc_find_by_id(record_id);
 	if (cc_record) {
 		/* Save User-B free information */
@@ -10958,7 +10948,7 @@
 
 						misdn_cfg_get(bc->port, MISDN_CFG_CC_REQUEST_RETENTION,
 							&request_retention, sizeof(request_retention));
-						cc_record->mode.ptp.requested_retention = request_retention;
+						cc_record->mode.ptp.requested_retention = request_retention ? 1 : 0;
 
 						/* Build message */
 						bc->fac_out.Function = request->ptp;
@@ -11010,12 +11000,12 @@
 			}
 		}
 	}
-	ast_mutex_unlock(&misdn_cc_record_lock);
+	AST_LIST_UNLOCK(&misdn_cc_records_db);
 
 	/* Wait for the response to the call completion request. */
 	misdn_cc_response_wait(chan, MISDN_CC_REQUEST_WAIT_MAX, record_id);
 
-	ast_mutex_lock(&misdn_cc_record_lock);
+	AST_LIST_LOCK(&misdn_cc_records_db);
 	cc_record = misdn_cc_find_by_id(record_id);
 	if (cc_record) {
 		if (!cc_record->activated) {
@@ -11055,7 +11045,7 @@
 	} else {
 		error_str = misdn_cc_record_not_found;
 	}
-	ast_mutex_unlock(&misdn_cc_record_lock);
+	AST_LIST_UNLOCK(&misdn_cc_records_db);
 	if (error_str) {
 		ast_verb(1, "%s(%s) diagnostic '%s' on channel %s\n",
 			misdn_command_name, subcommand->name, error_str, chan->name);




More information about the asterisk-commits mailing list