[interfacekit] Re: BScreen (again)

"Ingo Weinhold" <bonefish@xxxxxxxxxxxxxxx> wrote:
> BPrivateScreen seems to have a sem_id member, which is acquired in 
> WaitForRetrace() -- if not yet initialized, the method gets the 
> sem_id 
> from the app server. I suspect, all threads of all applications wait 
> on 
> the same semaphore for the vertical blank. I wonder a bit, how this 
> works, but probably there is something like an undocumented 
> release_sem_etc() flag that releases the semaphore exactly as often 
> as 
> necessary to unblock all waiting threads.

What about this:

int32 *sWaitForRetraceWaiters = locationInSomeSharedMemory;
sem_id sRetraceSemaphore;

status_t
WaitForRetrace()
{
        atomic_add(sWaitForRetraceWaiters, 1);
        return acquire_sem(sRetraceSemaphore);
}


and in the driver:

int32 waiters = atomic_and(sWaitForRetraceWaiters, 0);
release_sem_etc(sRetraceSemaphore, waiters);

?
Not tested, but it should work safely AFAICT.

Adios...
   Axel.


Other related posts: