Changeset 9346e4a


Ignore:
Timestamp:
09/10/15 16:40:56 (5 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
d2df7c4
Parents:
c3cb9f9
Message:

Allow trace_pstop to be called by a reporter thread.

This will allow reporters to decide they've seen enough packets and
trigger a program exit.

This has the side-effect that trace_ppause can also be called by the
reporter successfully, but restarting the trace again is probably not
going to work as intended.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/trace_parallel.c

    rf2066fa r9346e4a  
    18521852        // Check state from within the lock if we are going to change it
    18531853        ASSERT_RET(pthread_mutex_lock(&libtrace->libtrace_lock), == 0);
     1854
     1855        /* If we are already paused, just treat this as a NOOP */
     1856        if (libtrace->state == STATE_PAUSED) {
     1857                ASSERT_RET(pthread_mutex_unlock(&libtrace->libtrace_lock), == 0);
     1858                return 0;
     1859        }
    18541860        if (!libtrace->started || libtrace->state != STATE_RUNNING) {
    18551861                trace_set_err(libtrace,TRACE_ERR_BAD_STATE, "You must call trace_start() before calling trace_ppause()");
    1856                 ASSERT_RET(pthread_mutex_unlock(&libtrace->libtrace_lock), == 0);
    18571862                return -1;
    18581863        }
     
    19211926                if (libtrace->config.debug_state)
    19221927                        fprintf(stderr, "Reporter thread is running, asking it to pause ...");
    1923                 libtrace_message_t message = {0};
    1924                 message.code = MESSAGE_DO_PAUSE;
    1925                 trace_message_thread(libtrace, &libtrace->reporter_thread, &message);
    1926                 // Wait for it to pause
    1927                 ASSERT_RET(pthread_mutex_lock(&libtrace->libtrace_lock), == 0);
    1928                 while (libtrace->reporter_thread.state == THREAD_RUNNING) {
    1929                         ASSERT_RET(pthread_cond_wait(&libtrace->perpkt_cond, &libtrace->libtrace_lock), == 0);
    1930                 }
    1931                 ASSERT_RET(pthread_mutex_unlock(&libtrace->libtrace_lock), == 0);
     1928                if (pthread_equal(pthread_self(), libtrace->reporter_thread.tid)) {
     1929                        libtrace->combiner.pause(libtrace, &libtrace->combiner);
     1930                        thread_change_state(libtrace, &libtrace->reporter_thread, THREAD_PAUSED, true);
     1931               
     1932                } else {
     1933                        libtrace_message_t message = {0};
     1934                        message.code = MESSAGE_DO_PAUSE;
     1935                        trace_message_thread(libtrace, &libtrace->reporter_thread, &message);
     1936                        // Wait for it to pause
     1937                        ASSERT_RET(pthread_mutex_lock(&libtrace->libtrace_lock), == 0);
     1938                        while (libtrace->reporter_thread.state == THREAD_RUNNING) {
     1939                                ASSERT_RET(pthread_cond_wait(&libtrace->perpkt_cond, &libtrace->libtrace_lock), == 0);
     1940                        }
     1941                        ASSERT_RET(pthread_mutex_unlock(&libtrace->libtrace_lock), == 0);
     1942                }
    19321943                if (libtrace->config.debug_state)
    19331944                        fprintf(stderr, " DONE\n");
Note: See TracChangeset for help on using the changeset viewer.