Mercurial > libavcodec.hg
annotate os2thread.c @ 4090:8e35dfc4ae15 libavcodec
add support for while() loops again ugly syntax while(condition, statements) but very simple implementation
author | michael |
---|---|
date | Fri, 27 Oct 2006 22:35:55 +0000 |
parents | c8c591fe26f8 |
children | 6b784f65ce16 |
rev | line source |
---|---|
3081
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
1 /* |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
2 * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
3 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3517
diff
changeset
|
4 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3517
diff
changeset
|
5 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3517
diff
changeset
|
6 * FFmpeg is free software; you can redistribute it and/or |
3081
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
7 * modify it under the terms of the GNU Lesser General Public |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
8 * License as published by the Free Software Foundation; either |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3517
diff
changeset
|
9 * version 2.1 of the License, or (at your option) any later version. |
3081
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
10 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3517
diff
changeset
|
11 * FFmpeg is distributed in the hope that it will be useful, |
3081
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
14 * Lesser General Public License for more details. |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
15 * |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
16 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3517
diff
changeset
|
17 * License along with FFmpeg; if not, write to the Free Software |
3517 | 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3081
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
19 * |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
20 */ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
21 //#define DEBUG |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
22 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
23 // Ported by Vlad Stelmahovsky |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
24 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
25 #include "avcodec.h" |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
26 #include "common.h" |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
27 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
28 #ifdef HAVE_THREADS |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
29 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
30 #define INCL_DOS |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
31 #define INCL_DOSERRORS |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
32 #define INCL_DOSDEVIOCTL |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
33 #include <os2.h> |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
34 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
35 typedef struct ThreadContext{ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
36 AVCodecContext *avctx; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
37 int thread; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
38 HEV work_sem; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
39 HEV done_sem; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
40 int (*func)(AVCodecContext *c, void *arg); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
41 void *arg; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
42 int ret; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
43 }ThreadContext; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
44 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
45 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
46 void thread_func(void *v){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
47 ThreadContext *c= v; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
48 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
49 for(;;){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
50 //printf("thread_func %X enter wait\n", (int)v); fflush(stdout); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
51 DosWaitEventSem(c->work_sem, SEM_INDEFINITE_WAIT); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
52 // WaitForSingleObject(c->work_sem, INFINITE); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
53 //printf("thread_func %X after wait (func=%X)\n", (int)v, (int)c->func); fflush(stdout); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
54 if(c->func) |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
55 c->ret= c->func(c->avctx, c->arg); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
56 else |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
57 return; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
58 //printf("thread_func %X signal complete\n", (int)v); fflush(stdout); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
59 DosPostEventSem(c->done_sem); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
60 // ReleaseSemaphore(c->done_sem, 1, 0); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
61 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
62 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
63 return; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
64 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
65 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
66 /** |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
67 * free what has been allocated by avcodec_thread_init(). |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
68 * must be called after decoding has finished, especially dont call while avcodec_thread_execute() is running |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
69 */ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
70 void avcodec_thread_free(AVCodecContext *s){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
71 ThreadContext *c= s->thread_opaque; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
72 int i; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
73 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
74 for(i=0; i<s->thread_count; i++){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
75 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
76 c[i].func= NULL; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
77 DosPostEventSem(c[i].work_sem); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
78 // ReleaseSemaphore(c[i].work_sem, 1, 0); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
79 DosWaitThread((PTID)&c[i].thread,DCWW_WAIT); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
80 // WaitForSingleObject(c[i].thread, INFINITE); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
81 if(c[i].work_sem) DosCloseEventSem(c[i].work_sem);//CloseHandle(c[i].work_sem); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
82 if(c[i].done_sem) DosCloseEventSem(c[i].done_sem);//CloseHandle(c[i].done_sem); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
83 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
84 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
85 av_freep(&s->thread_opaque); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
86 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
87 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
88 int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
89 ThreadContext *c= s->thread_opaque; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
90 int i; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
91 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
92 assert(s == c->avctx); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
93 assert(count <= s->thread_count); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
94 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
95 /* note, we can be certain that this is not called with the same AVCodecContext by different threads at the same time */ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
96 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
97 for(i=0; i<count; i++){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
98 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
99 c[i].arg= arg[i]; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
100 c[i].func= func; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
101 c[i].ret= 12345; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
102 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
103 DosPostEventSem(c[i].work_sem); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
104 // ReleaseSemaphore(c[i].work_sem, 1, 0); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
105 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
106 for(i=0; i<count; i++){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
107 DosWaitEventSem(c[i].done_sem,SEM_INDEFINITE_WAIT); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
108 // WaitForSingleObject(c[i].done_sem, INFINITE); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
109 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
110 c[i].func= NULL; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
111 if(ret) ret[i]= c[i].ret; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
112 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
113 return 0; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
114 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
115 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
116 int avcodec_thread_init(AVCodecContext *s, int thread_count){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
117 int i; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
118 ThreadContext *c; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
119 uint32_t threadid; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
120 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
121 s->thread_count= thread_count; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
122 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
123 assert(!s->thread_opaque); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
124 c= av_mallocz(sizeof(ThreadContext)*thread_count); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
125 s->thread_opaque= c; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
126 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
127 for(i=0; i<thread_count; i++){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
128 //printf("init semaphors %d\n", i); fflush(stdout); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
129 c[i].avctx= s; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
130 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
131 if (DosCreateEventSem(NULL,&c[i].work_sem,DC_SEM_SHARED,0)) |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
132 goto fail; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
133 if (DosCreateEventSem(NULL,&c[i].done_sem,DC_SEM_SHARED,0)) |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
134 goto fail; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
135 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
136 //printf("create thread %d\n", i); fflush(stdout); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
137 // c[i].thread = (HANDLE)_beginthreadex(NULL, 0, thread_func, &c[i], 0, &threadid ); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
138 c[i].thread = _beginthread(thread_func, NULL, 0x10000, &c[i]); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
139 if( c[i].thread <= 0 ) goto fail; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
140 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
141 //printf("init done\n"); fflush(stdout); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
142 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
143 s->execute= avcodec_thread_execute; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
144 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
145 return 0; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
146 fail: |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
147 avcodec_thread_free(s); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
148 return -1; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
149 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
150 #endif |