Showing the changes to libavfilter (2 of 2 files). Show all
Unified · Split
| @@ -25,10 +25,28 @@ · 24 unmodified lines | |||
| 25 | #include "libavutil/avassert.h" | 25 | #include "libavutil/avassert.h" |
| 26 | #include "libavutil/thread.h" | 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 | struct FFSafeQueue { | 46 | struct FFSafeQueue { |
| 29 | FFQueue *q; | 47 | FFQueue *q; |
| 30 | pthread_mutex_t mutex; | 48 | AVMutex mutex; |
| 31 | pthread_cond_t cond; | 49 | DNNCond cond; |
| 32 | }; | 50 | }; |
| 33 | 51 | ||
| 34 | FFSafeQueue *ff_safe_queue_create(void) | 52 | FFSafeQueue *ff_safe_queue_create(void) |
| @@ -41,8 +59,8 @@ FFSafeQueue *ff_safe_queue_create(void) · 6 unmodified lines | |||
| 41 | if (!sq->q) | 59 | if (!sq->q) |
| 42 | return NULL; | 60 | return NULL; |
| 43 | 61 | ||
| 44 | pthread_mutex_init(&sq->mutex, NULL); | 62 | ff_mutex_init(&sq->mutex, NULL); |
| 45 | pthread_cond_init(&sq->cond, NULL); | 63 | dnn_cond_init(&sq->cond, NULL); |
| 46 | return sq; | 64 | return sq; |
| 47 | } | 65 | } |
| 48 | 66 | ||
| @@ -52,8 +70,8 @@ void ff_safe_queue_destroy(FFSafeQueue *sq) · 3 unmodified lines | |||
| 52 | return; | 70 | return; |
| 53 | 71 | ||
| 54 | ff_queue_destroy(sq->q); | 72 | ff_queue_destroy(sq->q); |
| 55 | pthread_mutex_destroy(&sq->mutex); | 73 | ff_mutex_destroy(&sq->mutex); |
| 56 | pthread_cond_destroy(&sq->cond); | 74 | dnn_cond_destroy(&sq->cond); |
| 57 | av_freep(&sq); | 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 | void ff_safe_queue_push_front(FFSafeQueue *sq, void *v) | 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 | ff_queue_push_front(sq->q, v); | 86 | ff_queue_push_front(sq->q, v); |
| 69 | pthread_cond_signal(&sq->cond); | 87 | dnn_cond_signal(&sq->cond); |
| 70 | pthread_mutex_unlock(&sq->mutex); | 88 | ff_mutex_unlock(&sq->mutex); |
| 71 | } | 89 | } |
| 72 | 90 | ||
| 73 | void ff_safe_queue_push_back(FFSafeQueue *sq, void *v) | 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 | ff_queue_push_back(sq->q, v); | 94 | ff_queue_push_back(sq->q, v); |
| 77 | pthread_cond_signal(&sq->cond); | 95 | dnn_cond_signal(&sq->cond); |
| 78 | pthread_mutex_unlock(&sq->mutex); | 96 | ff_mutex_unlock(&sq->mutex); |
| 79 | } | 97 | } |
| 80 | 98 | ||
| 81 | void *ff_safe_queue_pop_front(FFSafeQueue *sq) | 99 | void *ff_safe_queue_pop_front(FFSafeQueue *sq) |
| 82 | { | 100 | { |
| 83 | void *value; | 101 | void *value; |
| 84 | pthread_mutex_lock(&sq->mutex); | 102 | ff_mutex_lock(&sq->mutex); |
| 85 | while (ff_queue_size(sq->q) == 0) { | 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 | value = ff_queue_pop_front(sq->q); | 106 | value = ff_queue_pop_front(sq->q); |
| 89 | pthread_cond_signal(&sq->cond); | 107 | dnn_cond_signal(&sq->cond); |
| 90 | pthread_mutex_unlock(&sq->mutex); | 108 | ff_mutex_unlock(&sq->mutex); |
| 91 | return value; | 109 | return value; |
| 92 | } | 110 | } |
| @@ -110,6 +110,13 @@ static av_cold int init(AVFilterContext *context) · 109 unmodified lines | |||
| 110 | av_log(ctx, AV_LOG_WARNING, "this backend does not support async execution, roll back to sync.\n"); | 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 | return 0; | 120 | return 0; |
| 114 | } | 121 | } |
| 115 | 122 | ||