예제 #1
0
void mono_partial_order_reductiont::compute_dc(unsigned i)
{	
  dependency_chaint::dependenciest dep(nr_threads, false);
  dependency_chaint &dc=dcs[i];

  if(thread_creators.count(i))
  {
    // created thread is woken up by its creator
    dep.push_back(false);
    dep[i]=true;
    dep[nr_threads]=false;
    dc.update(state.node_ref->dc, dep, i); // wakeup
  } 
  else 
  {
    for(unsigned j=0; j<nr_threads; ++j)
    {
      bool depend=!independent(reads[i], 
                               writes[i], 
                               state.threads[j].reads, 
                               state.threads[j].writes);
      dep[j]=i==j || depend;
    }

    dc.update(state.node_ref->dc, dep, i);  

    dc.set_writes(i, writes[i]);
    dc.set_reads(i, reads[i]);
  }
}
예제 #2
0
void GenData::gen_syn_data(std::vector<std::vector<float>> &data, int data_size, char code, char* fName) {
	float* pt = new float(data_dim);
	float* test;
	int timeOfArrival = 0;
	char txtfile[100];
	char binfile[100];
	numDims = data_dim;
	std::vector<float> aux;
	assert(code == 'i' || code == 'c' || code == 'a');
	size_t dataFileSize = sizeof(Rectangle) * (data_size + 10);
	sprintf(txtfile, "Data/%s.txt", fName);
	sprintf(binfile, "Data/%s.bin", fName);
	FILE* fout = fopen(txtfile, "w");// Save info about the data on a separate file
	fprintf(fout, "Distribution = %c", code);
	fprintf(fout, "\nDimension    = %d", data_dim);
	fprintf(fout, "\nData Size    = %d", data_size);
	fclose(fout);

	static bi::managed_mapped_file seg(bi::open_or_create, binfile, dataFileSize);// Create memory mapped file
	dataset_b* rects = seg.find_or_construct<dataset_b>
		("DATA")
		(seg.get_segment_manager());

	srand(time(NULL));

	for (unsigned long long i = 0; i < data_size; i++) {
		if (code == 'i')
			independent(pt);
		else if (code == 'c')
			correlated(pt);
		else if (code == 'a')
			anti_correlated(pt);

		//fprintf(fout, "\n");
		for (int j = 0; j < data_dim; j++) {
			//assert(pt[j]>=0 && pt[j]<=1.0);
			if (!(pt[j] >= 0 && pt[j] <= 1.0))
			{
				//printf("%d point is zero.",j);
				pt[j] = 0;
			}

			pt[j] = pt[j] * DOM_SZ;
			//fprintf(fout, "%f ", pt[j]);
			//printf("%f ",pt[j]);
		}
		rects->push_back(Rectangle(pt, pt, timeOfArrival, i));

		timeOfArrival += rand() % 10 + 1;
		//printf("\n");
	}
}
예제 #3
0
inline bool KNMusicTagM4a::findBox(const QString &targetName,
                                   KNMusicTagM4a::M4ABox &targetBox,
                                   const QList<KNMusicTagM4a::M4ABox> &boxList)
{
    //Find all the box of the expand list.
    for(auto i : boxList)
    {
        //Check the name of each box.
        if(i.name==targetName)
        {
            //Save the box.
            targetBox=i;
            //Make the target box independent.
            independent(targetBox);
            //We find the box successfully.
            return true;
        }
    }
    //We cannot find the target name in the box list.
    return false;
}
예제 #4
0
void SkFrameHolder::setAlphaAndRequiredFrame(SkFrame* frame) {
    const bool reportsAlpha = frame->reportsAlpha();
    const auto screenRect = SkIRect::MakeWH(fScreenWidth, fScreenHeight);
    const auto frameRect = frame_rect_on_screen(frame->frameRect(), screenRect);

    const int i = frame->frameId();
    if (0 == i) {
        frame->setHasAlpha(reportsAlpha || frameRect != screenRect);
        frame->setRequiredFrame(SkCodec::kNone);
        return;
    }


    const bool blendWithPrevFrame = frame->getBlend() == SkCodecAnimation::Blend::kPriorFrame;
    if ((!reportsAlpha || !blendWithPrevFrame) && frameRect == screenRect) {
        frame->setHasAlpha(reportsAlpha);
        frame->setRequiredFrame(SkCodec::kNone);
        return;
    }

    const SkFrame* prevFrame = this->getFrame(i-1);
    while (prevFrame->getDisposalMethod() == SkCodecAnimation::DisposalMethod::kRestorePrevious) {
        const int prevId = prevFrame->frameId();
        if (0 == prevId) {
            frame->setHasAlpha(true);
            frame->setRequiredFrame(SkCodec::kNone);
            return;
        }

        prevFrame = this->getFrame(prevId - 1);
    }

    const bool clearPrevFrame = restore_bg(*prevFrame);
    auto prevFrameRect = frame_rect_on_screen(prevFrame->frameRect(), screenRect);

    if (clearPrevFrame) {
        if (prevFrameRect == screenRect || independent(*prevFrame)) {
            frame->setHasAlpha(true);
            frame->setRequiredFrame(SkCodec::kNone);
            return;
        }
    }

    if (reportsAlpha && blendWithPrevFrame) {
        // Note: We could be more aggressive here. If prevFrame clears
        // to background color and covers its required frame (and that
        // frame is independent), prevFrame could be marked independent.
        // Would this extra complexity be worth it?
        frame->setRequiredFrame(prevFrame->frameId());
        frame->setHasAlpha(prevFrame->hasAlpha() || clearPrevFrame);
        return;
    }

    while (frameRect.contains(prevFrameRect)) {
        const int prevRequiredFrame = prevFrame->getRequiredFrame();
        if (prevRequiredFrame == SkCodec::kNone) {
            frame->setRequiredFrame(SkCodec::kNone);
            frame->setHasAlpha(true);
            return;
        }

        prevFrame = this->getFrame(prevRequiredFrame);
        prevFrameRect = frame_rect_on_screen(prevFrame->frameRect(), screenRect);
    }

    if (restore_bg(*prevFrame)) {
        frame->setHasAlpha(true);
        if (prevFrameRect == screenRect || independent(*prevFrame)) {
            frame->setRequiredFrame(SkCodec::kNone);
        } else {
            // Note: As above, frame could still be independent, e.g. if
            // prevFrame covers its required frame and that frame is
            // independent.
            frame->setRequiredFrame(prevFrame->frameId());
        }
        return;
    }

    SkASSERT(prevFrame->getDisposalMethod() == SkCodecAnimation::DisposalMethod::kKeep);
    frame->setRequiredFrame(prevFrame->frameId());
    frame->setHasAlpha(prevFrame->hasAlpha() || (reportsAlpha && !blendWithPrevFrame));
}
예제 #5
0
bool KNMusicTagM4a::parseTag(QFile &musicFile,
                             QDataStream &musicDataStream,
                             KNMusicAnalysisItem &analysisItem)
{
    Q_UNUSED(musicFile)
    //Some comments is from:
    //      http://atomicparsley.sourceforge.net/mpeg-4files.html
    //The m4a file is made of a number of atoms, now they are called 'boxes'.
    //   A box always begins with 4 bytes length and follows 4 bytes name.
    //And first we need to check the header box of the file. Its name is 'ftyp'
    //Check out the data.
    M4ABox ftypBox;
    if(!getBox(musicDataStream, ftypBox, true) ||
            ftypBox.name!="ftyp")
    {
        //This cannot be a m4a file.
        return false;
    }
    //Metadata to be used with iTunes comes in the ilst box inside the moov box.
    //The structure of the ilst is:
    /* moov         <-
     * |-udta
     * | |-meta
     * | | |-ilst
     */
    //We have to keep reading until we find out the moov box.
    M4ABox moovBox;
    while(moovBox.name!="moov")
    {
        //If we cannot find a box, means there's no "moov" box, return false.
        if(!getBox(musicDataStream, moovBox))
        {
            return true;
        }
    }
    //When we comes to here, we should find the "moov" box, expand the box to
    //find out the "udta" box.
    /* moov
     * |-udta       <-
     * | |-meta
     * | | |-ilst
     */
    QList<M4ABox> expandList;
    extractBox(moovBox, expandList);
    //Check the expand list.
    if(expandList.isEmpty())
    {
        return true;
    }
    //Generate a empty box for "udta" box.
    M4ABox udtaBox;
    //Find all the box of the expand list of the "moov" box.
    for(auto i : expandList)
    {
        //Check the name of each box.
        if(i.name=="udta")
        {
            //Save the udta box.
            udtaBox=i;
            //Make the udta box to independent box.
            independent(udtaBox);
            //Clear the moov box.
            clearBox(moovBox);
            break;
        }
    }
    //Check out the data.
    if(udtaBox.name.isEmpty())
    {
        //If the name of the udta box is still empty, means there's no udta box
        //in the moov box, then we are faild to parse.
        return true;
    }
    //Expand the "udta" box, and find "meta" box.
    /* moov
     * |-udta
     * | |-meta     <-
     * | | |-ilst
     */
    expandList.clear();
    extractBox(udtaBox, expandList);
    //Check the expand list.
    if(expandList.isEmpty())
    {
        return true;
    }
    //Generate a empty box for "meta" box.
    M4ABox metaBox;
    //Find all the box of the expand list of the "meta" box.
    for(auto i : expandList)
    {
        //Check the name of each box.
        if(i.name=="meta")
        {
            //Save the udta box.
            metaBox=i;
            //Make the meta box to independent box.
            independent(metaBox);
            //Clear the udta box.
            clearBox(udtaBox);
            break;
        }
    }
    //Check out the box.
    if(metaBox.name.isEmpty())
    {
        //If the name of the meta box is still empty, means we cannot find meta
        //box in the meta box, then we are finished to parse.
        return true;
    }
    //Okay, now we can parse the meta box.
    /* moov
     * |-udta
     * | |-meta
     * | | |-ilst   <-
     */
    //Generate a box for ilst.
    M4ABox ilstBox;
    //Extract the meta box.
    if(!findIlstBox(metaBox, ilstBox))
    {
        //Finished to parse the tag if we cannot file the ilst box.
        return true;
    }
    //Clear the meta box to recover the memory.
    clearBox(metaBox);
    //Okay we are now find out the ilst box. Extract the ilst box and we can now
    //fill our data to the detail info.
    expandList.clear();
    extractBox(ilstBox, expandList);
    //Check out the expand list.
    if(expandList.isEmpty())
    {
        //If there's no data inside the expand list, then our mission is
        //finished.
        return true;
    }
    //Write the expand list to the detail info.
    //Get the detail info.
    KNMusicDetailInfo &detailInfo=analysisItem.detailInfo;
    //Check all box inside the list.
    for(auto i : expandList)
    {
        //Check the name of the box.
        //If it's "covr", means we find out the album art box.
        if(i.name=="covr")
        {
            analysisItem.imageData["M4A"].append(QByteArray(i.data, i.size));
            //Continue to next box.
            continue;
        }
        //Check the index of the box inside the map.
        int atomIndex=m_atomIndexMap.value(i.name, -1);
        //If the atom index is -1, then we have to continue to the next box.
        if(atomIndex==-1)
        {
            continue;
        }
        //Check the data size.
        if(i.size<16)
        {
            continue;
        }
        //Get the data position.
        //Actually there's another box inside the box of the i.
        //We can just skip it to read the data.
        char *dataPosition=i.data+16;
        int dataSize=i.size-16;
        //Output box data to detail info.
        switch(atomIndex)
        {
        case TrackNumber:
            //Ensure the data is enough to set the track number and track count.
            if(dataSize>6)
            {
                //Pick up the third byte data of the position as the track
                //number.
                detailInfo.textLists[TrackNumber]=
                        QString::number(dataPosition[3]);
                //Pick up the fifth byte data of the position as the track
                //count.
                detailInfo.textLists[TrackCount]=
                        QString::number(dataPosition[5]);
            }
            break;
        case DiscNumber:
            //Ensure the data is enough to set the disc number and disc count.
            if(dataSize>6)
            {
                //Pick up the third byte data of the position as the disc
                //number.
                detailInfo.textLists[DiscNumber]=
                        QString::number(dataPosition[3]);
                //Pick up the fifth byte data of the position as the disc
                //count.
                detailInfo.textLists[DiscCount]=
                        QString::number(dataPosition[5]);
            }
            break;
        case Rating:
            if(dataSize>0)
            {
                //Turn the first byte into the rating data.
                detailInfo.textLists[Rating]=
                        QString::number((quint8)dataPosition[0]);
            }
            break;
        default:
            //Check out the data size first.
            if(dataSize>0)
            {
                //Set the whole data as the text data.
                setTextData(detailInfo.textLists[atomIndex],
                            QByteArray(dataPosition, dataSize));
            }
            break;
        }
    }
    return true;
}