Changeset a8eb03fabf6c3d09bd5729b872da3929539cd9ae

Show
Ignore:
Timestamp:
12/22/07 19:11:50 (8 months ago)
Author:
Pierre d'Herbemont <pdherbemont@videolan.org>
git-committer:
Pierre d'Herbemont <pdherbemont@videolan.org> 1198347110 +0000
git-parent:

[c76ca6667fe719f8a7757f9b9d61fcd3cab64657]

git-author:
Pierre d'Herbemont <pdherbemont@videolan.org> 1198347110 +0000
Message:

services_discovery/sap.c: Make sure the thread will exit, even if in poll(). And properly lock the object.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/services_discovery/sap.c

    rca43433 ra8eb03f  
    543543    } 
    544544 
     545    vlc_object_lock( p_sd ); 
     546 
    545547    /* read SAP packets */ 
    546548    while( vlc_object_alive( p_sd ) ) 
    547549    { 
    548550        unsigned n = p_sd->p_sys->i_fd; 
    549         struct pollfd ufd[n]; 
     551        struct pollfd ufd[n+1]; 
    550552 
    551553        for (unsigned i = 0; i < n; i++) 
     
    556558        } 
    557559 
    558         /* FIXME: remove this stupid evil hack when we have sorted out how to 
    559          * to cancel threads while doing network I/O */ 
    560         if (timeout > 2000) 
    561             timeout = 2000; 
    562  
    563         if (poll (ufd, n, timeout) > 0) 
     560        /* Make sure we track vlc_object_signal() */ 
     561        ufd[n].fd = vlc_object_waitpipe( p_sd ); 
     562        ufd[n].events = POLLIN | POLLHUP; 
     563        ufd[n].revents = 0; 
     564 
     565        if( ufd[n].fd == -1 ) 
     566        { 
     567            /* On windows, fd will be -1, as we can't select on a pipe()-ed 
     568             * fildes. Because we have no other solution to track that 
     569             * object is killed, we make sure the timeout won't be to long. */ 
     570            if( timeout > 1000 || timeout == -1 ) 
     571                timeout = 1000; 
     572        } 
     573 
     574        vlc_object_unlock( p_sd ); 
     575 
     576        if (poll (ufd, n+1, timeout) > 0) 
    564577        { 
    565578            for (unsigned i = 0; i < n; i++) 
     
    618631        else if( timeout < 200 ) 
    619632            timeout = 200; /* Don't wakeup too fast. */ 
    620     } 
     633 
     634        vlc_object_lock( p_sd ); 
     635    } 
     636    vlc_object_unlock( p_sd ); 
    621637} 
    622638