comparison beosthread.c @ 2469:df02930c138b libavcodec

added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
author mmu_man
date Sat, 29 Jan 2005 20:09:33 +0000
parents 7a6ff8cc7c95
children ef2149182f1c
comparison
equal deleted inserted replaced
2468:1addaf6facbb 2469:df02930c138b
31 int (*func)(AVCodecContext *c, void *arg); 31 int (*func)(AVCodecContext *c, void *arg);
32 void *arg; 32 void *arg;
33 int ret; 33 int ret;
34 }ThreadContext; 34 }ThreadContext;
35 35
36 // it's odd Be never patented that :D
37 struct benaphore {
38 vint32 atom;
39 sem_id sem;
40 };
41 static inline int lock_ben(struct benaphore *ben)
42 {
43 if (atomic_add(&ben->atom, 1) > 0)
44 return acquire_sem(ben->sem);
45 return B_OK;
46 }
47 static inline int unlock_ben(struct benaphore *ben)
48 {
49 if (atomic_add(&ben->atom, -1) > 1)
50 return release_sem(ben->sem);
51 return B_OK;
52 }
53
54 static struct benaphore av_thread_lib_ben;
36 55
37 static int32 ff_thread_func(void *v){ 56 static int32 ff_thread_func(void *v){
38 ThreadContext *c= v; 57 ThreadContext *c= v;
39 58
40 for(;;){ 59 for(;;){
129 return 0; 148 return 0;
130 fail: 149 fail:
131 avcodec_thread_free(s); 150 avcodec_thread_free(s);
132 return -1; 151 return -1;
133 } 152 }
153
154 /* provide a mean to serialize calls to avcodec_*() for thread safety. */
155
156 int avcodec_thread_lock_lib(void)
157 {
158 return lock_ben(&av_thread_lib_ben);
159 }
160
161 int avcodec_thread_unlock_lib(void)
162 {
163 return unlock_ben(&av_thread_lib_ben);
164 }
165
166 /* our versions of _init and _fini (which are called by those actually from crt.o) */
167
168 void initialize_after(void)
169 {
170 av_thread_lib_ben.atom = 0;
171 av_thread_lib_ben.sem = create_sem(0, "libavcodec benaphore");
172 }
173
174 void uninitialize_before(void)
175 {
176 delete_sem(av_thread_lib_ben.sem);
177 }
178
179
180