src/lib/gscphost/callbackregistries.c
gs_retval_t ftacallback_add_streamid(struct ringbuf * r, gs_uint32_t streamid) {
    gs_int32_t x;
    if (lstreamid == 0) {
        if ((fstreamid = malloc(sizeof(struct ftacallbackstreamid)*STARTSZ))==0) {
            gslog(LOG_EMERG,"ERROR:Out of memory ftacallback\n");
            return -1;
        }
        memset(fstreamid,0,sizeof(struct ftacallbackstreamid)*STARTSZ);
        lstreamid = STARTSZ;
    }
    /* first try to increment refcnt */
    for(x=0;(x<lstreamid)&&(
                            (fstreamid[x].streamid!=streamid)
                            ||(fstreamid[x].r!=r)
                            ||(fstreamid[x].refcnt<=0)) ;x++);
    if (x>=lstreamid) {
        /* now try to find empty slot */
        for(x=0;(x<lstreamid)&&(fstreamid[x].refcnt!=0);x++);
        if (x >= lstreamid) {
            gs_int32_t y;
            lstreamid = 2*lstreamid;
            if ((fstreamid =
                 realloc(fstreamid,sizeof(struct ftacallbackstreamid)*lstreamid))==0) {
                gslog(LOG_EMERG,"ERROR:Out of memory ftacallback\n");
                return -1;
            }
            for (y=x;y<lstreamid;y++) {
                fstreamid[y].refcnt=0;
                fstreamid[y].streamid=0;
            }
        }
        fstreamid[x].state=HFTA_RINGBUF_ATOMIC;
    	fstreamid[x].streamid=streamid;
    	fstreamid[x].r=r;
    }
    fstreamid[x].refcnt+=1;
    return 0;
}
/* associate ringbuffer with streamid (using refcounting) */
associate ringbuffer with streamid (using refcounting)
associate ringbuffer with streamid ( using refcounting )
gs_retval_t ftacallback_add_streamid(struct ringbuf * r, gs_uint32_t streamid) {
    gs_int32_t x;
    if (lstreamid == 0) {
        if ((fstreamid = malloc(sizeof(struct ftacallbackstreamid)*STARTSZ))==0) {
            gslog(LOG_EMERG,"ERROR:Out of memory ftacallback\n");
            return -1;
        }
        memset(fstreamid,0,sizeof(struct ftacallbackstreamid)*STARTSZ);
        lstreamid = STARTSZ;
    }
    for(x=0;(x<lstreamid)&&(
                            (fstreamid[x].streamid!=streamid)
                            ||(fstreamid[x].r!=r)
                            ||(fstreamid[x].refcnt<=0)) ;x++);
    if (x>=lstreamid) {
        for(x=0;(x<lstreamid)&&(fstreamid[x].refcnt!=0);x++);
        if (x >= lstreamid) {
            gs_int32_t y;
            lstreamid = 2*lstreamid;
            if ((fstreamid =
                 realloc(fstreamid,sizeof(struct ftacallbackstreamid)*lstreamid))==0) {
                gslog(LOG_EMERG,"ERROR:Out of memory ftacallback\n");
                return -1;
            }
            for (y=x;y<lstreamid;y++) {
                fstreamid[y].refcnt=0;
                fstreamid[y].streamid=0;
            }
        }
        fstreamid[x].state=HFTA_RINGBUF_ATOMIC;
    	fstreamid[x].streamid=streamid;
    	fstreamid[x].r=r;
    }
    fstreamid[x].refcnt+=1;
    return 0;
}
gs_retval_t ftacallback_add_streamid ( struct ringbuf * r , gs_uint32_t streamid ) { gs_int32_t x ; if ( lstreamid == 0 ) { if ( ( fstreamid = malloc ( sizeof ( struct ftacallbackstreamid ) * STARTSZ ) ) == 0 ) { gslog ( LOG_EMERG , " \n " ) ; return -1 ; } memset ( fstreamid , 0 , sizeof ( struct ftacallbackstreamid ) * STARTSZ ) ; lstreamid = STARTSZ ; } for ( x = 0 ; ( x < lstreamid ) && ( ( fstreamid [ x ] . streamid != streamid ) || ( fstreamid [ x ] . r != r ) || ( fstreamid [ x ] . refcnt <= 0 ) ) ; x ++ ) ; if ( x >= lstreamid ) { for ( x = 0 ; ( x < lstreamid ) && ( fstreamid [ x ] . refcnt != 0 ) ; x ++ ) ; if ( x >= lstreamid ) { gs_int32_t y ; lstreamid = 2 * lstreamid ; if ( ( fstreamid = realloc ( fstreamid , sizeof ( struct ftacallbackstreamid ) * lstreamid ) ) == 0 ) { gslog ( LOG_EMERG , " \n " ) ; return -1 ; } for ( y = x ; y < lstreamid ; y ++ ) { fstreamid [ y ] . refcnt = 0 ; fstreamid [ y ] . streamid = 0 ; } } fstreamid [ x ] . state = HFTA_RINGBUF_ATOMIC ; fstreamid [ x ] . streamid = streamid ; fstreamid [ x ] . r = r ; } fstreamid [ x ] . refcnt += 1 ; return 0 ; }
associate ringbuffer with streamid (using refcounting)
associate ringbuffer with streamid ( using refcounting )
/* first try to increment refcnt */ /* now try to find empty slot */