Changeset 1321
- Timestamp:
- 01/26/08 20:27:22 (7 months ago)
- Location:
- portaudio/branches/v19-devel/src/hostapi/coreaudio
- Files:
-
- 2 modified
-
pa_mac_core_utilities.c (modified) (9 diffs)
-
pa_mac_core_utilities.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
portaudio/branches/v19-devel/src/hostapi/coreaudio/pa_mac_core_utilities.c
r1318 r1321 61 61 #include <libkern/OSAtomic.h> 62 62 #include <strings.h> 63 #include <pthread.h> 64 #include "pa_memorybarrier.h" 63 65 64 66 PaError PaMacCore_SetUnixError( int err, int line ) … … 636 638 typedef struct PaMacXRunListNode_s PaMacXRunListNode; 637 639 640 /** Always empty, so that it can always be the one returned by 641 addToXRunListenerList. note that it's not a pointer. */ 642 static PaMacXRunListNode firstXRunListNode; 643 static int xRunListSize; 644 static pthread_mutex_t xrunMutex; 645 638 646 OSStatus xrunCallback( 639 647 AudioDeviceID inDevice, … … 645 653 PaMacXRunListNode *node = (PaMacXRunListNode *) inClientData; 646 654 647 node = node->next ; //skip the first node 648 649 for( ; node; node=node->next ) { 650 PaMacCoreStream *stream = node->stream; 651 652 if( stream->state != ACTIVE ) 653 continue; //if the stream isn't active, we don't care if the device is dropping 654 655 if( isInput ) { 656 if( stream->inputDevice == inDevice ) 657 OSAtomicOr32( paInputOverflow, (uint32_t *)&(stream->xrunFlags) ); 658 } else { 659 if( stream->outputDevice == inDevice ) 660 OSAtomicOr32( paOutputUnderflow, (uint32_t *)&(stream->xrunFlags) ); 655 int ret = pthread_mutex_trylock( &xrunMutex ) ; 656 657 if( ret == 0 ) { 658 659 node = node->next ; //skip the first node 660 661 for( ; node; node=node->next ) { 662 PaUtil_ReadMemoryBarrier(); 663 PaMacCoreStream *stream = node->stream; 664 665 if( stream->state != ACTIVE ) 666 continue; //if the stream isn't active, we don't care if the device is dropping 667 668 if( isInput ) { 669 if( stream->inputDevice == inDevice ) 670 OSAtomicOr32( paInputOverflow, (uint32_t *)&(stream->xrunFlags) ); 671 } else { 672 if( stream->outputDevice == inDevice ) 673 OSAtomicOr32( paOutputUnderflow, (uint32_t *)&(stream->xrunFlags) ); 674 } 661 675 } 676 677 pthread_mutex_unlock( &xrunMutex ); 662 678 } 663 679 … … 665 681 } 666 682 667 /** Always empty, so that it can always be the one returned by 668 addToXRunListenerList. note that it's not a pointer. */ 669 static PaMacXRunListNode firstXRunListNode; 670 static int xRunListSize; 671 672 void initializeXRunListenerList() 683 int initializeXRunListenerList() 673 684 { 674 685 xRunListSize = 0; 675 686 bzero( (void *) &firstXRunListNode, sizeof(firstXRunListNode) ); 676 } 677 void destroyXRunListenerList() 687 return pthread_mutex_init( &xrunMutex, NULL ); 688 } 689 int destroyXRunListenerList() 678 690 { 679 691 PaMacXRunListNode *node; … … 685 697 } 686 698 xRunListSize = 0; 699 return pthread_mutex_destroy( &xrunMutex ); 687 700 } 688 701 689 702 void *addToXRunListenerList( void *stream ) 690 703 { 704 pthread_mutex_lock( &xrunMutex ); 691 705 PaMacXRunListNode *newNode; 692 706 // setup new node: … … 694 708 newNode->stream = (PaMacCoreStream *) stream; 695 709 newNode->next = firstXRunListNode.next; 710 PaUtil_WriteMemoryBarrier(); 696 711 // insert: 697 712 firstXRunListNode.next = newNode; 713 pthread_mutex_unlock( &xrunMutex ); 698 714 699 715 return &firstXRunListNode; … … 702 718 int removeFromXRunListenerList( void *stream ) 703 719 { 720 pthread_mutex_lock( &xrunMutex ); 704 721 PaMacXRunListNode *node, *prev; 705 722 prev = &firstXRunListNode; … … 710 727 --xRunListSize; 711 728 prev->next = node->next; 729 PaUtil_WriteMemoryBarrier(); 712 730 free( node ); 731 pthread_mutex_unlock( &xrunMutex ); 713 732 return xRunListSize; 714 733 } … … 717 736 } 718 737 738 pthread_mutex_unlock( &xrunMutex ); 719 739 // failure 720 740 return xRunListSize; -
portaudio/branches/v19-devel/src/hostapi/coreaudio/pa_mac_core_utilities.h
r1318 r1321 218 218 void* inClientData ) ; 219 219 220 void initializeXRunListenerList(); 221 void destroyXRunListenerList(); 220 /** returns zero on success or a unix style error code. */ 221 int initializeXRunListenerList(); 222 /** returns zero on success or a unix style error code. */ 223 int destroyXRunListenerList(); 222 224 223 225 /**Returns the list, so that it can be passed to CorAudio.*/
