Mercurial > libavcodec.hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
2978:403183bbb505 | 2979:bfabfdf9ce55 |
---|---|
33 int ret; | 33 int ret; |
34 }ThreadContext; | 34 }ThreadContext; |
35 | 35 |
36 // it's odd Be never patented that :D | 36 // it's odd Be never patented that :D |
37 struct benaphore { | 37 struct benaphore { |
38 vint32 atom; | 38 vint32 atom; |
39 sem_id sem; | 39 sem_id sem; |
40 }; | 40 }; |
41 static inline int lock_ben(struct benaphore *ben) | 41 static inline int lock_ben(struct benaphore *ben) |
42 { | 42 { |
43 if (atomic_add(&ben->atom, 1) > 0) | 43 if (atomic_add(&ben->atom, 1) > 0) |
44 return acquire_sem(ben->sem); | 44 return acquire_sem(ben->sem); |
45 return B_OK; | 45 return B_OK; |
46 } | 46 } |
47 static inline int unlock_ben(struct benaphore *ben) | 47 static inline int unlock_ben(struct benaphore *ben) |
48 { | 48 { |
49 if (atomic_add(&ben->atom, -1) > 1) | 49 if (atomic_add(&ben->atom, -1) > 1) |
50 return release_sem(ben->sem); | 50 return release_sem(ben->sem); |
51 return B_OK; | 51 return B_OK; |
52 } | 52 } |
53 | 53 |
54 static struct benaphore av_thread_lib_ben; | 54 static struct benaphore av_thread_lib_ben; |
55 | 55 |
56 static int32 ff_thread_func(void *v){ | 56 static int32 ff_thread_func(void *v){ |
153 | 153 |
154 /* provide a mean to serialize calls to avcodec_*() for thread safety. */ | 154 /* provide a mean to serialize calls to avcodec_*() for thread safety. */ |
155 | 155 |
156 int avcodec_thread_lock_lib(void) | 156 int avcodec_thread_lock_lib(void) |
157 { | 157 { |
158 return lock_ben(&av_thread_lib_ben); | 158 return lock_ben(&av_thread_lib_ben); |
159 } | 159 } |
160 | 160 |
161 int avcodec_thread_unlock_lib(void) | 161 int avcodec_thread_unlock_lib(void) |
162 { | 162 { |
163 return unlock_ben(&av_thread_lib_ben); | 163 return unlock_ben(&av_thread_lib_ben); |
164 } | 164 } |
165 | 165 |
166 /* our versions of _init and _fini (which are called by those actually from crt.o) */ | 166 /* our versions of _init and _fini (which are called by those actually from crt.o) */ |
167 | 167 |
168 void initialize_after(void) | 168 void initialize_after(void) |
169 { | 169 { |
170 av_thread_lib_ben.atom = 0; | 170 av_thread_lib_ben.atom = 0; |
171 av_thread_lib_ben.sem = create_sem(0, "libavcodec benaphore"); | 171 av_thread_lib_ben.sem = create_sem(0, "libavcodec benaphore"); |
172 } | 172 } |
173 | 173 |
174 void uninitialize_before(void) | 174 void uninitialize_before(void) |
175 { | 175 { |
176 delete_sem(av_thread_lib_ben.sem); | 176 delete_sem(av_thread_lib_ben.sem); |
177 } | 177 } |
178 | 178 |
179 | 179 |
180 | 180 |