25 #include <linux/wait.h>
27 #include <linux/errno.h>
28 #include <linux/string.h>
29 #include <linux/slab.h>
38 static int pvr2_context_cleanup_flag;
39 static int pvr2_context_cleaned_flag;
49 signal_flag = (pvr2_context_notify_first ==
NULL);
52 pvr2_context_notify_last =
mp;
56 pvr2_context_notify_first =
mp;
76 if (signal_flag)
wake_up(&pvr2_context_sync_data);
80 static void pvr2_context_destroy(
struct pvr2_context *mp)
84 pvr2_context_set_notify(mp, 0);
96 if (!pvr2_context_exist_first) {
99 wake_up(&pvr2_context_sync_data);
106 static void pvr2_context_notify(
struct pvr2_context *mp)
108 pvr2_context_set_notify(mp,!0);
116 "pvr2_context %p (notify)", mp);
120 "pvr2_context %p (initialize)", mp);
123 (
void (*)(
void *))pvr2_context_notify,
133 "pvr2_context %p (thread skipping setup)",
143 for (ch1 = mp->
mc_first; ch1; ch1 = ch2) {
150 pvr2_context_destroy(mp);
156 static int pvr2_context_shutok(
void)
158 return pvr2_context_cleanup_flag && (pvr2_context_exist_first ==
NULL);
162 static int pvr2_context_thread_func(
void *
foo)
169 while ((mp = pvr2_context_notify_first) !=
NULL) {
170 pvr2_context_set_notify(mp, 0);
171 pvr2_context_check(mp);
174 pvr2_context_sync_data,
175 ((pvr2_context_notify_first !=
NULL) ||
176 pvr2_context_shutok()));
177 }
while (!pvr2_context_shutok());
179 pvr2_context_cleaned_flag = !0;
180 wake_up(&pvr2_context_cleanup_data);
185 pvr2_context_sync_data,
196 pvr2_context_thread_ptr =
kthread_run(pvr2_context_thread_func,
199 return (pvr2_context_thread_ptr ? 0 : -
ENOMEM);
205 pvr2_context_cleanup_flag = !0;
206 wake_up(&pvr2_context_sync_data);
208 pvr2_context_cleanup_data,
209 pvr2_context_cleaned_flag);
228 pvr2_context_exist_last =
mp;
232 pvr2_context_exist_first =
mp;
237 pvr2_context_destroy(mp);
241 pvr2_context_set_notify(mp, !0);
247 static void pvr2_context_reset_input_limits(
struct pvr2_context *mp)
249 unsigned int tmsk,mmsk;
271 int destroy_flag = 0;
276 if (destroy_flag) pvr2_context_notify(mp);
284 pvr2_context_notify(mp);
290 pvr2_context_enter(mp);
301 pvr2_context_exit(mp);
305 static void pvr2_channel_disclaim_stream(
struct pvr2_channel *cp)
317 pvr2_context_enter(mp);
319 pvr2_channel_disclaim_stream(cp);
320 pvr2_context_reset_input_limits(mp);
332 pvr2_context_exit(mp);
338 unsigned int tmsk,mmsk;
350 pvr2_context_enter(cp->
mc_head);
354 pvr2_context_reset_input_limits(cp->
mc_head);
359 if (p2 == cp)
continue;
363 if (!(tmsk & cmsk)) {
376 pvr2_context_exit(cp->
mc_head);
391 pvr2_context_enter(cp->
mc_head);
do {
392 if (sp == cp->
stream)
break;
393 if (sp && sp->
user) {
397 pvr2_channel_disclaim_stream(cp);
401 }
while (0); pvr2_context_exit(cp->
mc_head);
407 static char stream_sync_key[] = {
408 0x00, 0x00, 0x01, 0xba,
416 if (!cp)
return NULL;