static void BAMReaderWhack(BAMReader *const self) { KThreadCancel(self->th); KThreadWait(self->th, NULL); BAMFileRelease(self->file); KConditionRelease(self->need_data); KConditionRelease(self->have_data); KLockRelease(self->lock); KThreadRelease(self->th); }
rc_t BAMReaderMake( const BAMReader **result, char const headerText[], char const path[] ) { rc_t rc; BAMReader *self = malloc(sizeof(BAMReader)); if ( self == NULL ) { *result = NULL; return RC(rcAlign, rcFile, rcConstructing, rcMemory, rcExhausted); } else { atomic32_set( & self->refcount, 1 ); rc = BAMFileMakeWithHeader( & self->file, headerText, "%s", path); if ( rc != 0 ) { free(self); *result = 0; } else *result = self; } self->nque = 0; self->rc = 0; self->eof = false; rc = KLockMake(&self->lock); if (rc == 0) { rc = KConditionMake(&self->have_data); if (rc == 0) { rc = KConditionMake(&self->need_data); if (rc == 0) { rc = KThreadMake(&self->th, BAMReaderThreadMain, self); if (rc == 0) return 0; KConditionRelease(self->need_data); } KConditionRelease(self->have_data); } KLockRelease(self->lock); } return rc; }
/* Whack */ rc_t VCursorWhack ( VCursor *self ) { #if VCURSOR_FLUSH_THREAD if ( self -> flush_thread != NULL ) { rc_t rc = KLockAcquire ( self -> flush_lock ); if ( rc == 0 ) { while ( self -> flush_state == vfBusy ) { MTCURSOR_DBG (( "VCursorWhack: waiting for thread to process\n" )); KConditionWait ( self -> flush_cond, self -> flush_lock ); } self -> flush_state = vfExit; KConditionSignal ( self -> flush_cond ); KLockUnlock ( self -> flush_lock ); } MTCURSOR_DBG (( "VCursorWhack: waiting on thread to exit\n" )); KThreadWait ( self -> flush_thread, NULL ); } MTCURSOR_DBG (( "VCursorWhack: finishing\n" )); KThreadRelease ( self -> flush_thread ); KConditionRelease ( self -> flush_cond ); KLockRelease ( self -> flush_lock ); #endif VCursorTerminatePagemapThread(self); return VCursorDestroy ( self ); }
/* Whack */ static rc_t KSemaphoreWhack ( KSemaphore *self ) { rc_t rc; if ( self -> waiting != 0 ) return RC ( rcPS, rcSemaphore, rcDestroying, rcSemaphore, rcBusy ); rc = KConditionRelease ( self -> cond ); if ( rc != 0 ) return ResetRCContext ( rc, rcPS, rcSemaphore, rcDestroying ); free ( self ); return 0; }