Changeset b959a8f
- Timestamp:
- Oct 6, 2016, 8:03:01 PM (8 years ago)
- Branches:
- sampler
- Children:
- 6cc2d9d
- Parents:
- 2f1ab3f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/synth/sampler.c
r2f1ab3f rb959a8f 28 28 29 29 #define HAVE_THREADS 1 30 #define READER_THREAD_ON 0 30 31 #if 0 31 32 #undef HAVE_THREADS … … 47 48 uint_t eof; // end of file is now 48 49 #ifdef HAVE_THREADS 49 pthread_t read_thread; // file reading thread 50 // file reading thread 51 pthread_t read_thread; 52 uint_t threaded_read; // use reading thread? 50 53 pthread_mutex_t read_mutex; 51 54 pthread_cond_t read_avail; … … 63 66 64 67 #ifdef HAVE_THREADS 68 static void *aubio_sampler_openfn(void *p); 65 69 static void *aubio_sampler_readfn(void *p); 70 static void aubio_sampler_open_opening_thread(aubio_sampler_t *o); 71 static void aubio_sampler_open_reading_thread(aubio_sampler_t *o); 72 static void aubio_sampler_close_opening_thread(aubio_sampler_t *o); 73 static void aubio_sampler_close_reading_thread(aubio_sampler_t *o); 66 74 #endif 67 75 … … 82 90 s->eof = 0; 83 91 s->opened = 0; 84 85 #ifdef HAVE_THREADS 92 s->available = 0; 93 94 #ifdef HAVE_THREADS 95 s->threaded_read = READER_THREAD_ON; 96 aubio_sampler_open_opening_thread(s); 97 if (s->threaded_read) { 98 aubio_sampler_open_reading_thread(s); 99 } 100 #endif 101 102 return s; 103 beach: 104 AUBIO_FREE(s); 105 return NULL; 106 } 107 108 #ifdef HAVE_THREADS 109 void aubio_sampler_open_opening_thread(aubio_sampler_t *s) { 86 110 pthread_mutex_init(&s->open_mutex, 0); 87 111 s->waited = 0; 88 112 s->open_thread = 0; 89 113 s->open_thread_running = 0; 90 114 } 115 116 void aubio_sampler_open_reading_thread(aubio_sampler_t *s) { 91 117 s->read_thread_finish = 0; 92 118 pthread_mutex_init(&s->read_mutex, 0); … … 94 120 pthread_cond_init (&s->read_request, 0); 95 121 pthread_create(&s->read_thread, 0, aubio_sampler_readfn, s); 96 #endif 97 return s; 98 beach: 99 AUBIO_FREE(s); 100 return NULL; 101 } 122 } 123 124 void aubio_sampler_close_opening_thread(aubio_sampler_t *o) { 125 // clean up opening thread 126 void *threadret; 127 pthread_mutex_destroy(&o->open_mutex); 128 if (o->open_thread_running) { 129 if (pthread_cancel(o->open_thread)) { 130 AUBIO_WRN("sampler: cancelling file opening thread failed\n"); 131 } 132 } 133 if (o->open_thread && pthread_join(o->open_thread, &threadret)) { 134 AUBIO_WRN("sampler: joining file opening thread failed\n"); 135 } 136 pthread_mutex_destroy(&o->open_mutex); 137 } 138 139 void aubio_sampler_close_reading_thread(aubio_sampler_t *o) { 140 // clean up reading thread 141 void *threadret; 142 if (!o->read_thread) return; 143 o->read_thread_finish = 1; 144 pthread_cond_signal(&o->read_request); 145 if (pthread_cancel(o->read_thread)) { 146 AUBIO_WRN("sampler: cancelling file reading thread failed\n"); 147 } 148 if (pthread_join(o->read_thread, &threadret)) { 149 AUBIO_WRN("sampler: joining file reading thread failed\n"); 150 } 151 pthread_mutex_destroy(&o->read_mutex); 152 pthread_cond_destroy(&o->read_avail); 153 pthread_cond_destroy(&o->read_request); 154 } 155 #endif 102 156 103 157 uint_t aubio_sampler_load( aubio_sampler_t * o, const char_t * uri ) … … 391 445 { 392 446 #ifdef HAVE_THREADS 393 void *threadret; 394 395 // clean up opening thread 396 pthread_mutex_destroy(&o->open_mutex); 397 if (o->open_thread_running) { 398 if (pthread_cancel(o->open_thread)) { 399 AUBIO_WRN("sampler: cancelling file opening thread failed\n"); 400 } 401 } 402 if (o->open_thread && pthread_join(o->open_thread, &threadret)) { 403 AUBIO_WRN("sampler: joining file opening thread failed\n"); 404 } 405 pthread_mutex_destroy(&o->open_mutex); 406 447 // close opening thread 448 aubio_sampler_close_opening_thread(o); 407 449 // close reading thread 408 o->read_thread_finish = 1; 409 pthread_cond_signal(&o->read_request); 410 if (pthread_cancel(o->read_thread)) { 411 AUBIO_WRN("sampler: cancelling file reading thread failed\n"); 412 } 413 if (pthread_join(o->read_thread, &threadret)) { 414 AUBIO_WRN("sampler: joining file reading thread failed\n"); 415 } 416 pthread_mutex_destroy(&o->read_mutex); 417 pthread_cond_destroy(&o->read_avail); 418 pthread_cond_destroy(&o->read_request); 450 aubio_sampler_close_reading_thread(o); 419 451 #endif 420 452 if (o->source) {
Note: See TracChangeset
for help on using the changeset viewer.