[asterisk-commits] nadi: branch group/trunk-cm-csel-hash r47785 - /team/group/trunk-cm-csel-hash...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Nov 17 02:35:37 MST 2006


Author: nadi
Date: Fri Nov 17 03:35:36 2006
New Revision: 47785

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47785
Log:
use ast_atomic.. for glob_channel

Modified:
    team/group/trunk-cm-csel-hash/channels/chan_misdn.c

Modified: team/group/trunk-cm-csel-hash/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/group/trunk-cm-csel-hash/channels/chan_misdn.c?view=diff&rev=47785&r1=47784&r2=47785
==============================================================================
--- team/group/trunk-cm-csel-hash/channels/chan_misdn.c (original)
+++ team/group/trunk-cm-csel-hash/channels/chan_misdn.c Fri Nov 17 03:35:36 2006
@@ -163,7 +163,27 @@
 
 struct misdn_pvt {
 	struct statemachine *sm;
-	
+	struct misdn_bchannel *bc;
+	struct ast_channel *ast;
+
+	int ast_dsp;
+	struct ast_dsp *dsp;
+	struct ast_trans_pvt *trans;
+	struct ast_frame frame;
+	char ast_rd_buf[4096];
+	int pipe[2];
+
+	char context[BUFFERSIZE];
+	unsigned int l3id;
+	int addr;
+	int dropped_frame_cnt;
+	int other_pid;
+	struct misdn_pvt *other_pvt;
+	struct {
+		int port;
+		int channel;
+	} hold_info;
+
 	char allowed_bearers[BUFFERSIZE];
 	int need_queue_hangup;
 	int need_hangup;
@@ -186,26 +206,6 @@
 	int overlap_dial_task;
 	ast_mutex_t overlap_tv_lock;
 	struct timeval overlap_tv;
-
-	int pipe[2];
-	char ast_rd_buf[4096];
-	struct ast_frame frame;
-	int ast_dsp;
-	struct ast_dsp *dsp;
-	struct ast_trans_pvt *trans;
-	struct ast_channel *ast;
-	struct misdn_bchannel *bc;
-	struct {
-		int port;
-		int channel;
-	} hold_info;
-
-	unsigned int l3id;
-	int addr;
-	char context[BUFFERSIZE];
-	int dropped_frame_cnt;
-	int other_pid;
-	struct misdn_pvt *other_pvt;
 	const struct tone_zone_sound *ts;
 
 	int destroy_me;
@@ -244,10 +244,7 @@
 static int                    max_ports;
 static const int              prefformat = AST_FORMAT_ALAW;
 static char                   tracefile[BUFFERSIZE];
-static int                    g_config_initialized = 0;
-static int                    glob_channel = 0;
-
-static AST_RWLIST_HEAD_STATIC(pvt_list, misdn_pvt);
+static volatile int           glob_channel = 0;
 
 static char                ** misdn_key_vector = NULL;
 static int                    misdn_key_vector_size = 0;
@@ -262,6 +259,7 @@
                             * misdn_debug_only = NULL,
                             * misdn_ports;
 
+static AST_RWLIST_HEAD_STATIC(pvt_list, misdn_pvt);
 static AST_HASH_STR(, struct csel *) group_csel_hash;
 
 /* mISDN Configuration */
@@ -1190,7 +1188,7 @@
 			break;
 	}
 	AST_RWLIST_UNLOCK(&pvt_list);
-	
+
 	return p;
 }
 
@@ -1557,8 +1555,8 @@
 		if (tmp_port == port) break;
 		chan_offset += misdn_lib_port_is_pri(tmp_port) ? 30 : 2;	
 	}
-	ast_string_field_build(tmp, name, "%s/%d-u%d",
-						   misdn_type, chan_offset + (c < 0 ? 0 : c), glob_channel++);
+	ast_string_field_build(tmp, name, "%s/%d-u%d", misdn_type, chan_offset + (c < 0 ? 0 : c),
+						   ast_atomic_fetchadd_int(&glob_channel, 1));
 
 	chan_misdn_log(3, port, " --> updating channel name to [%s]\n", tmp->name);
 }
@@ -1799,7 +1797,7 @@
 		chan_misdn_log(2, 0, "Cannot hangup chan, no ch or no p->bc!\n");
 		return;
 	}
-	
+
 	port = p->bc ? p->bc->port : 0;
 	chan_misdn_log(2, port, "hangup_chan\n");
 
@@ -1882,7 +1880,7 @@
 	statemachine_set_state(p->sm, MISDN_HOLD_DISCONNECT);
 	ast_moh_stop(AST_BRIDGED_P(holded_p->ast));
 	statemachine_set_state(holded_p->sm, MISDN_CONNECTED);
-/* 	misdn_lib_transfer(holded_p->bc); */
+	/* 	misdn_lib_transfer(holded_p->bc); */
 	ast_channel_masquerade(holded_p->ast, AST_BRIDGED_P(p->ast));
 }
 
@@ -2121,12 +2119,8 @@
 
 static int misdn_reload (int fd, int argc, char *argv[])
 {
-	if (!g_config_initialized)
-		ast_log(LOG_WARNING, "chan_misdn is not initialized properly, still reloading?\n");
-	else {
-		ast_cli(fd, "Reloading mISDN Config\n");
-		config_reload();
-	}
+	ast_cli(fd, "Reloading mISDN Config\n");
+	config_reload();
 
 	return 0;
 }
@@ -2701,16 +2695,17 @@
 			break;
 		chan_offset += misdn_lib_port_is_pri(tmp_port) ? 30 : 2;	
 	}
-	
+
 	c = c < 0 ? 0 : c;
-	
+
 	if (callerid) 
 		ast_callerid_parse(callerid, &cid_name, &cid_num);
-	
-	tmp = ast_channel_alloc(1, state, cid_num, cid_name, "%s/%d-u%d", misdn_type, chan_offset + c, glob_channel++);
+
+	tmp = ast_channel_alloc(1, state, cid_num, cid_name, "%s/%d-u%d", misdn_type,
+							chan_offset + c, ast_atomic_fetchadd_int(&glob_channel, 1));
 	if (tmp) {
 		chan_misdn_log(2, 0, " --> * NEW CHANNEL dad:%s oad:%s\n", exten, callerid);
-		
+
 		tmp->nativeformats = prefformat;
 		tmp->readformat = format;
 		tmp->rawreadformat = format;
@@ -2839,7 +2834,7 @@
 		ast_log(LOG_WARNING, " --> !! Got Digit Event withut having bchannel Object\n");
 		return -1;
 	}
-	
+
 	chan_misdn_log(2, bc->port, "* IND : Digit %c\n", digit);
 
 	switch (statemachine_get_state(p->sm)) {
@@ -2956,7 +2951,7 @@
 
 	/** we should have l3id after sending setup **/
 	p->l3id = newbc->l3_id;
-	
+
 	if (r == -ENOCHAN) {
 		chan_misdn_log(0, port, " --> * Theres no Channel at the moment .. !\n");
 		chan_misdn_log(2, port, " --> * SEND: State Down pid:%d\n", newbc ? newbc->pid : -1);
@@ -3122,7 +3117,7 @@
 		chan_misdn_log(0, bc->port, "statemachine_run failed on AEVENT_HANGUP: %d!\n", re);
 		return -1;
 	}
-	
+
 	chan_misdn_log(2, bc->port, "Channel: %s hanguped new state:%s\n", ast->name,
 				   get_state_string(statemachine_get_state(p->sm)));
 
@@ -3203,7 +3198,7 @@
 		p->bc->hdlc = 0;
 		p->bc->nojitter = 1;
 	}
-	
+
 	misdn_lib_echo(p->bc, 0);
 	stop_indicate(p);
 
@@ -3213,7 +3208,7 @@
 	}
 
 	statemachine_run(p->sm, AEVENT_ANSWER);
-	
+
 	start_bc_tones(p);
 
 	return 0;
@@ -3340,7 +3335,7 @@
 		chan_misdn_log(5, p->bc->port, "faxdetect: detecting ... (no timeout)\n");
 		return process_ast_dsp(p, &p->frame);
 	}
-	
+
 	return p->ast_dsp ? process_ast_dsp(p, &p->frame) : &p->frame;
 }
 
@@ -3410,12 +3405,12 @@
 static int misdn_indication (struct ast_channel *ast, int cond, const void *data, size_t datalen)
 {
 	struct misdn_pvt *p;
-	
+
 	if (!ast || !(p = MISDN_ASTERISK_TECH_PVT(ast)) || !p->bc) {
 		ast_log(LOG_WARNING, "Returned -1 in misdn_indication\n");
 		return -1;
 	}
-	
+
 	chan_misdn_log(2, p->bc->port, "* IND : Indication [%d] from %s\n", cond, ast->exten);
 
 	switch (cond) {
@@ -3561,7 +3556,7 @@
 			}
 		}
 	}
-	
+
 	return RE_DEFAULT;
 }
 
@@ -3700,7 +3695,7 @@
 {
 	struct misdn_pvt *p = pvt;
 	struct misdn_bchannel *bc = p->bc;
-	
+
 	if (bc->channel) 
 		update_name(p->ast, bc->port, bc->channel);
 
@@ -3740,7 +3735,7 @@
 	p->l3id = p->bc->l3_id;
 	p->addr = p->bc->addr;
 	start_bc_tones(p);
-	
+
 	return RE_DEFAULT;
 }
 
@@ -3753,7 +3748,7 @@
 	/* we might not have an p->ast ptr here anymore */
 	chan_misdn_log(3, bc->port, " --> org:%d nt:%d, inbandavail:%d state:%d\n",
 				   p->orginator, bc->nt, misdn_inband_avail(bc), state);
-	
+
 	if (p->orginator == ORG_AST && !bc->nt && misdn_inband_avail(bc) && state != MISDN_CONNECTED) {
 		/* If there's inband information available (e.g. a recorded message saying what was wrong with the
 		 * dialled number, or perhaps even giving an alternative number, then play it instead of
@@ -3839,7 +3834,7 @@
 {
 	struct misdn_pvt *p = pvt;
 	struct misdn_bchannel *bc = p->bc;
-	
+
 	chan_misdn_log(2, bc->port, "Set State Ringing\n");
 	if (misdn_cap_is_speech(bc->capability) && misdn_inband_avail(bc)) {
 		chan_misdn_log(2, bc->port, "Starting tones, we have inband data.\n");
@@ -3875,11 +3870,11 @@
 static struct statemachine_handle_retval handle_mevent_release_complete (void *pvt, int state, int event)
 {
 	struct misdn_pvt *p = pvt;
-	
+
 	stop_bc_tones(p);
 	hangup_chan(p);
 	p->destroy_me = 1;
-	
+
 	return RE_DEFAULT;
 }
 
@@ -3900,7 +3895,7 @@
 {
 	struct misdn_pvt *p = pvt;
 	struct misdn_bchannel *bc = p->bc;
-		
+
 	print_facility(&bc->fac_in, bc);
 	switch (bc->fac_in.Function) {
 	case Fac_CD:
@@ -3964,12 +3959,12 @@
 		chan_misdn_log(-1, bc->port, "Hold not allowed for this port.\n");
 		return RE_STATE_EVENT(STATE_KEEP, EVENT_HOLD_REJECT);
 	}
-			
+
 	bridged = AST_BRIDGED_P(p->ast);
 	if (bridged) {
 		chan_misdn_log(2, bc->port, "Bridge partner is of type: %s\n", bridged->tech->type);
 		p->l3id = bc->l3_id;
-		
+
 		/* XXX This should queue an AST_CONTROL_HOLD frame on this channel
 		 * instead of starting moh on the bridged channel directly */
 		ast_moh_start(bridged, NULL, NULL);
@@ -4200,7 +4195,7 @@
 			export_chan(p->ast, bc, p);
 
 			misdn_pvt_queue(p) ;
-			
+
 			break; /* continue with statemachine */
 		}
 	case EVENT_NEW_BC:
@@ -4422,16 +4417,15 @@
 
 	misdn_tasks_destroy();
 
-	if (g_config_initialized) {
+	if (misdn_ports)
 		free(misdn_ports);
-		ast_cli_unregister_multiple(chan_misdn_clis, sizeof(chan_misdn_clis) / sizeof(struct ast_cli_entry));
-		ast_unregister_application("misdn_set_opt");
-		ast_unregister_application("misdn_facility");
-		ast_channel_unregister(&misdn_tech);
-		misdn_csel_destroy();
-		misdn_lib_destroy();
-		config_destroy();
-	}
+	ast_cli_unregister_multiple(chan_misdn_clis, sizeof(chan_misdn_clis) / sizeof(struct ast_cli_entry));
+	ast_unregister_application("misdn_set_opt");
+	ast_unregister_application("misdn_facility");
+	ast_channel_unregister(&misdn_tech);
+	misdn_csel_destroy();
+	misdn_lib_destroy();
+	config_destroy();
 
 	return 0;
 }
@@ -4461,7 +4455,7 @@
 
 	misdn_in_calls = calloc(max_ports + 1, sizeof(int));
 	misdn_out_calls = calloc(max_ports + 1, sizeof(int));
-	
+
 	for (*buf = 0, *ports = 0, prev = NULL; cm_get_next_id(misdn_cm, PORT, prev, &port); prev = &port) {
 		if (snprintf(buf, sizeof(buf), "%d,", port))
 			strncat(ports, buf, sizeof(ports) - strlen(ports) - 1);
@@ -4484,7 +4478,24 @@
 	cm_get(misdn_cm, buf, sizeof(buf), GENERAL, MCFG_NTDEBUGFILE);
 	misdn_lib_nt_debug_init(ntflags, buf);
 
-	ast_cli_register_multiple(chan_misdn_clis, sizeof(chan_misdn_clis) / sizeof(struct ast_cli_entry));
+	cm_get(misdn_cm, tracefile, sizeof(tracefile), GENERAL, MCFG_TRACEFILE);
+
+	misdn_ports = malloc(sizeof(int) * (max_ports + 1));
+	for (prev = NULL; cm_get_next_id(misdn_cm, PORT, prev, &port); prev = &port) {
+		misdn_ports[port] = port;
+		l1timeout = 0;
+		cm_get_int(misdn_cm, l1timeout, PORT, MCFG_L1WATCHER_TIMEOUT, port);
+		if (l1timeout) {
+			chan_misdn_log(4, 0, "Adding L1watcher task: port:%d timeout:%ds\n", port, l1timeout);
+			misdn_tasks_add(l1timeout * 1000, misdn_l1_task, &misdn_ports[port]);  
+		}
+	}
+
+	if (ast_channel_register(&misdn_tech)) {
+		ast_log(LOG_ERROR, "Unable to register channel class %s\n", misdn_type);
+		unload_module();
+		return -1;
+	}
 
 	ast_register_application("misdn_set_opt", misdn_set_opt_exec, "misdn_set_opt",
 							 "misdn_set_opt(:<opt><optarg>:<opt><optarg>..):\n"
@@ -4511,26 +4522,7 @@
 							 "type=calldeflect args=Nr where to deflect\n"
 							);
 
-	cm_get(misdn_cm, tracefile, sizeof(tracefile), GENERAL, MCFG_TRACEFILE);
-
-	misdn_ports = malloc(sizeof(int) * (max_ports + 1));
-	for (prev = NULL; cm_get_next_id(misdn_cm, PORT, prev, &port); prev = &port) {
-		misdn_ports[port] = port;
-		l1timeout = 0;
-		cm_get_int(misdn_cm, l1timeout, PORT, MCFG_L1WATCHER_TIMEOUT, port);
-		if (l1timeout) {
-			chan_misdn_log(4, 0, "Adding L1watcher task: port:%d timeout:%ds\n", port, l1timeout);
-			misdn_tasks_add(l1timeout * 1000, misdn_l1_task, &misdn_ports[port]);  
-		}
-	}
-
-	if (ast_channel_register(&misdn_tech)) {
-		ast_log(LOG_ERROR, "Unable to register channel class %s\n", misdn_type);
-		unload_module();
-		return -1;
-	}
-
-	g_config_initialized = 1;
+	ast_cli_register_multiple(chan_misdn_clis, sizeof(chan_misdn_clis) / sizeof(struct ast_cli_entry));
 
 	chan_misdn_log(0, 0, "-- mISDN Channel Driver Registered --\n");
 



More information about the asterisk-commits mailing list