/* Make * create an empty queue object * * "capacity" [ IN ] - minimum queue length * always expands to a power of 2, i.e. providing * a length of 10 will result in a length of 16. */ LIB_EXPORT rc_t CC KQueueMake ( KQueue **qp, uint32_t capacity ) { rc_t rc; if ( qp == NULL ) rc = RC ( rcCont, rcQueue, rcConstructing, rcParam, rcNull ); else { KQueue *q; uint32_t cap = 1; while ( cap < capacity ) cap += cap; q = malloc ( sizeof * q - sizeof q -> buffer + cap * sizeof q -> buffer [ 0 ] ); if ( q == NULL ) rc = RC ( rcCont, rcQueue, rcConstructing, rcMemory, rcExhausted ); else { rc = KSemaphoreMake ( & q -> rc, 0 ); if ( rc == 0 ) { rc = KSemaphoreMake ( & q -> wc, cap ); if ( rc == 0 ) { rc = KLockMake ( & q -> rl ); if ( rc == 0 ) { rc = KLockMake ( & q -> wl ); if ( rc == 0 ) { q -> capacity = cap; q -> bmask = cap - 1; q -> imask = ( cap + cap ) - 1; q -> read = q -> write = 0; atomic32_set ( & q -> refcount, 1 ); q -> sealed = false; QMSG ( "%s: created queue with capacity %u, " "bmask %#032b, imask %#032b.\n" , __func__, q -> capacity, q -> bmask, q -> imask ); * qp = q; return 0; } KLockRelease ( q -> rl ); } KSemaphoreRelease ( q -> wc ); } KSemaphoreRelease ( q -> rc ); } free ( q ); } * qp = NULL; } return rc; }
LIB_EXPORT rc_t CC XFSTreeDepotMake ( const struct XFSTreeDepot ** Depot ) { rc_t RCt; struct XFSTreeDepot * TheDepot; RCt = 0; TheDepot = NULL; if ( Depot == NULL ) { return XFS_RC ( rcNull ); } * Depot = NULL; TheDepot = calloc ( 1, sizeof ( struct XFSTreeDepot ) ); if ( TheDepot == NULL ) { return XFS_RC ( rcExhausted ); } RCt = KLockMake ( & ( TheDepot -> mutabor ) ); if ( RCt == 0 ) { * Depot = TheDepot; } else { free ( TheDepot ); * Depot = NULL; } return RCt; } /* XFSTreeDepotMake () */
/*))) Two methods: _InitSidStorage() and _DisposeSidStorage() /// You should call them before and after (((*/ static rc_t CC _SidStorageInit () { rc_t RCt; struct KLock * tLock; RCt = 0; tLock = NULL; if ( _IsSidStorageGood () ) { return XFS_RC ( rcInvalid ); } RCt = KLockMake ( & tLock ); if ( RCt == 0 ) { BSTreeInit ( & _sSidStorage ); } if ( RCt == 0 ) { _sMutabor = tLock; } else { if ( tLock != NULL ) { KLockRelease ( tLock ); } } return RCt; } /* _SidStorageInit () */
rc_t SRAFastqFile_Open(const KFile** cself, const SRAListNode* sra, const FileOptions* opt) { rc_t rc = 0; SRAFastqFile* self; CALLOC( self, 1, sizeof( *self ) ); if( self == NULL ) { rc = RC( rcExe, rcFile, rcConstructing, rcMemory, rcExhausted ); } else { if ( ( rc = KFileInit( &self->dad, (const KFile_vt*)&SRAFastqFile_vtbl, "SRAFastqFile", "no-name", true, false ) ) == 0 ) { if ( ( rc = SRAListNode_TableOpen( sra, &self->stbl ) ) == 0 ) { if ( ( rc = SRATableGetKTableRead( self->stbl, &self->ktbl ) ) == 0 ) { if ( ( rc = KTableOpenIndexRead( self->ktbl, &self->kidx, opt->index ) ) == 0 ) { if ( ( rc = KLockMake( &self->lock ) ) == 0 ) { MALLOC( self->buf, opt->buffer_sz * ( opt->f.fastq.gzip ? 2 : 1 ) ); if ( self->buf == NULL ) { rc = RC( rcExe, rcFile, rcOpening, rcMemory, rcExhausted ); } else { self->file_sz = opt->file_sz; self->buffer_sz = opt->buffer_sz; if ( opt->f.fastq.gzip ) { self->gzipped = &self->buf[ opt->buffer_sz ]; } self->from = ~0; /* reset position beyond file end */ rc = FastqReaderMake( &self->reader, self->stbl, opt->f.fastq.accession, opt->f.fastq.colorSpace, opt->f.fastq.origFormat, false, opt->f.fastq.printLabel, opt->f.fastq.printReadId, !opt->f.fastq.clipQuality, false, opt->f.fastq.minReadLen, opt->f.fastq.qualityOffset, opt->f.fastq.colorSpaceKey, opt->f.fastq.minSpotId, opt->f.fastq.maxSpotId ); } } } } } if ( rc == 0 ) { *cself = &self->dad; } else { KFileRelease( &self->dad ); } } } 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; }
static rc_t KCipherManagerInit (KCipherManager * self) { rc_t rc; rc = KLockMake (&self->lock); if (rc == 0) { KRefcountInit (&self->refcount, 1, kciphermanager_classname, "init", "singleton"); } return rc; }
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; }
rc_t make_temp_registry( temp_registry ** registry, struct KFastDumpCleanupTask * cleanup_task ) { KLock * lock; rc_t rc = KLockMake ( &lock ); if ( rc == 0 ) { temp_registry * p = calloc( 1, sizeof * p ); if ( p == 0 ) { rc = RC( rcVDB, rcNoTarg, rcConstructing, rcMemory, rcExhausted ); ErrMsg( "make_temp_registry().calloc( %d ) -> %R", ( sizeof * p ), rc ); KLockRelease ( lock ); } else { VectorInit ( &p -> lists, 0, 4 ); p -> lock = lock; p -> cleanup_task = cleanup_task; *registry = p; } } return rc; }
rc_t CC XStatsMake ( const struct XStats ** Stats ) { rc_t RCt; struct XStats * Ret; RCt = 0; Ret = NULL; if ( Stats != NULL ) { * Stats = NULL; } Ret = calloc ( 1, sizeof ( struct XStats ) ); if ( Ret == NULL ) { return RC ( rcExe, rcNoTarg, rcProcessing, rcParam, rcExhausted ); } else { RCt = KLockMake ( & ( Ret -> mutabor ) ); if ( RCt == 0 ) { RCt = XStatsReset ( Ret ); if ( RCt == 0 ) { * Stats = ( const struct XStats * ) Ret; } } } if ( RCt != 0 ) { * Stats = NULL; if ( Ret != NULL ) { XStatsDispose ( Ret ); } } return RCt; } /* XStatMake () */
LIB_EXPORT rc_t CC XFSTreeDepotMake ( const struct XFSTreeDepot ** Depot ) { rc_t RCt; struct XFSTreeDepot * TheDepot; RCt = 0; TheDepot = NULL; if ( Depot == NULL ) { return XFS_RC ( rcNull ); } * Depot = NULL; TheDepot = calloc ( 1, sizeof ( struct XFSTreeDepot ) ); if ( TheDepot == NULL ) { return XFS_RC ( rcExhausted ); } RCt = KLockMake ( & ( TheDepot -> mutabor ) ); if ( RCt == 0 ) { * Depot = TheDepot; } else { free ( TheDepot ); * Depot = NULL; } /* pLogMsg ( klogDebug, " |<- TreeDepotMake ( $(tree) )", "tree=%p", ( void * ) * Depot ); */ return RCt; } /* XFSTreeDepotMake () */