[asterisk-commits] nadi: branch crichter/0.4.0 r38851 - /team/crichter/0.4.0/channels/chan_misdn.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Aug 4 01:48:25 MST 2006


Author: nadi
Date: Fri Aug  4 03:48:17 2006
New Revision: 38851

URL: http://svn.digium.com/view/asterisk?rev=38851&view=rev
Log:
using unnamed semaphore for syncing in misdn_thread.

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=38851&r1=38850&r2=38851&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/chan_misdn.c (original)
+++ team/crichter/0.4.0/channels/chan_misdn.c Fri Aug  4 03:48:17 2006
@@ -39,8 +39,7 @@
 #include <sys/ioctl.h>
 #include <signal.h>
 #include <sys/file.h>
-#include <sys/ipc.h>
-#include <sys/sem.h>
+#include <semaphore.h>
 
 #include <asterisk/channel.h>
 #include <asterisk/config.h>
@@ -256,7 +255,6 @@
 /* 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, ...);
 
@@ -446,11 +444,6 @@
 {
 	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;
@@ -458,7 +451,7 @@
 	sigaddset(&sa.sa_mask, SIGUSR1);
 	sigaction(SIGUSR1, &sa, NULL);
 	
-	semop(misdn_tasks_semid, &semb, 1);
+	sem_post((sem_t *)data);
 
 	while (1) {
 		wait = ast_sched_wait(misdn_tasks);
@@ -473,44 +466,21 @@
 
 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) {
+	sem_t blocker;
+	int i = 5;
+
+	if (sem_init(&blocker, 0, 0)) {
 		perror("chan_misdn: Failed to initialize semaphore!");
 		exit(1);
 	}
 
+	chan_misdn_log(4, 0, "Starting misdn_tasks thread\n");
+	
 	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);
+	pthread_create(&misdn_tasks_thread, NULL, misdn_tasks_thread_func, &blocker);
+
+	while (sem_wait(&blocker) && --i);
+	sem_destroy(&blocker);
 }
 
 static void misdn_tasks_destroy (void)



More information about the asterisk-commits mailing list