thread preemption

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

thread preemption

I have a question with regards to thread synchronization on the dm6446
using open source kernel 2.6.18.

I am trying to figure out how to prevent the context from switching at
certain points in my application.
For example, when I call VIDENC1_create or VIDENC1_process, this seems
to open up the possibility of a context switch to another thread.
This is bad, and will cause the program to hang, particularly if the
other thread has file/hardware i/o in it.

So I would like to do something that I think should be easy, wrap the
calls to VIDENC1_create/process/etc in a critical section that prevents
the context from switching to another thread.
On a microcontroller I would just disable all interrupts and then
reenable them after the call.

I can't use a mutex, sema4, or a barrier as far as I know because the
thread would have to be switched to in order to check these. In other
words, if the thread is waiting on an interrupt/blocking function to
return, it can no longer be made to wait.
I don't want to make the main thread wait, because the interrupt that
will unblock the second thread can happen at any time, or not at all.

I have seen use of functions pthread_sched_prevent and
pthread_sched_resume, which look like they do what I would like. But
these do not seem to be part of my kernel or pthread library.
There is also preempt.h in the kernel which has preempt_disable and
preempt_enable, but these seem just for kernel mode code (i also tried
them and they don't do anything in the user mode app).

Is there any function that I am missing? Maybe some kind of scheduler
library that has a pause or a way to temporarily disable the switching
to a thread.
It has to be in there somewhere, I think this a basic embedded os feature.