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; }
/* Make * * "count" [ IN ] - initial count value */ LIB_EXPORT rc_t CC KSemaphoreMake ( KSemaphore **semp, uint64_t count ) { rc_t rc; if ( semp == NULL ) rc = RC ( rcPS, rcSemaphore, rcConstructing, rcParam, rcNull ); else { KSemaphore *sem = malloc ( sizeof * sem ); if ( sem == NULL ) rc = RC ( rcPS, rcSemaphore, rcConstructing, rcMemory, rcExhausted ); else { rc = KConditionMake( & sem -> cond ); if ( rc == 0 ) { sem -> avail = count; sem -> requested = 0; sem -> min_requested = 0; sem -> waiting = 0; sem -> uniform = false; * semp = sem; return 0; } free ( sem ); } * semp = NULL; } return rc; }
rc_t VTableCreateCursorWriteInt ( VTable *self, VCursor **cursp, KCreateMode mode, bool create_thread ) { rc_t rc; if ( cursp == NULL ) rc = RC ( rcVDB, rcCursor, rcCreating, rcParam, rcNull ); else { if ( self == NULL ) rc = RC ( rcVDB, rcTable, rcAccessing, rcSelf, rcNull ); else if ( self -> read_only ) rc = RC ( rcVDB, rcCursor, rcCreating, rcTable, rcReadonly ); #if VCURSOR_WRITE_MODES_SUPPORTED #error "expecting kcmInsert mode only" #else else if ( mode != kcmInsert ) rc = RC ( rcVDB, rcCursor, rcCreating, rcMode, rcUnsupported ); #endif else { VCursor *curs; #if LAZY_OPEN_COL_NODE if ( self -> col_node == NULL ) KMetadataOpenNodeUpdate ( self -> meta, & self -> col_node, "col" ); #endif rc = VCursorMake ( & curs, self ); if ( rc == 0 ) { rc = VCursorSupplementSchema ( curs ); #if VCURSOR_FLUSH_THREAD if ( rc == 0 && create_thread ) { rc = KLockMake ( & curs -> flush_lock ); if ( rc == 0 ) rc = KConditionMake ( & curs -> flush_cond ); if ( rc == 0 ) rc = KThreadMake ( & curs -> flush_thread, run_flush_thread, curs ); } if(rc == 0) rc = VCursorLaunchPagemapThread(curs); #endif if ( rc == 0 ) { * cursp = curs; return 0; } VCursorRelease ( curs ); } } * cursp = NULL; } return rc; }