ut fast : use sigsuspend to be signal safe
[lttv.git] / usertrace-fast / ltt-usertrace-fast.c
index d722460b10e1f4a98d4048feed7e46ea57b408c2..1a57db154686f910b1eff7b7b553bf3c825df985 100644 (file)
@@ -319,14 +319,9 @@ static inline int ltt_buffer_put(struct ltt_buf *ltt_buf,
                 * It can also happen if this is a buffer we never got. */
                return -EIO;
        } else {
-               if(atomic_inc_return(&ltt_buf->writer_futex) <= 0) {
-                       atomic_set(&ltt_buf->writer_futex, 1);
-                       /* tell the client that buffer is now unfull */
-                       ret = futex((unsigned long)&ltt_buf->writer_futex,
-                                       FUTEX_WAKE, 1, 0, 0, 0);
-                       if(ret != 1) {
-                               dbg_printf("LTT warning : race condition : writer not waiting or too many writers\n");
-                       }
+               ret = sem_post(&ltt_buf->writer_sem);
+               if(ret < 0) {
+                       printf("error in sem_post");
                }
        }
 }
@@ -380,6 +375,7 @@ get_error:
 static void ltt_usertrace_fast_daemon(struct ltt_trace_info *shared_trace_info,
                sigset_t oldset, pid_t l_traced_pid, pthread_t l_traced_tid)
 {
+       sigset_t set;
        struct sigaction act;
        int ret;
        int fd_process;
@@ -411,12 +407,6 @@ static void ltt_usertrace_fast_daemon(struct ltt_trace_info *shared_trace_info,
        sigaddset(&(act.sa_mask), SIGALRM);
        sigaction(SIGALRM, &act, NULL);
 
-       /* Enable signals */
-       ret = pthread_sigmask(SIG_SETMASK, &oldset, NULL);
-       if(ret) {
-               dbg_printf("LTT Error in pthread_sigmask\n");
-       }
-
        alarm(3);
 
        /* Open output files */
@@ -449,11 +439,15 @@ static void ltt_usertrace_fast_daemon(struct ltt_trace_info *shared_trace_info,
 #endif //LTT_NULL_OUTPUT_TEST
        
        while(1) {
-               pause();
+               ret = sigsuspend(&oldset);
+               if(ret != -1) {
+                       perror("LTT Error in sigsuspend\n");
+               }
+               
                if(traced_pid == 0) break; /* parent died */
                if(parent_exited) break;
                dbg_printf("LTT Doing a buffer switch read. pid is : %lu\n", getpid());
-       
+
                do {
                        ret = read_subbuffer(&shared_trace_info->channel.process, fd_process);
                } while(ret == 0);
@@ -471,6 +465,10 @@ static void ltt_usertrace_fast_daemon(struct ltt_trace_info *shared_trace_info,
 
        close(fd_process);
        
+       ret = sem_destroy(&shared_trace_info->channel.process.writer_sem);
+       if(ret < 0) {
+               perror("error in sem_destroy");
+       }
        munmap(shared_trace_info, sizeof(*shared_trace_info));
        
        exit(0);
@@ -501,9 +499,12 @@ void ltt_rw_init(void)
        shared_trace_info->nesting=0;
        memset(&shared_trace_info->channel.process, 0,
                        sizeof(shared_trace_info->channel.process));
-       /* Tricky semaphore : is in a shared memory space, so it's ok for a fast
-        * mutex (futex). */
-       atomic_set(&shared_trace_info->channel.process.writer_futex, LTT_N_SUBBUFS);
+       //Need NPTL!
+       ret = sem_init(&shared_trace_info->channel.process.writer_sem, 1,
+                                                                       LTT_N_SUBBUFS);
+       if(ret < 0) {
+               perror("error in sem_init");
+       }
        shared_trace_info->channel.process.alloc_size = LTT_BUF_SIZE_PROCESS;
        shared_trace_info->channel.process.subbuf_size = LTT_SUBBUF_SIZE_PROCESS;
        shared_trace_info->channel.process.start =
This page took 0.028139 seconds and 4 git commands to generate.