Mercurial > libavcodec.hg
comparison pthread.c @ 1822:7366bb5c363f libavcodec
w32threads by (Gildas Bazin <gbazin at altern dot org>)
| author | michael |
|---|---|
| date | Thu, 19 Feb 2004 20:29:26 +0000 |
| parents | 95612d423fde |
| children | 00a6bfc81010 |
comparison
equal
deleted
inserted
replaced
| 1821:1adbe0ab09fc | 1822:7366bb5c363f |
|---|---|
| 52 | 52 |
| 53 return NULL; | 53 return NULL; |
| 54 } | 54 } |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * free what has been allocated by avcodec_pthread_init(). | 57 * free what has been allocated by avcodec_thread_init(). |
| 58 * must be called after decoding has finished, especially dont call while avcodec_pthread_execute() is running | 58 * must be called after decoding has finished, especially dont call while avcodec_thread_execute() is running |
| 59 */ | 59 */ |
| 60 void avcodec_pthread_free(AVCodecContext *s){ | 60 void avcodec_thread_free(AVCodecContext *s){ |
| 61 ThreadContext *c= s->thread_opaque; | 61 ThreadContext *c= s->thread_opaque; |
| 62 int i; | 62 int i; |
| 63 | 63 |
| 64 for(i=0; i<s->thread_count; i++){ | 64 for(i=0; i<s->thread_count; i++){ |
| 65 int val; | 65 int val; |
| 75 } | 75 } |
| 76 | 76 |
| 77 av_freep(&s->thread_opaque); | 77 av_freep(&s->thread_opaque); |
| 78 } | 78 } |
| 79 | 79 |
| 80 int avcodec_pthread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){ | 80 int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){ |
| 81 ThreadContext *c= s->thread_opaque; | 81 ThreadContext *c= s->thread_opaque; |
| 82 int i, val; | 82 int i, val; |
| 83 | 83 |
| 84 assert(s == c->avctx); | 84 assert(s == c->avctx); |
| 85 assert(count <= s->thread_count); | 85 assert(count <= s->thread_count); |
| 105 if(ret) ret[i]= c[i].ret; | 105 if(ret) ret[i]= c[i].ret; |
| 106 } | 106 } |
| 107 return 0; | 107 return 0; |
| 108 } | 108 } |
| 109 | 109 |
| 110 int avcodec_pthread_init(AVCodecContext *s, int thread_count){ | 110 int avcodec_thread_init(AVCodecContext *s, int thread_count){ |
| 111 int i; | 111 int i; |
| 112 ThreadContext *c; | 112 ThreadContext *c; |
| 113 | 113 |
| 114 s->thread_count= thread_count; | 114 s->thread_count= thread_count; |
| 115 | 115 |
| 128 if(pthread_create(&c[i].thread, NULL, thread_func, &c[i])) | 128 if(pthread_create(&c[i].thread, NULL, thread_func, &c[i])) |
| 129 goto fail; | 129 goto fail; |
| 130 } | 130 } |
| 131 //printf("init done\n"); fflush(stdout); | 131 //printf("init done\n"); fflush(stdout); |
| 132 | 132 |
| 133 s->execute= avcodec_pthread_execute; | 133 s->execute= avcodec_thread_execute; |
| 134 | 134 |
| 135 return 0; | 135 return 0; |
| 136 fail: | 136 fail: |
| 137 avcodec_pthread_free(s); | 137 avcodec_thread_free(s); |
| 138 return -1; | 138 return -1; |
| 139 } | 139 } |
