Showing the changes to libavfilter (2 of 2 files). Show all
Unified · Split
| @@ -25,10 +25,28 @@ · 24 unmodified lines | ||
| 25 | 25 | #include "libavutil/avassert.h" |
| 26 | 26 | #include "libavutil/thread.h" |
| 27 | 27 | |
| 28 | +#if HAVE_PTHREAD_CANCEL | |
| 29 | +#define DNNCond pthread_cond_t | |
| 30 | +#define dnn_cond_init pthread_cond_init | |
| 31 | +#define dnn_cond_destroy pthread_cond_destroy | |
| 32 | +#define dnn_cond_signal pthread_cond_signal | |
| 33 | +#define dnn_cond_wait pthread_cond_wait | |
| 34 | +#else | |
| 35 | +#define DNNCond char | |
| 36 | +static inline int dnn_cond_init(DNNCond *cond, const void *attr) { return 0; } | |
| 37 | +static inline int dnn_cond_destroy(DNNCond *cond) { return 0; } | |
| 38 | +static inline int dnn_cond_signal(DNNCond *cond) { return 0; } | |
| 39 | +static inline int dnn_cond_wait(DNNCond *cond, AVMutex *mutex) | |
| 40 | +{ | |
| 41 | + av_assert0(!"should not reach here"); | |
| 42 | + return 0; | |
| 43 | +} | |
| 44 | +#endif | |
| 45 | + | |
| 28 | 46 | struct FFSafeQueue { |
| 29 | 47 | FFQueue *q; |
| 30 | − pthread_mutex_t mutex; | |
| 31 | − pthread_cond_t cond; | |
| 48 | + AVMutex mutex; | |
| 49 | + DNNCond cond; | |
| 32 | 50 | }; |
| 33 | 51 | |
| 34 | 52 | FFSafeQueue *ff_safe_queue_create(void) |
| @@ -41,8 +59,8 @@ FFSafeQueue *ff_safe_queue_create(void) · 6 unmodified lines | ||
| 41 | 59 | if (!sq->q) |
| 42 | 60 | return NULL; |
| 43 | 61 | |
| 44 | − pthread_mutex_init(&sq->mutex, NULL); | |
| 45 | − pthread_cond_init(&sq->cond, NULL); | |
| 62 | + ff_mutex_init(&sq->mutex, NULL); | |
| 63 | + dnn_cond_init(&sq->cond, NULL); | |
| 46 | 64 | return sq; |
| 47 | 65 | } |
| 48 | 66 | |
| @@ -52,8 +70,8 @@ void ff_safe_queue_destroy(FFSafeQueue *sq) · 3 unmodified lines | ||
| 52 | 70 | return; |
| 53 | 71 | |
| 54 | 72 | ff_queue_destroy(sq->q); |
| 55 | − pthread_mutex_destroy(&sq->mutex); | |
| 56 | − pthread_cond_destroy(&sq->cond); | |
| 73 | + ff_mutex_destroy(&sq->mutex); | |
| 74 | + dnn_cond_destroy(&sq->cond); | |
| 57 | 75 | av_freep(&sq); |
| 58 | 76 | } |
| 59 | 77 | |
| @@ -64,29 +82,29 @@ size_t ff_safe_queue_size(FFSafeQueue *sq) · 4 unmodified lines | ||
| 64 | 82 | |
| 65 | 83 | void ff_safe_queue_push_front(FFSafeQueue *sq, void *v) |
| 66 | 84 | { |
| 67 | − pthread_mutex_lock(&sq->mutex); | |
| 85 | + ff_mutex_lock(&sq->mutex); | |
| 68 | 86 | ff_queue_push_front(sq->q, v); |
| 69 | − pthread_cond_signal(&sq->cond); | |
| 70 | − pthread_mutex_unlock(&sq->mutex); | |
| 87 | + dnn_cond_signal(&sq->cond); | |
| 88 | + ff_mutex_unlock(&sq->mutex); | |
| 71 | 89 | } |
| 72 | 90 | |
| 73 | 91 | void ff_safe_queue_push_back(FFSafeQueue *sq, void *v) |
| 74 | 92 | { |
| 75 | − pthread_mutex_lock(&sq->mutex); | |
| 93 | + ff_mutex_lock(&sq->mutex); | |
| 76 | 94 | ff_queue_push_back(sq->q, v); |
| 77 | − pthread_cond_signal(&sq->cond); | |
| 78 | − pthread_mutex_unlock(&sq->mutex); | |
| 95 | + dnn_cond_signal(&sq->cond); | |
| 96 | + ff_mutex_unlock(&sq->mutex); | |
| 79 | 97 | } |
| 80 | 98 | |
| 81 | 99 | void *ff_safe_queue_pop_front(FFSafeQueue *sq) |
| 82 | 100 | { |
| 83 | 101 | void *value; |
| 84 | − pthread_mutex_lock(&sq->mutex); | |
| 102 | + ff_mutex_lock(&sq->mutex); | |
| 85 | 103 | while (ff_queue_size(sq->q) == 0) { |
| 86 | − pthread_cond_wait(&sq->cond, &sq->mutex); | |
| 104 | + dnn_cond_wait(&sq->cond, &sq->mutex); | |
| 87 | 105 | } |
| 88 | 106 | value = ff_queue_pop_front(sq->q); |
| 89 | − pthread_cond_signal(&sq->cond); | |
| 90 | − pthread_mutex_unlock(&sq->mutex); | |
| 107 | + dnn_cond_signal(&sq->cond); | |
| 108 | + ff_mutex_unlock(&sq->mutex); | |
| 91 | 109 | return value; |
| 92 | 110 | } |
| @@ -110,6 +110,13 @@ static av_cold int init(AVFilterContext *context) · 109 unmodified lines | ||
| 110 | 110 | av_log(ctx, AV_LOG_WARNING, "this backend does not support async execution, roll back to sync.\n"); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | +#if !HAVE_PTHREAD_CANCEL | |
| 114 | + if (ctx->async) { | |
| 115 | + ctx->async = 0; | |
| 116 | + av_log(ctx, AV_LOG_WARNING, "pthread is not supported, roll back to sync.\n"); | |
| 117 | + } | |
| 118 | +#endif | |
| 119 | + | |
| 113 | 120 | return 0; |
| 114 | 121 | } |
| 115 | 122 | |