Exemplo n.º 1
0
void Writer( void * arg )
{
	struct LOCKING_CONTEXT block;
	INDEX sequenceIndex=0;
	INDEX index;

	LockingInit( &block, LockingBlockNonBlocking, LockingWakeNonBlocking );

	while(1)
	{
		ResourceLockExclusive( &BufferLock, &block);

		while( !LockingIsAcquired( &block ) );
	
		//resource should be exlusive
		ASSERT( BufferLock.State == RESOURCE_EXCLUSIVE );

		sequenceIndex++;
		sequenceIndex%=SEQUENCE_LENGTH;

		for( index = 0; index < BUFFER_SIZE; index++ )
		{
			Buffer[index] = index + Sequence[ sequenceIndex ] ;
		}
		
		ResourceUnlockExclusive( &BufferLock );
		
		SchedulerStartCritical();
		TimesWritten++;
		SchedulerForceSwitch();
	}
}
Exemplo n.º 2
0
void WorkerInitItem( struct WORKER_QUEUE * queue, WORKER_FUNCTION foo, void * context, struct WORKER_ITEM * item  )
{
        //Its assumed that the caller of WorkerInitItem is the sole owner of the item
        //at the time it is called. This means we dont have to disable interrupts around
        //the init code.

        item->Foo = foo;
        LockingInit( &item->LockingContext, WorkerBlockOnLock, WorkerWakeOnLock );
        item->Context = context;


        //Now we are going to insert the work item into the list.
        WorkerAddItem(queue, item );
}