comparison w32thread.c @ 2967:ef2149182f1c libavcodec

COSMETICS: Remove all trailing whitespace.
author diego
date Sat, 17 Dec 2005 18:14:38 +0000
parents 7366bb5c363f
children 0b546eab515d
comparison
equal deleted inserted replaced
2966:564788471dd4 2967:ef2149182f1c
48 else 48 else
49 return 0; 49 return 0;
50 //printf("thread_func %X signal complete\n", (int)v); fflush(stdout); 50 //printf("thread_func %X signal complete\n", (int)v); fflush(stdout);
51 ReleaseSemaphore(c->done_sem, 1, 0); 51 ReleaseSemaphore(c->done_sem, 1, 0);
52 } 52 }
53 53
54 return 0; 54 return 0;
55 } 55 }
56 56
57 /** 57 /**
58 * free what has been allocated by avcodec_thread_init(). 58 * free what has been allocated by avcodec_thread_init().
61 void avcodec_thread_free(AVCodecContext *s){ 61 void avcodec_thread_free(AVCodecContext *s){
62 ThreadContext *c= s->thread_opaque; 62 ThreadContext *c= s->thread_opaque;
63 int i; 63 int i;
64 64
65 for(i=0; i<s->thread_count; i++){ 65 for(i=0; i<s->thread_count; i++){
66 66
67 c[i].func= NULL; 67 c[i].func= NULL;
68 ReleaseSemaphore(c[i].work_sem, 1, 0); 68 ReleaseSemaphore(c[i].work_sem, 1, 0);
69 WaitForSingleObject(c[i].thread, INFINITE); 69 WaitForSingleObject(c[i].thread, INFINITE);
70 if(c[i].work_sem) CloseHandle(c[i].work_sem); 70 if(c[i].work_sem) CloseHandle(c[i].work_sem);
71 if(c[i].done_sem) CloseHandle(c[i].done_sem); 71 if(c[i].done_sem) CloseHandle(c[i].done_sem);
75 } 75 }
76 76
77 int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){ 77 int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){
78 ThreadContext *c= s->thread_opaque; 78 ThreadContext *c= s->thread_opaque;
79 int i; 79 int i;
80 80
81 assert(s == c->avctx); 81 assert(s == c->avctx);
82 assert(count <= s->thread_count); 82 assert(count <= s->thread_count);
83 83
84 /* note, we can be certain that this is not called with the same AVCodecContext by different threads at the same time */ 84 /* note, we can be certain that this is not called with the same AVCodecContext by different threads at the same time */
85 85
86 for(i=0; i<count; i++){ 86 for(i=0; i<count; i++){
87 c[i].arg= arg[i]; 87 c[i].arg= arg[i];
88 c[i].func= func; 88 c[i].func= func;
90 90
91 ReleaseSemaphore(c[i].work_sem, 1, 0); 91 ReleaseSemaphore(c[i].work_sem, 1, 0);
92 } 92 }
93 for(i=0; i<count; i++){ 93 for(i=0; i<count; i++){
94 WaitForSingleObject(c[i].done_sem, INFINITE); 94 WaitForSingleObject(c[i].done_sem, INFINITE);
95 95
96 c[i].func= NULL; 96 c[i].func= NULL;
97 if(ret) ret[i]= c[i].ret; 97 if(ret) ret[i]= c[i].ret;
98 } 98 }
99 return 0; 99 return 0;
100 } 100 }
107 s->thread_count= thread_count; 107 s->thread_count= thread_count;
108 108
109 assert(!s->thread_opaque); 109 assert(!s->thread_opaque);
110 c= av_mallocz(sizeof(ThreadContext)*thread_count); 110 c= av_mallocz(sizeof(ThreadContext)*thread_count);
111 s->thread_opaque= c; 111 s->thread_opaque= c;
112 112
113 for(i=0; i<thread_count; i++){ 113 for(i=0; i<thread_count; i++){
114 //printf("init semaphors %d\n", i); fflush(stdout); 114 //printf("init semaphors %d\n", i); fflush(stdout);
115 c[i].avctx= s; 115 c[i].avctx= s;
116 116
117 if(!(c[i].work_sem = CreateSemaphore(NULL, 0, s->thread_count, NULL))) 117 if(!(c[i].work_sem = CreateSemaphore(NULL, 0, s->thread_count, NULL)))
122 //printf("create thread %d\n", i); fflush(stdout); 122 //printf("create thread %d\n", i); fflush(stdout);
123 c[i].thread = (HANDLE)_beginthreadex(NULL, 0, thread_func, &c[i], 0, &threadid ); 123 c[i].thread = (HANDLE)_beginthreadex(NULL, 0, thread_func, &c[i], 0, &threadid );
124 if( !c[i].thread ) goto fail; 124 if( !c[i].thread ) goto fail;
125 } 125 }
126 //printf("init done\n"); fflush(stdout); 126 //printf("init done\n"); fflush(stdout);
127 127
128 s->execute= avcodec_thread_execute; 128 s->execute= avcodec_thread_execute;
129 129
130 return 0; 130 return 0;
131 fail: 131 fail:
132 avcodec_thread_free(s); 132 avcodec_thread_free(s);