Beispiel #1
0
bool32 OSXDoNextWorkQueueEntry(platform_work_queue* Queue)
{
	bool32 WeShouldSleep = false;

	uint32 OriginalNextEntryToRead = Queue->NextEntryToRead;
	uint32 NewNextEntryToRead = (OriginalNextEntryToRead + 1) % ArrayCount(Queue->Entries);

	if(OriginalNextEntryToRead != Queue->NextEntryToWrite)
	{
        // NOTE(jeff): OSAtomicCompareAndSwapXXX functions return 1 if the swap took place, 0 otherwise!
		uint32 SwapOccurred = OSAtomicCompareAndSwapIntBarrier(OriginalNextEntryToRead,
															   NewNextEntryToRead,
															   (int volatile*)&Queue->NextEntryToRead);

		if (SwapOccurred)
		{
			platform_work_queue_entry Entry = Queue->Entries[OriginalNextEntryToRead];
			Entry.Callback(Queue, Entry.Data);
			//InterlockedIncrement((int volatile *)&Queue->CompletionCount);
			OSAtomicIncrement32Barrier((int volatile *)&Queue->CompletionCount);
		}
		else
		{
		}
	}
	else
	{
		WeShouldSleep = true;
	}

	return(WeShouldSleep);
}
Beispiel #2
0
int OSAtomicCompareAndSwapLongBarrier(long oldValue,long newValue,volatile long* target) {
    return OSAtomicCompareAndSwapIntBarrier((int)oldValue,(int)newValue,(volatile int*)target);
}
Beispiel #3
0
int OSAtomicCompareAndSwap32Barrier(int32_t oldValue,int32_t newValue,volatile int32_t* target) {
    return OSAtomicCompareAndSwapIntBarrier((int)oldValue,(int)newValue,(volatile int*)target);
}
Beispiel #4
0
int OSAtomicCompareAndSwapPtrBarrier(void* oldValue,void* newValue,void* volatile* target) {
    return OSAtomicCompareAndSwapIntBarrier((int)oldValue,(int)newValue,(volatile int*)target);
}