Пример #1
0
static void
mix_buffer(SDL_AudioDevice * audio, UInt8 * buffer)
{
    if (!audio->paused) {
#ifdef __MACOSX__
        SDL_mutexP(audio->mixer_lock);
#endif
        if (audio->convert.needed) {
            audio->spec.callback(audio->spec.userdata,
                                 (Uint8 *) audio->convert.buf,
                                 audio->convert.len);
            SDL_ConvertAudio(&audio->convert);
            if (audio->convert.len_cvt != audio->spec.size) {
                /* Uh oh... probably crashes here */ ;
            }
            SDL_memcpy(buffer, audio->convert.buf, audio->convert.len_cvt);
        } else {
            audio->spec.callback(audio->spec.userdata, buffer,
                                 audio->spec.size);
        }
#ifdef __MACOSX__
        SDL_mutexV(audio->mixer_lock);
#endif
    }

    DecrementAtomic((SInt32 *) & need_to_mix);
}
Пример #2
0
static void
process_request_queue( channel_t *ch )
{
	/* if somebody is already processing requests, increasing ring_lock
	 * will cause an extra iteration (thus other request _will_ be handled).
	 */
	if( IncrementAtomic( &ch->ring_lock ) )
		return;
	do {
		request_t *r;
		while( (r=(request_t*)dequeue(&ch->req_queue)) )
			if( process_request( ch, r ) )
				break;
	} while( DecrementAtomic(&ch->ring_lock) > 1 );
}
Пример #3
0
static void Mac_UnlockAudio(_THIS)
{
    SInt32 oldval;
         
    oldval = DecrementAtomic((SInt32 *) &audio_is_locked);
    if ( oldval != 1 )  /* != 1 means audio is still locked. */
        return;

    /* Did we miss the chance to mix in an interrupt? Do it now. */
    if ( BitAndAtomic (0xFFFFFFFF, (UInt32 *) &need_to_mix) ) {
        /*
         * Note that this could be a problem if you missed an interrupt
         *  while the audio was locked, and get preempted by a second
         *  interrupt here, but that means you locked for way too long anyhow.
         */
        mix_buffer (this, buffer[fill_me]);
    }
}
void releaseWorkerThread ( WorkerThreadRef worker )
{
    if ( !worker ) return;

    if ( 1 == DecrementAtomic( &worker->referenceCount ) ) {
        if ( 0 != worker->numberOfActiveRequests ) {
            DebugStr("\preleaseWorkerThread: reference count went to zero, but there are still active requests" );
        }

        ExitMoviesOnThread();
        
        pthread_detach( worker->workerThread );
        
        // ask worker thread to clean up and exit
        worker->shutdown = true;
        //POSIX sem_post( &worker->requestSemaphore );
        //POSIX sem_post( &worker->shutdownSemaphore ); // avoid race condition where busy thread disposes requestSemaphore before we post to it
        MPSignalSemaphore(worker->requestSemaphore);
        MPSignalSemaphore(worker->shutdownSemaphore); // avoid race condition where busy thread disposes requestSemaphore before we post to it
    }
Пример #5
0
void
AddNeighborhoodToList(char * neighborhood, UInt32 parentID)
{
    CFStringRef tempNeighborhood = NULL;
    CFComparisonResult result = -1;
    UInt32 neighborhoodID, i;
    
    
    if (neighborhood)
    {
        tempNeighborhood = CFStringCreateWithCString(NULL, neighborhood, CFStringGetSystemEncoding());
        if (tempNeighborhood)
        {
            // Check if the item is already in our list.  If it is, "result" will be kCFCompareEqualTo.
            for (i = 0; i < kMaxNeighborhoods; i++)
            {
                if (gData[i] && gNeighborhoodInfo.parentID[i] == parentID)
                {
                    result = CFStringCompare(tempNeighborhood, gData[i], kCFCompareCaseInsensitive);
                    if (result == kCFCompareEqualTo) break;
                }
            }        
            
            if (result != kCFCompareEqualTo)
            {
                // Only add the item if the parent neighborhood is open and visible in the Data Browser.
            	if ((gNeighborhoodInfo.isNeighborhoodOpen[parentID - 1] && gNeighborhoodInfo.isNeighborhoodVisible[parentID - 1]) || parentID == 0)
            	{
                    neighborhoodID = IncrementAtomic(&gNeighborhoodInfo.neighborhoodCount); 
                    
                    if (++neighborhoodID < kMaxNeighborhoods)
                    {   
                        gNeighborhoodInfo.parentID[neighborhoodID - 1] = parentID;
                        gData[neighborhoodID - 1] = CFStringCreateCopy(NULL, tempNeighborhood);
                    
                        AddDataBrowserItems(gDataBrowserControl, parentID, 1, &neighborhoodID, kNameColumn);
                    
                        if (parentID == kDataBrowserNoItem)
                        {
                            gNeighborhoodInfo.isDefaultNeighborhood[neighborhoodID - 1] = true;
                        }
                        else
                        {
                            gNeighborhoodInfo.isDefaultNeighborhood[neighborhoodID - 1] = false;
                        }                    
                    }
                    else
                    {
                        DecrementAtomic(&gNeighborhoodInfo.neighborhoodCount);
                    }
                }
            }
            else if (result == kCFCompareEqualTo)
            {   
                if (gNeighborhoodInfo.isNeighborhoodOpen[parentID - 1] && gNeighborhoodInfo.isNeighborhoodVisible[parentID - 1])
                {
                    neighborhoodID = i + 1;
                    
                    if (gNeighborhoodInfo.isNeighborhoodVisible[i] == false)
                    {
                    	AddDataBrowserItems(gDataBrowserControl, parentID, 1, &neighborhoodID, kNameColumn);
                	
                        if (gNeighborhoodInfo.isNeighborhoodOpen[i])
                        {
                            OpenDataBrowserContainer(gDataBrowserControl, neighborhoodID);	                        
                        }
                    }
                    else
                    {
                    	if (gNeighborhoodInfo.isNeighborhoodOpen[i])
                    	{
                            CancelServicesLookup(parentID);
                            CancelNeighborhoodLookup(parentID);
                            
                            InstallEventLoopTimer(GetMainEventLoop(), 0.3, 0, gMyStartLookupTimerUPP, (void *)(neighborhoodID), NULL);
                        }
                    }
                }
            }

            CFRelease(tempNeighborhood);
        		
        	
        }
        free(neighborhood);
    }
}