annotate beosthread.c @ 2979:bfabfdf9ce55 libavcodec

COSMETICS: tabs --> spaces, some prettyprinting
author diego
date Thu, 22 Dec 2005 01:10:11 +0000
parents ef2149182f1c
children 0b546eab515d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2362
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
1 /*
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
2 * Copyright (c) 2004 François Revol <revol@free.fr>
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
3 *
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
4 * This library is free software; you can redistribute it and/or
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
5 * modify it under the terms of the GNU Lesser General Public
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
6 * License as published by the Free Software Foundation; either
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
7 * version 2 of the License, or (at your option) any later version.
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
8 *
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
9 * This library is distributed in the hope that it will be useful,
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
12 * Lesser General Public License for more details.
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
13 *
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
14 * You should have received a copy of the GNU Lesser General Public
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
15 * License along with this library; if not, write to the Free Software
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
17 *
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
18 */
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
19 //#define DEBUG
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
20
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
21 #include "avcodec.h"
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
22 #include "common.h"
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
23
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
24 #include <OS.h>
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
25
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
26 typedef struct ThreadContext{
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
27 AVCodecContext *avctx;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
28 thread_id thread;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
29 sem_id work_sem;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
30 sem_id done_sem;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
31 int (*func)(AVCodecContext *c, void *arg);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
32 void *arg;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
33 int ret;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
34 }ThreadContext;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
35
2469
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
36 // it's odd Be never patented that :D
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
37 struct benaphore {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
38 vint32 atom;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
39 sem_id sem;
2469
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
40 };
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
41 static inline int lock_ben(struct benaphore *ben)
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
42 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
43 if (atomic_add(&ben->atom, 1) > 0)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
44 return acquire_sem(ben->sem);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
45 return B_OK;
2469
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
46 }
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
47 static inline int unlock_ben(struct benaphore *ben)
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
48 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
49 if (atomic_add(&ben->atom, -1) > 1)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
50 return release_sem(ben->sem);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
51 return B_OK;
2469
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
52 }
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
53
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
54 static struct benaphore av_thread_lib_ben;
2362
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
55
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
56 static int32 ff_thread_func(void *v){
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
57 ThreadContext *c= v;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
58
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
59 for(;;){
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
60 //printf("thread_func %X enter wait\n", (int)v); fflush(stdout);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
61 acquire_sem(c->work_sem);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
62 //printf("thread_func %X after wait (func=%X)\n", (int)v, (int)c->func); fflush(stdout);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
63 if(c->func)
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
64 c->ret= c->func(c->avctx, c->arg);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
65 else
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
66 return 0;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
67 //printf("thread_func %X signal complete\n", (int)v); fflush(stdout);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
68 release_sem(c->done_sem);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
69 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2469
diff changeset
70
2362
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
71 return B_OK;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
72 }
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
73
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
74 /**
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
75 * free what has been allocated by avcodec_thread_init().
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
76 * must be called after decoding has finished, especially dont call while avcodec_thread_execute() is running
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
77 */
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
78 void avcodec_thread_free(AVCodecContext *s){
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
79 ThreadContext *c= s->thread_opaque;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
80 int i;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
81 int32 ret;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
82
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
83 for(i=0; i<s->thread_count; i++){
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2469
diff changeset
84
2362
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
85 c[i].func= NULL;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
86 release_sem(c[i].work_sem);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
87 wait_for_thread(c[i].thread, &ret);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
88 if(c[i].work_sem > B_OK) delete_sem(c[i].work_sem);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
89 if(c[i].done_sem > B_OK) delete_sem(c[i].done_sem);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
90 }
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
91
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
92 av_freep(&s->thread_opaque);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
93 }
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
94
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
95 int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
96 ThreadContext *c= s->thread_opaque;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
97 int i;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2469
diff changeset
98
2362
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
99 assert(s == c->avctx);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
100 assert(count <= s->thread_count);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2469
diff changeset
101
2362
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
102 /* note, we can be certain that this is not called with the same AVCodecContext by different threads at the same time */
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
103
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
104 for(i=0; i<count; i++){
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
105 c[i].arg= arg[i];
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
106 c[i].func= func;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
107 c[i].ret= 12345;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
108
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
109 release_sem(c[i].work_sem);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
110 }
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
111 for(i=0; i<count; i++){
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
112 acquire_sem(c[i].done_sem);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2469
diff changeset
113
2362
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
114 c[i].func= NULL;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
115 if(ret) ret[i]= c[i].ret;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
116 }
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
117 return 0;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
118 }
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
119
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
120 int avcodec_thread_init(AVCodecContext *s, int thread_count){
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
121 int i;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
122 ThreadContext *c;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
123
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
124 s->thread_count= thread_count;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
125
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
126 assert(!s->thread_opaque);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
127 c= av_mallocz(sizeof(ThreadContext)*thread_count);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
128 s->thread_opaque= c;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2469
diff changeset
129
2362
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
130 for(i=0; i<thread_count; i++){
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
131 //printf("init semaphors %d\n", i); fflush(stdout);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
132 c[i].avctx= s;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
133
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
134 if((c[i].work_sem = create_sem(0, "ff work sem")) < B_OK)
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
135 goto fail;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
136 if((c[i].done_sem = create_sem(0, "ff done sem")) < B_OK)
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
137 goto fail;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
138
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
139 //printf("create thread %d\n", i); fflush(stdout);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
140 c[i].thread = spawn_thread(ff_thread_func, "libavcodec thread", B_LOW_PRIORITY, &c[i] );
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
141 if( c[i].thread < B_OK ) goto fail;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
142 resume_thread(c[i].thread );
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
143 }
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
144 //printf("init done\n"); fflush(stdout);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2469
diff changeset
145
2362
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
146 s->execute= avcodec_thread_execute;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
147
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
148 return 0;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
149 fail:
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
150 avcodec_thread_free(s);
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
151 return -1;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
152 }
2469
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
153
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
154 /* provide a mean to serialize calls to avcodec_*() for thread safety. */
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
155
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
156 int avcodec_thread_lock_lib(void)
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
157 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
158 return lock_ben(&av_thread_lib_ben);
2469
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
159 }
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
160
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
161 int avcodec_thread_unlock_lib(void)
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
162 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
163 return unlock_ben(&av_thread_lib_ben);
2469
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
164 }
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
165
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
166 /* our versions of _init and _fini (which are called by those actually from crt.o) */
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
167
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
168 void initialize_after(void)
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
169 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
170 av_thread_lib_ben.atom = 0;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
171 av_thread_lib_ben.sem = create_sem(0, "libavcodec benaphore");
2469
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
172 }
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
173
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
174 void uninitialize_before(void)
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
175 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
176 delete_sem(av_thread_lib_ben.sem);
2469
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
177 }
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
178
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
179
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
180