コード例 #1
0
ファイル: wave_writer.c プロジェクト: weinerjm/vgm2wav
void wave_write( short const* in, long remain )
{
	sample_count_ += remain;
	while ( remain )
	{
		if ( buf_pos >= buf_size )
			flush_();
		
		{
			unsigned char* p = &buf [buf_pos];
			long n = (buf_size - buf_pos) / sizeof (sample_t);
			if ( n > remain )
				n = remain;
			remain -= n;
			
			/* convert to LSB first format */
			while ( n-- )
			{
				int s = *in++;
				*p++ = (unsigned char) s;
				*p++ = (unsigned char) (s >> 8);
			}
			
			buf_pos = p - buf;
			assert( buf_pos <= buf_size );
		}
	}
}
コード例 #2
0
ファイル: block_id_factory.cpp プロジェクト: keoyeop/tfs
 uint64_t BlockIdFactory::generation(const bool verify)
 {
   mutex_.lock();
   ++count_;
   uint64_t id = ++global_id_;
   assert(id <= MAX_BLOCK_ID);
   bool flush_flag = false;
   if (count_ >= SKIP_BLOCK_NUMBER)
   {
     flush_flag = true;
     count_ = 0;
   }
   mutex_.unlock();
   int32_t ret = common::TFS_SUCCESS;
   if (flush_flag)
   {
     ret = flush_(id);
     if (common::TFS_SUCCESS != ret)
     {
       TBSYS_LOG(WARN, "update global block id failed, id: %"PRI64_PREFIX"u, ret: %d", id, ret);
     }
   }
   if (common::TFS_SUCCESS == ret)
   {
     if (verify)
       id |= 0x8000000000000000;
   }
   return id;
 }
コード例 #3
0
ファイル: block_id_factory.cpp プロジェクト: keoyeop/tfs
 int BlockIdFactory::update(const uint64_t id)
 {
   bool flush_flag = false;
   uint64_t tmp_id = IS_VERFIFY_BLOCK(id) ? id & 0x7FFFFFFFFFFFFFFF : id;
   int32_t ret = (common::INVALID_BLOCK_ID == id) ? common::EXIT_PARAMETER_ERROR : common::TFS_SUCCESS;
   if (common::TFS_SUCCESS == ret)
   {
     tbutil::Mutex::Lock lock(mutex_);
     ++count_;
     global_id_ = std::max(global_id_, tmp_id);
     if (count_ >= SKIP_BLOCK_NUMBER)
     {
       flush_flag = true;
       count_ = 0;
     }
   }
   if (common::TFS_SUCCESS == ret && flush_flag)
   {
     ret = flush_(tmp_id);
     if (common::TFS_SUCCESS != ret)
     {
       TBSYS_LOG(WARN, "flush global block id failed, id: %"PRI64_PREFIX"u, ret: %d", tmp_id, ret);
     }
   }
   return ret;
 }
コード例 #4
0
ファイル: block_id_factory.cpp プロジェクト: keoyeop/tfs
 int BlockIdFactory::destroy()
 {
   int32_t ret = common::TFS_SUCCESS;
   if (fd_ > 0)
   {
     ret = flush_(global_id_);
     ::close(fd_);
   }
   return ret;
 }
コード例 #5
0
ファイル: fork_.c プロジェクト: dank101/4.4BSD-Alpha
long fork_()
{
	long i;

	for (i = 0; i < MXUNIT; i++)
		flush_(&i);
	i = (long)fork();
	if (i < 0)
		return((long)(-errno));
	return(i);
}
コード例 #6
0
ファイル: qlog.c プロジェクト: Zengwn/qlibc
/**
 * qlog->free(): Close ratating-log file & de-allocate resources
 *
 * @param log       a pointer of qlog_t
 */
static void free_(qlog_t *log) {
    if (log == NULL)
        return;

    flush_(log);
    Q_MUTEX_ENTER(log->qmutex);
    if (log->fp != NULL) {
        fclose(log->fp);
        log->fp = NULL;
    }
    Q_MUTEX_LEAVE(log->qmutex);
    Q_MUTEX_DESTROY(log->qmutex);
    free(log);
    return;
}
コード例 #7
0
ファイル: event.c プロジェクト: marayl/aug
static aug_result
loadcasptr_(aug_events_t events, struct link_** head)
{
    for (;;) {
        *head = aug_acqptr(&events->shared_);
        if (head) {
            /* Defensive: return null if wakeup marker has already been
            published by this (the only) consumer. This should only happen if
            consumer has read more than once without polling the event
            descriptor for readability -- and no event was available on each
            occasion. */
            if (WAKEUP_ == *head) {
                *head = NULL;
                break;
            }
            /* Replace head with null. */
            if (aug_casptr(&events->shared_, *head, NULL)) {
                /* Shread stack has now been transferred to head. */
                if (0 < events->wakeups_) {
                    /* Flush each wakeup written by producers. */
                    aug_rsize rsize = flush_(events->mds_[0],
                                             events->wakeups_);
                    if (rsize < 0)
                        return -1;
                    /* Reduce wakeups by actual number read. The result may be
                       zero as the publisher is not gauranteed to have written
                       by this time.
                    */
                    events->wakeups_ -= rsize;
                }
                break;
            }
        } else {
            /* Replace null head with wakeup marker, indicating that the
               consumer will wait until woken. */
            if (aug_casptr(&events->shared_, NULL, WAKEUP_)) {
                /* Consumer should now proceed to wait on event descriptor
                   readability. */
                ++events->wakeups_;
                break;
            }
        }
        /* Modification detected, so continue. */
    }
    /* Head is either shared stack or null. */
    return 0;
}
コード例 #8
0
/*
 *  _flushall - flush all connected Fortran units except 100, 101, 102.
 */
void
_flushall(void)
{
    int	ret;
    register short	errflag;
    static short	pass = 0; /* incremented when _flushall is called */
    unit		*uptr;

    if (pass++ >= 1)
        return;

    errflag	= 0;
    /*
     *	Find all open Fortran units not connected by
     *	WOPEN/OPENMS/OPENDR/AQOPEN and flush them.
     */
    uptr	= _get_next_unit(NULL, 0, 0);

    while (uptr != NULL) {     /* while more open units */
#ifdef KEY /* Bug 6433 */
        _f_int4	unum;
#else /* KEY Bug 6433 */
        unum_t	unum;
#endif /* KEY Bug 6433 */

        unum	= uptr->uid;

        if (OPEN_UPTR(uptr) && uptr->ufs != FS_AUX) {
            flush_( &unum );
        }
        uptr	= _get_next_unit(uptr, 0, 0);
    }
    /*
     *	Flush C files on mips because the C cleanup routine will not
     *	be executed if the code is loaded using the f90 command.  So
     *	Fortran fork_ processing must flush stdout and any user C
     *	files in addition to the Fortran files.
     */
    (void) fflush(NULL);
    return;
}
コード例 #9
0
ファイル: wave_writer.c プロジェクト: weinerjm/vgm2wav
void wave_write_header( void )
{
	if ( file )
	{
		/* generate header */
		unsigned char h [header_size] =
		{
			'R','I','F','F',
			0,0,0,0,        /* length of rest of file */
			'W','A','V','E',
			'f','m','t',' ',
			0x10,0,0,0,     /* size of fmt chunk */
			1,0,            /* uncompressed format */
			0,0,            /* channel count */
			0,0,0,0,        /* sample rate */
			0,0,0,0,        /* bytes per second */
			0,0,            /* bytes per sample frame */
			16,0,           /* bits per sample */
			'd','a','t','a',
			0,0,0,0,        /* size of sample data */
			/* ... */       /* sample data */
		};
		long ds = sample_count_ * sizeof (sample_t);
		int frame_size = chan_count * sizeof (sample_t);
		
		set_le32( h + 0x04, header_size - 8 + ds );
		h [0x16] = chan_count;
		set_le32( h + 0x18, sample_rate_ );
		set_le32( h + 0x1C, sample_rate_ * frame_size );
		h [0x20] = frame_size;
		set_le32( h + 0x28, ds );
		
		flush_();
		
		/* write header */
		fseek( file, 0, SEEK_SET );
		fwrite( h, sizeof h, 1, file );
    }
}
コード例 #10
0
ファイル: dl_snopt1.C プロジェクト: distanceModling/DAKOTA
 static void
my_findopt(void *v, Optimizer1 *D, char *options)
{
	Dakota_probsize *ps;
	Opt_Info OI(options);
	RealMatrix const *RMe, *RMi;
	RealVector const *Ru,  *Rv;
	Snopt_Details *T, *T0;
	char *cu, *cw, *ve;
	double *A, *bl, *bu, f, objadd, *pi, *rc, *ru, *rw, sinf, t, *x;
	int co, i, i1, inform, j, k, k1, lencu, lencw, leniu, leniw, lenru, lenrw;
	int m, mincw, miniw, minrw, n, ninf, nlc, nlce, nlci, nlnz;
	int nm, nname, nnjac, nnlc, nnobj, ns, nz;
	int *hs, *ind, *iu, *iw, *loc;
	size_t L, Lc, Li;
	ftnlen cu_len, cw_len, prob_len, start_len;

	T0 = snopt_details;
	snopt_details = T = (Snopt_Details *)v;
	T->D = D;	//should be unnecessary
	ps = DF->ps;
	T->nf = 0;
	T->n = n = ps->n_var;
	T->nnlc = nnlc = ps->n_nlinc;
	T->co = co = ps->n_obj;
	T->numgflag = ps->numgflag;
	T->maxfe = ps->maxfe;
	nlc = ps->n_linc;
	T->m = m = nlc + nnlc;
	// Since Dakota does not provide sparsity information,
	// we simply assume all variables are nonlinear and
	// involved with every nonlinear function.
	nlnz = nnlc * n;
	loc = new int[n + 1];
	memset(loc, 0, n*sizeof(int));
	RMe = linear_eq_constraint_coeffs(D);
	nlce = RMe->numRows();
	for(i = 0; i < nlce; i++) {
		for(j = 0; j < n; j++)
			if ((*RMe)[i][j] != 0.)
				++loc[j];
		}
	RMi = linear_ineq_constraint_coeffs(D);
	nlci = RMi->numRows();
	for(i = 0; i < nlci; i++) {
		for(j = 0; j < n; j++)
			if ((*RMi)[i][j] != 0.)
				++loc[j];
		}
	for(i = nz = 0; i < n; i++) {
		j = loc[i];
		loc[i] = nz;
		nz += j + nnlc;
		}
	ind = new int[nz];
	A = new double[nz];
	memset(A, 0, nz*sizeof(double));
	for(i = 0; i < n; i++) {
		j = loc[i];
		for(k = 1; k <= nnlc; k++)
			ind[j++] = k;
		loc[i] = j;
		}
	for(i = 0; i < nlce; ++i) {
		i1 = i + nnlc + 1;
		for(j = 0; j < n; j++)
			if ((t = (*RMe)[i][j]) != 0.) {
				k = loc[j]++;
				ind[k] = i1;
				A[k] = t;
				}
		}
	for(i = 0; i < nlci; ++i) {
		i1 = i + nnlc + 1;
		for(j = 0; j < n; j++)
			if ((t = (*RMi)[i][j]) != 0.) {
				k = loc[j]++;
				ind[k] = i1;
				A[k] = t;
				}
		}
	for(i = n; i > 0; --i)
		loc[i] = loc[i-1] + 1;
	loc[0] = 1;

	lencw = leniw = lenrw = 500;
	rw = new double[lenrw];
	iw = new int[leniw];
	cw = new char[lencw*8];
	mincw = miniw = minrw = -1;
	cu_len = cw_len = prob_len = 8;
	nnjac = nnobj = n;	//snmemb_ may clobber nnjac and nnobj if nnlc == 0
	i = j = 0;
	sninit_(&i, &j, cw, &lencw, iw, &leniw, rw, &lenrw, cw_len);
	snmemb_(&m, &n, &nz, &nlnz, &nnlc, &nnjac, &nnobj, &mincw, &miniw, &minrw,
		cw, &lencw, iw, &leniw, rw, &lenrw, cw_len);
	delete[] cw;
	delete[] iw;
	delete[] rw;
	i = 20 * (m + n);
	leniw = miniw + i;
	lenrw = minrw + i;
	lencw = mincw;
	nm = n + m;
	L = lenrw + 3*nm + 2*n + m + 1;
	rw = new double[L];
	memset(rw, 0, L*sizeof(double));
	bl = rw + lenrw;
	bu = bl + nm;
	rc = bu + nm;
	pi = rc + nm;
	x = pi + m;
	T->Lastx = x + n;
	ru = T->Lastx + n;
	Li = leniw + 1 + nm;
	iw = new int[Li];
	memset(iw, 0, Li*sizeof(int));
	hs = iw + leniw;
	iu = hs + nm;
	Lc = lencw*8;
	cw = new char[Lc + 8];
	memset(cw, 0, Lc + 8);
	cu = cw + Lc;
	start_len = 4;
	lencu = leniu = lenru = 1;
	i = 6;	// detailed output
	j = 0;	// no summary output
	// Look for initial outlev = n:
	// n & 1 ==> want detailed output; n & 2 ==> summary output
	if (dlsolver_option(&OI)) {
		if (!strncmp(OI.name, "outlev", OI.name_len)) {
			k = (int)strtol(OI.val, &ve, 10);
			if (ve > OI.val) {
				i = k & 1 ? 6 : 0;
				j = k & 2 ? 6 : 0;
				}
			}
		else
			OI.begin = options;	// reset
		}
	sninit_(&i, &j, cw, &lencw, iw, &leniw, rw, &lenrw, cw_len);
	Rv = continuous_lower_bounds(D);
	Ru = continuous_upper_bounds(D);
	k = Rv->length();
	for(i = 0; i < k; i++) {
		bl[i] = (*Rv)[i];
		bu[i] = (*Ru)[i];
		}
	Rv = nonlinear_ineq_constraint_lower_bounds(D);
	Ru = nonlinear_ineq_constraint_upper_bounds(D);
	k = Rv->length();
	for(j = 0; j < k; ++j, ++i) {
		bl[i] = (*Rv)[j];
		bu[i] = (*Ru)[j];
		}
	Rv = nonlinear_eq_constraint_targets(D);
	k = Rv->length();
	for(j = 0; j < k; ++j, ++i)
		bl[i] = bu[i] = (*Rv)[j];
	Rv = linear_eq_constraint_targets(D);
	k = Rv->length();
	for(j = 0; j < k; ++j, ++i)
		bl[i] = bu[i] = (*Rv)[j];
	Rv = linear_ineq_constraint_lower_bounds(D);
	Ru = linear_ineq_constraint_upper_bounds(D);
	k = Rv->length();
	for(j = 0; j < k; j++, i++) {
		bl[i] = (*Rv)[j];
		bu[i] = (*Ru)[j];
		}
	j = 0;
	while(dlsolver_option(&OI)) {
		inform = 0;
		snset_(OI.name, &j, &j, &inform, cw, &lencw, iw, &leniw, rw, &lenrw,
			(ftnlen)OI.all_len, cw_len);
		printf(inform	? "\n**** Rejecting \"%.*s\"****\n"
				: "accepted snopt option: %.*s\n", OI.all_len, OI.name);
		}
	GetContVars(D, n, x);
	f = std::numeric_limits<double>::infinity();
	nname = 1;	// no names
	objadd = sinf = 0.;
	inform = ns = ninf = 0;
	if (x[0] == 0.)
		T->Lastx[0] = 1.; // ensure Lastx != x;
	snopt_("Cold", &m, &n, &nz, &nname, &nnlc, &nnobj, &nnjac, &m, &objadd,
		"dakotapr", funcon, funobj, A, ind, loc,
		bl, bu, cu, hs, x, pi, rc, &inform, &mincw, &miniw,
		&minrw, &ns, &ninf, &sinf, &f, cu, &lencu,
		iu, &leniu, ru, &lenru, cw, &lencw, iw, &leniw,
		rw, &lenrw, start_len, prob_len, cu_len,
		cu_len, cw_len);
	flush_();	// flush Fortran buffers
	if (inform > 1) {
		f = std::numeric_limits<double>::infinity();
		printf("snopt returned inform = %d\n", inform);
		}
	SetBestContVars(D, n, x);
	if (!ps->multiobj) {
		Real bestf[m+1];
		bestf[0] = f;
		for (i = 0; i < m; i++)
			bestf[i+1] = x[i];
		SetBestRespFns(D, m+1, bestf);
		}
	delete[] cw;
	delete[] iw;
	delete[] rw;
	delete[] A;
	delete[] ind;
	delete[] loc;
	}
コード例 #11
0
void FailOverCacheAsyncBridge::Flush()
{
    LOCK();
    flush_();
}
コード例 #12
0
ファイル: queue.hpp プロジェクト: maoy/mosaic
 void close()
 {
   typename boost::mutex::scoped_lock lock( mtx_);
   deactivate_();
   flush_();
 }
コード例 #13
0
ファイル: queue.hpp プロジェクト: maoy/mosaic
 void flush()
 {
   typename boost::mutex::scoped_lock lock( mtx_);
   flush_();
 }