[asterisk-commits] branch crichter/0.4.0 r37337 - /team/crichter/0.4.0/channels/chan_misdn.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Jul 10 09:24:02 MST 2006


Author: crichter
Date: Mon Jul 10 11:24:01 2006
New Revision: 37337

URL: http://svn.digium.com/view/asterisk?rev=37337&view=rev
Log:
added some semaphore magic to get rid of a hack on init.

Modified:
    team/crichter/0.4.0/channels/chan_misdn.c

Modified: team/crichter/0.4.0/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/chan_misdn.c?rev=37337&r1=37336&r2=37337&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/chan_misdn.c (original)
+++ team/crichter/0.4.0/channels/chan_misdn.c Mon Jul 10 11:24:01 2006
@@ -39,6 +39,8 @@
 #include <sys/ioctl.h>
 #include <signal.h>
 #include <sys/file.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
 
 #include <asterisk/channel.h>
 #include <asterisk/config.h>
@@ -249,6 +251,7 @@
 /* the main schedule context for stuff like l1 watcher, overlap dial, ... */
 static struct sched_context *misdn_tasks = NULL;
 static pthread_t misdn_tasks_thread;
+static int misdn_tasks_semid;
 
 static void chan_misdn_log(int level, int port, char *tmpl, ...);
 
@@ -431,21 +434,27 @@
 }
 /*************** Helpers END *************/
 
-static void sighandler(int sig) {
-	return;
-} 
+static void sighandler(int sig)
+{}
 
 static void* misdn_tasks_thread_func (void *data)
 {
 	int wait;
-
 	struct sigaction sa;
+	struct sembuf semb = {
+		.sem_num = 0,
+		.sem_op = 1,
+		.sem_flg = 0
+	};
+
 	sa.sa_handler = sighandler;
 	sa.sa_flags = SA_NODEFER;
 	sigemptyset(&sa.sa_mask);
 	sigaddset(&sa.sa_mask, SIGUSR1);
 	sigaction(SIGUSR1, &sa, NULL);
 	
+	semop(misdn_tasks_semid, &semb, 1);
+
 	while (1) {
 		wait = ast_sched_wait(misdn_tasks);
 		if (wait < 0)
@@ -459,9 +468,44 @@
 
 static void misdn_tasks_init (void)
 {
+	key_t key;
+	union {
+		int val;
+		struct semid_ds *buf;
+		unsigned short *array;
+		struct seminfo *__buf;
+	} semu;
+	struct sembuf semb = {
+		.sem_num = 0,
+		.sem_op = -1,
+		.sem_flg = 0
+	};
+	
 	chan_misdn_log(4, 0, "Starting misdn_tasks thread\n");
+	
+	key = ftok("/etc/asterisk/misdn.conf", 'E');
+	if (key == -1) {
+		perror("chan_misdn: Failed to create a semaphore key!");
+		exit(1);
+	}
+
+	misdn_tasks_semid = semget(key, 10, 0666 | IPC_CREAT);
+	if (misdn_tasks_semid == -1) {
+		perror("chan_misdn: Failed to get a semaphore!");
+		exit(1);
+	}
+
+	semu.val = 0;
+	if (semctl(misdn_tasks_semid, 0, SETVAL, semu) == -1) {
+		perror("chan_misdn: Failed to initialize semaphore!");
+		exit(1);
+	}
+
 	misdn_tasks = sched_context_create();
 	pthread_create(&misdn_tasks_thread, NULL, misdn_tasks_thread_func, NULL);
+
+	semop(misdn_tasks_semid, &semb, 1);
+	semctl(misdn_tasks_semid, 0, IPC_RMID, semu);
 }
 
 static void misdn_tasks_destroy (void)



More information about the asterisk-commits mailing list