udp: check for HAVE_PTHREAD_CANCEL instead of HAVE_PTHREADS.

Some environments, for example Android, pretend to have pthreads
but actually have only a partial implementation.
This commit is contained in:
Nicolas George 2012-05-08 19:36:06 +02:00
parent 83f954e859
commit 281bde2789

View File

@ -38,7 +38,7 @@
#include "os_support.h" #include "os_support.h"
#include "url.h" #include "url.h"
#if HAVE_PTHREADS #if HAVE_PTHREAD_CANCEL
#include <pthread.h> #include <pthread.h>
#endif #endif
@ -68,7 +68,7 @@ typedef struct {
int circular_buffer_size; int circular_buffer_size;
AVFifoBuffer *fifo; AVFifoBuffer *fifo;
int circular_buffer_error; int circular_buffer_error;
#if HAVE_PTHREADS #if HAVE_PTHREAD_CANCEL
pthread_t circular_buffer_thread; pthread_t circular_buffer_thread;
pthread_mutex_t mutex; pthread_mutex_t mutex;
pthread_cond_t cond; pthread_cond_t cond;
@ -321,7 +321,7 @@ static int udp_get_file_handle(URLContext *h)
return s->udp_fd; return s->udp_fd;
} }
#if HAVE_PTHREADS #if HAVE_PTHREAD_CANCEL
static void *circular_buffer_task( void *_URLContext) static void *circular_buffer_task( void *_URLContext)
{ {
URLContext *h = _URLContext; URLContext *h = _URLContext;
@ -526,7 +526,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
s->udp_fd = udp_fd; s->udp_fd = udp_fd;
#if HAVE_PTHREADS #if HAVE_PTHREAD_CANCEL
if (!is_output && s->circular_buffer_size) { if (!is_output && s->circular_buffer_size) {
int ret; int ret;
@ -552,7 +552,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
#endif #endif
return 0; return 0;
#if HAVE_PTHREADS #if HAVE_PTHREAD_CANCEL
thread_fail: thread_fail:
pthread_cond_destroy(&s->cond); pthread_cond_destroy(&s->cond);
cond_fail: cond_fail:
@ -571,7 +571,7 @@ static int udp_read(URLContext *h, uint8_t *buf, int size)
int ret; int ret;
int avail, nonblock = h->flags & AVIO_FLAG_NONBLOCK; int avail, nonblock = h->flags & AVIO_FLAG_NONBLOCK;
#if HAVE_PTHREADS #if HAVE_PTHREAD_CANCEL
if (s->fifo) { if (s->fifo) {
pthread_mutex_lock(&s->mutex); pthread_mutex_lock(&s->mutex);
do { do {
@ -652,7 +652,7 @@ static int udp_close(URLContext *h)
udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr);
closesocket(s->udp_fd); closesocket(s->udp_fd);
av_fifo_free(s->fifo); av_fifo_free(s->fifo);
#if HAVE_PTHREADS #if HAVE_PTHREAD_CANCEL
if (s->thread_started) { if (s->thread_started) {
pthread_cancel(s->circular_buffer_thread); pthread_cancel(s->circular_buffer_thread);
ret = pthread_join(s->circular_buffer_thread, NULL); ret = pthread_join(s->circular_buffer_thread, NULL);