Esempio n. 1
0
test_case(p2, mux) {
  bool a[8], b[8], c[8];

  str_to_bits8(a, "00000000");
  str_to_bits8(b, "11111111");
  mux(c, T, a, b);
  assert_eq8(a, c);
  mux(c, F, a, b);
  assert_eq8(b, c);
}
int main()
{
  // 8 to 3 encoder test (using vec<bool>)
  std::vector<bool> vb_in(8,0);
  vb_in[4] = true; // 10000
  std::vector<bool> vb_out = encoder(vb_in);
  reverse_print_vector(vb_in);
  std::cout << " --> [encoder] --> ";
  reverse_print_vector(vb_out);
  std::cout << "\n\n";

  // 3 to 8 decoder test (using vec<bool>)
  std::vector<bool> vb_out2 = decoder(vb_out); // using output from encoder from last test
  reverse_print_vector(vb_out);
  std::cout << " --> [decoder] --> ";
  reverse_print_vector(vb_out2);
  std::cout << "\n\n";

  // 8 to 1 muxer test, using input from 8 to 3 encoder test
  std::vector<bool> sw(3,0); // switch input for muxer, set to 100
  sw[2] = true;

  std::vector<bool> muxer_out = mux(vb_in, sw);
  reverse_print_vector(vb_in);
  std::cout << " --- > +-----+ " << "\n";
  std::cout << "               | mux | --> "; 
  reverse_print_vector(muxer_out);
  std::cout << "\n";
  reverse_print_vector(sw);
  std::cout << "      --- > +-----+\n";
}
Esempio n. 3
0
/**@ingroup gen_mux
 *
 */
int work(void **inp, void **out) {
	int i;
	int out_len;
	int nof_active_inputs;

	nof_active_inputs = 0;
	for (i=0;i<nof_inputs;i++) {
		input_lengths[i] = get_input_samples(i);
		nof_active_inputs++;
	}

	if (exclusive && nof_active_inputs>1) {
		moderror_msg("Exclusive mux but %d inputs have data\n",nof_active_inputs);
		return -1;
	}
	if(check_all && (nof_active_inputs<nof_inputs)) {
		moderror_msg("Only %d/%d inputs have data\n",nof_active_inputs,nof_inputs);
		return -1;
	}
	if (!out[0]) {
		moderror("Output not ready\n");
		return -1;
	}
	out_len = sum_i(input_lengths,nof_inputs);
	if (out_len) {
		mux(inp,out[0],input_lengths,input_padding_pre,nof_inputs,input_sample_sz);
	}
	return out_len;
}
Esempio n. 4
0
File: mlpx.c Progetto: bytemine/ut
void mlpx_printf (int id, int flags, const char *fmt, ...)
{
va_list ap;
msg_t *m;
int l;

    if (!chmap[id]) {
	/* invalid channel */
	if (id == CHN_MSG)		/* huh, must not happen */
	    exit (EXIT_FAILURE);	/* avoid inf. recursion */

	mlpx_printf (CHN_MSG, MF_ERR,
			"internal error: channel %02X does not exist\n", id);
	return;
    }

    va_start(ap, fmt);

    m = sec_malloc (sizeof(msg_t) + MLPX_PRINTF_MAX + 1);	/* may exit */
    m->next = 0;

    l = vsnprintf (m->data, MLPX_PRINTF_MAX + 1, fmt, ap);
    va_end(ap);

    m->len = l;
    m->flags = flags | MF_PLAIN;	/* no prefix yet */

    mux (m, chmap[id]);

    return;
}
Esempio n. 5
0
int main(int argc, char **argv) {
    ros::init(argc, argv, "mux_node");
    ros::NodeHandle nh;
    command_mux::MoveBaseMux mux(nh, "mux_control", "mux_message", "move_base");
    ros::Rate loop_rate(10);
    while(nh.ok()) {
        mux.SendNextGoal();
        ros::spinOnce();
        loop_rate.sleep();
    }
}
Esempio n. 6
0
int main (void)
{
	static FILE *fp = 0;
	unsigned int ret;
	tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

	printf("\nINFO: Starting %s example.\r\n", "blink");
	/* Initialize the PRU */
	prussdrv_init ();		

	// Set ADC CS
	if((fp=fopen("/sys/class/gpio/export", "w"))==NULL){
		printf("Cannot open GPIO file 62.\n");
		return (1);
	}
	fprintf(fp,"62");
	fclose(fp);

	if((fp=fopen("/sys/class/gpio/gpio62/direction", "w"))==NULL){
		printf("cannot open gpio direction file.\n");
		return(1);
	}
	fprintf(fp,"out");
	fclose(fp);
	mux("lcd_pclk",0x0d);

	/* Open PRU Interrupt */
	ret = prussdrv_open(PRU_EVTOUT_0);
	if (ret)
	{
		printf("prussdrv_open open failed\n");
		return (ret);
    }
    
    /* Get the interrupt initialized */
    prussdrv_pruintc_init(&pruss_intc_initdata);

    /* Execute example on PRU */
    printf("\tINFO: Executing example.\r\n");
    prussdrv_exec_program (PRU_NUM, "./blink.bin");
    
    /* Wait until PRU0 has finished execution */
    printf("\tINFO: Waiting for HALT command.\r\n");
    prussdrv_pru_wait_event (PRU_EVTOUT_0);
    printf("\tINFO: PRU completed transfer.\r\n");
    prussdrv_pru_clear_event (PRU0_ARM_INTERRUPT);

    /* Disable PRU and close memory mapping*/
    prussdrv_pru_disable (PRU_NUM);
    prussdrv_exit ();

    return(0);
}
Esempio n. 7
0
/**@ingroup gen_mux
 *
 */
int work(void **inp, void **out) {
	int i;
	int out_len;

	for (i=0;i<nof_inputs;i++) {
		input_lengths[i] = get_input_samples(i);
	}
	out_len = sum_i(input_lengths,nof_inputs);
	if (out_len) {
		mux(inp,out[0],input_lengths,input_padding_pre,nof_inputs,input_sample_sz);
	}
	return out_len;
}
Esempio n. 8
0
void WaitForAllTasks() {
	std::unique_lock<std::mutex> mux(tasksRunningConditionMutex);
	while (numUnfinishedTasks > 0) {
		std::cout << "waiting tasksRunningCondition" << std::endl;
		tasksRunningCondition.wait(mux);
	}
	//	for (int i = 0; i < CORE_NUM; ++i) {
	//			delete threads[i];
	//	}
	delete[] threads;
	threads=nullptr;
	std::cout << "all tasks OK" << std::endl;
}
Esempio n. 9
0
int
main(int argc, char **argv) {
  options_t options;
  char *format;

  /* Parse options. */
  static struct option longopts[] = {
    {"help", no_argument, NULL, 'h'},
    {NULL, 0, NULL, 0}
  };
  const char *optstring = "h";
  char opt;
  while ((opt = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) {
    switch (opt) {
      case 'h':
        usage(argv[0], 0);
        break;
      default:
        fprintf(stderr, "unrecognized option '%c'\n", opt);
        usage(argv[0], 1);
        break;
    }
  }

  if (argc - optind == 0) {
    fprintf(stderr, "missing FORMAT and INPUT...\n");
    usage(argv[0], 1);
  }

  format = *(argv + optind);
  if (strcmp(format, "db") == 0) {
    options.format = FMT_DB;
  } else if (strcmp(format, "json") == 0) {
    options.format = FMT_JSON;
  } else {
    fprintf(stderr, "invalid input format '%s'\n", format);
    exit(1);
  }

  options.input_count = argc - optind - 1;
  if (options.input_count == 0) {
    fprintf(stderr, "missing INPUT...\n");
    usage(argv[0], 1);
  }

  options.inputs = argv + optind + 1;

  exit(mux(&options));
}
Esempio n. 10
0
//_________________________
uint8_t ADM_aviUISetMuxer(  void )
{

//	return DIA_setUserMuxParam ((int *) &muxMode, (int *) &muxParam, (int *) &muxSize);
    uint32_t mux_n_frame=muxParam;
    uint32_t mux_size_block=muxParam;
    uint32_t mux_mode=(uint32_t)muxMode;


    diaMenuEntry muxingType[]= {
        {MUX_REGULAR,QT_TR_NOOP("Normal")},
        {MUX_N_FRAMES,QT_TR_NOOP("Mux every N video frames")},
        {MUX_N_BYTES,QT_TR_NOOP("Mux by packet size")}
    };

    diaElemMenu      mux(&(mux_mode),QT_TR_NOOP("Muxing _type:"),3,muxingType);
    diaElemUInteger blockSize(&(muxSize),QT_TR_NOOP("_Split every MB:"),1,9000);

    diaElemUInteger n_frames(&(mux_n_frame),QT_TR_NOOP("Mux _every x video frames:"),1,100);
    diaElemUInteger n_block(&(mux_size_block),QT_TR_NOOP("Mux in _blocks of x bytes:"),1,50000);


    mux.link(&(muxingType[1]),1,&n_frames);
    mux.link(&(muxingType[2]),1,&n_block);

    diaElem *elems[4]= {&mux,&n_frames,&n_block,&blockSize};
    if( diaFactoryRun(QT_TR_NOOP("AVI Muxer Options"),4,elems))
    {
        muxMode=(PARAM_MUX)mux_mode;
        switch(muxMode)
        {
        case MUX_REGULAR:
            muxParam=1;
            break;
        case MUX_N_FRAMES:
            muxParam=mux_n_frame;
            break;
        case MUX_N_BYTES:
            muxParam=mux_size_block;
            break;
        default:
            ADM_assert(0);
        }
        return 1;
    }
    return 0;
};
Esempio n. 11
0
bool ffTSConfigure(void)
{
        uint32_t muxRate=(uint32_t)tsMuxerConfig.muxRateInMBits;
        bool     vbr=tsMuxerConfig.vbr;

        diaElemToggle   v(&vbr,"VBR muxing");
        diaElemUInteger mux(&muxRate,"Mux rate (MBits/s)",3,60);

        v.link(0,&mux);

        diaElem *tabs[]={&v,&mux};
        if( diaFactoryRun(("TS Muxer"),2,tabs))
        {            
            tsMuxerConfig.muxRateInMBits=muxRate;
            tsMuxerConfig.vbr=vbr;
            return true;
        }
        return false;
}
Esempio n. 12
0
/**
 * Mux a h264 file to mp4, remove h264 and create a thumbnail
 * 
 * @param input the full path of the h264 file
 * @param outputCTime the ctime of the input file
 */
void muxAndCreateThumbnail(char* input, int ctime) {
    char videoOutput[256];
    snprintf(videoOutput, 256, "%s/%d.mp4", config.VideoSaveDirectory, ctime);

    syslog(LOG_INFO, "Muxing: %s -> %s.", input, videoOutput);
    
    //Muxing h264 to mp4
    {
        pid_t muxPid = mux(config.ffmpegPath, config.RaspividFramerate, input, videoOutput);
        if (muxPid < 0) {
            syslog(LOG_ERR, "Failed to create muxer thread.");
        } else {
            waitpid(muxPid, NULL, 0);   //Waiting
            syslog(LOG_INFO, "Video %s saved.", videoOutput);
        }
    }

    //Removing h264
    {
        int status = remove(input);
        if (status == 0) {
            syslog(LOG_INFO, "Temporary raw file %s removed.", input);
        } else {
            syslog(LOG_ERR, "Failed to remove %s: %d.", input, status);
        }
    }

    //Making a thumbnail for this video
    {
        pid_t thumbnailPid = makeThumbnail(config.ffmpegPath, config.ThumbnailWidth, config.ThumbnailFormat, videoOutput, config.ThumbnailSaveDirectory);
        if (thumbnailPid < 0) {
            syslog(LOG_ERR, "Failed to create thumbnail thread.");
        } else {
            waitpid(thumbnailPid, NULL, 0);  //Waiting
            syslog(LOG_INFO, "Thumbnail saved.");
        }
    }
}
Esempio n. 13
0
int
mux_main(mux_ctx_t ctx, int argc, char *argv[])
{
	static struct mux_ctx_s __ctx[1U];
	static struct sumux_opt_s __opts[1U];
	yuck_t argi[1U];
	int rc = 0;

	if (yuck_parse(argi, argc, argv)) {
		rc = 1;
		goto out;
	} else if (UNLIKELY(ctx == NULL)) {
		ctx = __ctx;
		ctx->opts = __opts;
	}

	if (argi->human_readable_flag) {
		/* wipe off the stuff ute-mux prepared for us */
		const char *fn;

		if (ctx->wrr != NULL &&
		    ctx->opts->outfile == NULL &&
		    (fn = ute_fn(ctx->wrr)) != NULL) {
			unlink(fn);
			ute_close(ctx->wrr);
			ctx->wrr = NULL;
		}
	}
	if (argi->all_flag) {
		ctx->opts->flags |= SUMUX_FLAG_ALL_TICKS;
	}

	for (size_t j = 0U; j < argi->nargs; j++) {
		const char *f = argi->args[j];
		int fd;

		/* open the infile ... */
		if (f[0] == '-' && f[1] == '\0') {
			ctx->infd = fd = STDIN_FILENO;
			ctx->infn = NULL;
			ctx->badfd = STDERR_FILENO;
		} else if ((fd = open(f, 0)) < 0) {
			ctx->infd = -1;
			error("cannot open file '%s'", f);
			/* just try the next bloke */
			continue;
		} else if (argi->guess_flag && guess(ctx, f) < 0) {
			error("cannot guess info from '%s'", f);
			/* well try to do the actual muxing anyway */
			;
		} else {
			/* huuuuge success */
			ctx->infd = fd;
			ctx->infn = f;
			ctx->badfd = STDERR_FILENO;
		}
		/* ... and now mux it */
		if (argi->human_readable_flag) {
			dump_l1bi5(ctx);
		} else {
			mux(ctx);
		}
		/* close the infile */
		close(fd);
	}

out:
	yuck_free(argi);
	return rc;
}
Esempio n. 14
0
//////////////////////////////////////////
// FETCH
//  //INPUTS
//  clk: input clk
//  adder2out:used for branch, to mux1
//  pcSrc:used to determine output of mux1
//  
//  //OUTPUTS
//  adder1: incremented program counter
//  instruction: current instruction to decode
//////////////////////////////////////////
void writeBack(int clk, int *regWrite, int *memtoReg, char rdData3_2[16], char aluResultOut3[16], char mux3Out4[16]) {

    mux4Out = mux(aluResultOut3, rdData3_2, &memtoReg);  
}
Esempio n. 15
0
bool G1RemSet::concurrentRefineOneCard_impl(jbyte* card_ptr, int worker_i,
                                                   bool check_for_refs_into_cset) {
  // Construct the region representing the card.
  HeapWord* start = _ct_bs->addr_for(card_ptr);
  // And find the region containing it.
  HeapRegion* r = _g1->heap_region_containing(start);
  assert(r != NULL, "unexpected null");

  HeapWord* end   = _ct_bs->addr_for(card_ptr + 1);
  MemRegion dirtyRegion(start, end);

#if CARD_REPEAT_HISTO
  init_ct_freq_table(_g1->max_capacity());
  ct_freq_note_card(_ct_bs->index_for(start));
#endif

  assert(!check_for_refs_into_cset || _cset_rs_update_cl[worker_i] != NULL, "sanity");
  UpdateRSOrPushRefOopClosure update_rs_oop_cl(_g1,
                                               _g1->g1_rem_set(),
                                               _cset_rs_update_cl[worker_i],
                                               check_for_refs_into_cset,
                                               worker_i);
  update_rs_oop_cl.set_from(r);

  TriggerClosure trigger_cl;
  FilterIntoCSClosure into_cs_cl(NULL, _g1, &trigger_cl);
  InvokeIfNotTriggeredClosure invoke_cl(&trigger_cl, &into_cs_cl);
  Mux2Closure mux(&invoke_cl, &update_rs_oop_cl);

  FilterOutOfRegionClosure filter_then_update_rs_oop_cl(r,
                        (check_for_refs_into_cset ?
                                (OopClosure*)&mux :
                                (OopClosure*)&update_rs_oop_cl));

  // Undirty the card.
  *card_ptr = CardTableModRefBS::clean_card_val();
  // We must complete this write before we do any of the reads below.
  OrderAccess::storeload();
  // And process it, being careful of unallocated portions of TLAB's.

  // The region for the current card may be a young region. The
  // current card may have been a card that was evicted from the
  // card cache. When the card was inserted into the cache, we had
  // determined that its region was non-young. While in the cache,
  // the region may have been freed during a cleanup pause, reallocated
  // and tagged as young.
  //
  // We wish to filter out cards for such a region but the current
  // thread, if we're running conucrrently, may "see" the young type
  // change at any time (so an earlier "is_young" check may pass or
  // fail arbitrarily). We tell the iteration code to perform this
  // filtering when it has been determined that there has been an actual
  // allocation in this region and making it safe to check the young type.
  bool filter_young = true;

  HeapWord* stop_point =
    r->oops_on_card_seq_iterate_careful(dirtyRegion,
                                        &filter_then_update_rs_oop_cl,
                                        filter_young);

  // If stop_point is non-null, then we encountered an unallocated region
  // (perhaps the unfilled portion of a TLAB.)  For now, we'll dirty the
  // card and re-enqueue: if we put off the card until a GC pause, then the
  // unallocated portion will be filled in.  Alternatively, we might try
  // the full complexity of the technique used in "regular" precleaning.
  if (stop_point != NULL) {
    // The card might have gotten re-dirtied and re-enqueued while we
    // worked.  (In fact, it's pretty likely.)
    if (*card_ptr != CardTableModRefBS::dirty_card_val()) {
      *card_ptr = CardTableModRefBS::dirty_card_val();
      MutexLockerEx x(Shared_DirtyCardQ_lock,
                      Mutex::_no_safepoint_check_flag);
      DirtyCardQueue* sdcq =
        JavaThread::dirty_card_queue_set().shared_dirty_card_queue();
      sdcq->enqueue(card_ptr);
    }
  } else {
    out_of_histo.add_entry(filter_then_update_rs_oop_cl.out_of_region());
    _conc_refine_cards++;
  }

  return trigger_cl.value();
}
Esempio n. 16
0
File: PC.c Progetto: blaunay/preesm
    DWORD WINAPI computationThread_PC( LPVOID lpParam ){
        // Buffer declarations
        long i ;

        {
            init_ProdMatVect_0_prodScalVect_init_accIn(vectorOut_accIn);
        }

        for(;;){
            vectorOut_accIn_2 = &vectorOut_accIn[0];
            generateMatrix(outMat_in, 9/*size*/);
            generateVect(outVect_in, 3/*size*/);
            {//ProdMatVect_0_explode_vectorIn
                out_ScalIn = &outVect_in[0];
                out_ScalIn_1 = &outVect_in[3];
                out_ScalIn_0 = &outVect_in[2];
            }
            {//ProdMatVect_0_explode_matrixIn
                out_vector1In = &outMat_in[0];
                out_vector1In_0 = &outMat_in[9];
                out_vector1In_1 = &outMat_in[6];
            }
            {//ProdMatVect_0_prodScalVect
                init_inLoopPort_0(outLoopPort_0_inLo_0, 1/*init_size*/);
                for(i = 0; i<3 ; i ++)
                {//cluster_0
                    char *inSub_i_cluster_0__0 = &cluster_0_in_in [((i*(1))%3)];
                    int *outSub_i_out_vecto_0 = &out_vector1In [((i*(1))%0)];
                    char *outSub_i_vectorOut_0 = &vectorOut_accIn [((i*(1))%3)];
                    int *outSub_i_out_ScalIn = &out_ScalIn [((i*(1))%0)];
                    mux();
                    {//productScal
                        {//brScal
                            memcpy(outLoopPort_0_inLo_0, out_scal2, 1*sizeof(char)/*size*/);
                        }
                        mult(outSub_i_out_vecto_0, res_op1);
                        add(res_op1, outSub_i_vectorOut_0, inSub_i_cluster_0__0);
                    }
                }
                for(i = 0; i<3 ; i ++)
                {//brScal
                    char *inSub_i_vectorOut__0 = &vectorOut_accIn_0 [((i*(1))%3)];
                    char *inSub_i_vectorFina_0 = &vectorFinal_in [((i*(1))%3)];
                    char *outSub_i_cluster_0_0 = &cluster_0_in_in [((i*(1))%3)];
                    brScal();
                }
            }
            {//ProdMatVect_0_prodScalVect_1
                init_inLoopPort_0(outLoopPort_0_inLo_0, 1/*init_size*/);
                for(i = 0; i<3 ; i ++)
                {//cluster_0
                    char *inSub_i_cluster_0__0 = &cluster_0_in_in [((i*(1))%3)];
                    int *outSub_i_out_vecto_0 = &out_vector1In_0 [((i*(1))%0)];
                    char *outSub_i_vectorOut_0 = &vectorOut_accIn_0 [((i*(1))%3)];
                    int *outSub_i_out_ScalI_0 = &out_ScalIn_1 [((i*(1))%0)];
                    mux();
                    {//productScal
                        {//brScal
                            memcpy(outLoopPort_0_inLo_0, out_scal2, 1*sizeof(char)/*size*/);
                        }
                        mult(outSub_i_out_vecto_0, res_op1);
                        add(res_op1, outSub_i_vectorOut_0, inSub_i_cluster_0__0);
                    }
                }
                for(i = 0; i<3 ; i ++)
                {//brScal
                    char *inSub_i_vectorOut__0 = &vectorOut_accIn_1 [((i*(1))%3)];
                    char *inSub_i_vectorFina_0 = &vectorFinal_in_0 [((i*(1))%9)];
                    char *outSub_i_cluster_0_0 = &cluster_0_in_in [((i*(1))%3)];
                    brScal();
                }
            }
            {//ProdMatVect_0_prodScalVect_2
                init_inLoopPort_0(outLoopPort_0_inLo_0, 1/*init_size*/);
                for(i = 0; i<3 ; i ++)
                {//cluster_0
                    char *inSub_i_cluster_0__0 = &cluster_0_in_in [((i*(1))%3)];
                    int *outSub_i_out_vecto_0 = &out_vector1In_1 [((i*(1))%0)];
                    char *outSub_i_vectorOut_0 = &vectorOut_accIn_1 [((i*(1))%3)];
                    int *outSub_i_out_ScalI_0 = &out_ScalIn_0 [((i*(1))%0)];
                    mux();
                    {//productScal
                        {//brScal
                            memcpy(outLoopPort_0_inLo_0, out_scal2, 1*sizeof(char)/*size*/);
                        }
                        mult(outSub_i_out_vecto_0, res_op1);
                        add(res_op1, outSub_i_vectorOut_0, inSub_i_cluster_0__0);
                    }
                }
                for(i = 0; i<3 ; i ++)
                {//brScal
                    char *inSub_i_vectorOut__0 = &vectorOut_accIn_2 [((i*(1))%0)];
                    char *inSub_i_vectorFina_0 = &vectorFinal_in_1 [((i*(1))%3)];
                    char *outSub_i_cluster_0_0 = &cluster_0_in_in [((i*(1))%3)];
                    brScal();
                }
            }
            {//ProdMatVect_0_roundBuffer_vectorOut
                memcpy(out_inResult, vectorFinal_in_1, 3*sizeof(char)/*size*/);
            }
            display(out_inResult, 3/*size*/);
        }

        return 0;
    }//computationThread
Esempio n. 17
0
/* Play a list of audio files. */
int
main(int argc, char **argv) {
	int		errorStatus = 0;
	int		i;
	int		c;
	int		cnt;
	int		file_type;
	int		rem;
	int		outsiz;
	int		tsize;
	int		len;
	int		err;
	int		ifd;
	int		stdinseen;
	int		regular;
	int		swapBytes;
	int		frame;
	char		*outbuf;
	caddr_t		mapaddr;
	struct stat	st;
	char		*cp;
	char		ctldev[MAXPATHLEN];

	(void) setlocale(LC_ALL, "");
	(void) textdomain(TEXT_DOMAIN);

	/* Get the program name */
	prog = strrchr(argv[0], '/');
	if (prog == NULL)
		prog = argv[0];
	else
		prog++;
	Stdin = MGET("(stdin)");

	/* Check AUDIODEV environment for audio device name */
	if (cp = getenv("AUDIODEV")) {
		Audio_dev = cp;
	}

	/* Parse the command line arguments */
	err = 0;
	while ((i = getopt(argc, argv, prog_opts)) != EOF) {
		switch (i) {
			case 'v':
				if (parse_unsigned(optarg, &Volume, "-v")) {
					err++;
				} else if (Volume > MAX_GAIN) {
					Error(stderr, MGET("%s: invalid value "
					    "for -v\n"), prog);
					err++;
				}
				break;
			case 'd':
				Audio_dev = optarg;
				break;
			case 'V':
				Verbose = TRUE;
				break;
			case 'E':
				Errdetect = TRUE;
				break;
			case 'i':
				Immediate = TRUE;
				break;
			case '?':
				usage();
		/*NOTREACHED*/
		}
	}
	if (err > 0)
		exit(1);

	argc -= optind;		/* update arg pointers */
	argv += optind;

	/* Validate and open the audio device */
	err = stat(Audio_dev, &st);
	if (err < 0) {
		Error(stderr, MGET("%s: cannot stat "), prog);
		perror(Audio_dev);
		exit(1);
	}
	if (!S_ISCHR(st.st_mode)) {
		Error(stderr, MGET("%s: %s is not an audio device\n"), prog,
		    Audio_dev);
		exit(1);
	}

	/* This should probably use audio_cntl instead of open_audio */
	if ((argc <= 0) && isatty(fileno(stdin))) {
		Error(stderr, MGET("%s: No files and stdin is a tty.\n"), prog);
		exit(1);
	}

	/* Check on the -i status now. */
	Audio_fd = open(Audio_dev, O_WRONLY | O_NONBLOCK);
	if ((Audio_fd < 0) && (errno == EBUSY)) {
		if (Immediate) {
			Error(stderr, MGET("%s: %s is busy\n"), prog,
			    Audio_dev);
			exit(1);
		}
	}
	(void) close(Audio_fd);
	Audio_fd = -1;

	/* Try to open the control device and save the current format */
	(void) snprintf(ctldev, sizeof (ctldev), "%sctl", Audio_dev);
	Audio_ctlfd = open(ctldev, O_RDWR);
	if (Audio_ctlfd >= 0) {
		/*
		 * wait for the device to become available then get the
		 * controls. We want to save the format that is left when the
		 * device is in a quiescent state. So wait until then.
		 */
		Audio_fd = open(Audio_dev, O_WRONLY);
		(void) close(Audio_fd);
		Audio_fd = -1;
		if (audio_get_play_config(Audio_ctlfd, &Save_hdr)
		    != AUDIO_SUCCESS) {
			(void) close(Audio_ctlfd);
			Audio_ctlfd = -1;
		}
	}

	/* store AUDIOPATH so we don't keep doing getenv() */
	Audio_path = getenv("AUDIOPATH");

	/* Set up SIGINT handler to flush output */
	(void) signal(SIGINT, sigint);

	/* Set the endian nature of the machine. */
	if ((ulong_t)1 != htonl((ulong_t)1)) {
		NetEndian = FALSE;
	}

	/* If no filenames, read stdin */
	stdinseen = FALSE;
	if (argc <= 0) {
		Ifile = Stdin;
	} else {
		Ifile = *argv++;
		argc--;
	}

	/* Loop through all filenames */
	do {
		/* Interpret "-" filename to mean stdin */
		if (strcmp(Ifile, "-") == 0)
			Ifile = Stdin;

		if (Ifile == Stdin) {
			if (stdinseen) {
				Error(stderr,
				    MGET("%s: stdin already processed\n"),
				    prog);
				goto nextfile;
			}
			stdinseen = TRUE;
			ifd = fileno(stdin);
		} else {
			if ((ifd = path_open(Ifile, O_RDONLY, 0, Audio_path))
			    < 0) {
				Error(stderr, MGET("%s: cannot open "), prog);
				perror(Ifile);
				errorStatus++;
				goto nextfile;
			}
		}

		/* Check to make sure this is an audio file */
		err = audio_read_filehdr(ifd, &File_hdr, &file_type,
		    (char *)NULL, 0);
		if (err != AUDIO_SUCCESS) {
			Error(stderr,
			    MGET("%s: %s is not a valid audio file\n"),
			    prog, Ifile);
			errorStatus++;
			goto closeinput;
		}

		/* If G.72X adpcm, set flags for conversion */
		if ((File_hdr.encoding == AUDIO_ENCODING_G721) &&
		    (File_hdr.samples_per_unit == 2) &&
		    (File_hdr.bytes_per_unit == 1)) {
			Decode = AUDIO_ENCODING_G721;
			File_hdr.encoding = AUDIO_ENCODING_ULAW;
			File_hdr.samples_per_unit = 1;
			File_hdr.bytes_per_unit = 1;
			adpcm_state = (struct audio_g72x_state *)malloc
			    (sizeof (*adpcm_state) * File_hdr.channels);
			for (i = 0; i < File_hdr.channels; i++) {
				g721_init_state(&adpcm_state[i]);
			}
		} else if ((File_hdr.encoding == AUDIO_ENCODING_G723) &&
		    (File_hdr.samples_per_unit == 8) &&
		    (File_hdr.bytes_per_unit == 3)) {
			Decode = AUDIO_ENCODING_G723;
			File_hdr.encoding = AUDIO_ENCODING_ULAW;
			File_hdr.samples_per_unit = 1;
			File_hdr.bytes_per_unit = 1;
			adpcm_state = (struct audio_g72x_state *)malloc
			    (sizeof (*adpcm_state) * File_hdr.channels);
			for (i = 0; i < File_hdr.channels; i++) {
				g723_init_state(&adpcm_state[i]);
			}
		} else {
			Decode = AUDIO_ENCODING_NONE;
		}

		/* Check the device configuration */
		open_audio();
		if (audio_cmp_hdr(&Dev_hdr, &File_hdr) != 0) {
			/*
			 * The device does not match the input file.
			 * Wait for any old output to drain, then attempt
			 * to reconfigure the audio device to match the
			 * input data.
			 */
			if (audio_drain(Audio_fd, FALSE) != AUDIO_SUCCESS) {
				/* Flush any remaining audio */
				(void) ioctl(Audio_fd, I_FLUSH, FLUSHW);

				Error(stderr, MGET("%s: "), prog);
				perror(MGET("AUDIO_DRAIN error"));
				exit(1);
			}

			/* Flush any remaining audio */
			(void) ioctl(Audio_fd, I_FLUSH, FLUSHW);

			if (!reconfig()) {
				errorStatus++;
				goto closeinput;
			}
		}


		/* try to do the mmaping - for regular files only ... */
		err = fstat(ifd, &st);
		if (err < 0) {
			Error(stderr, MGET("%s: cannot stat "), prog);
			perror(Ifile);
			exit(1);
		}
		regular = (S_ISREG(st.st_mode));


		/* If regular file, map it.  Else, allocate a buffer */
		mapaddr = 0;

		/*
		 * This should compare to MAP_FAILED not -1, can't
		 * find MAP_FAILED
		 */
		if (regular && ((mapaddr = mmap(0, st.st_size, PROT_READ,
		    MAP_SHARED, ifd, 0)) != MAP_FAILED)) {

			(void) madvise(mapaddr, st.st_size, MADV_SEQUENTIAL);

			/* Skip the file header and set the proper size */
			cnt = lseek(ifd, 0, SEEK_CUR);
			if (cnt < 0) {
			    perror("lseek");
			    exit(1);
			}
			inbuf = (unsigned char *) mapaddr + cnt;
			len = cnt = st.st_size - cnt;
		} else {		/* Not a regular file, or map failed */

			/* mark is so. */
			mapaddr = 0;

			/* Allocate buffer to hold 10 seconds of data */
			cnt = BUFFER_LEN * File_hdr.sample_rate *
			    File_hdr.bytes_per_unit * File_hdr.channels;
			if (bufsiz != cnt) {
				if (buf != NULL) {
					(void) free(buf);
				}
				buf = (unsigned char *) malloc(cnt);
				if (buf == NULL) {
					Error(stderr,
					    MGET("%s: couldn't allocate %dK "
					    "buf\n"), prog, bufsiz / 1000);
					exit(1);
				}
				inbuf = buf;
				bufsiz = cnt;
			}
		}

		/* Set buffer sizes and pointers for conversion, if any */
		switch (Decode) {
		default:
		case AUDIO_ENCODING_NONE:
			insiz = bufsiz;
			outbuf = (char *)buf;
			break;
		case AUDIO_ENCODING_G721:
			insiz = ADPCM_SIZE / 2;
			outbuf = (char *)adpcm_buf;
			initmux(1, 2);
			break;
		case AUDIO_ENCODING_G723:
			insiz = (ADPCM_SIZE * 3) / 8;
			outbuf = (char *)adpcm_buf;
			initmux(3, 8);
			break;
		}

		/*
		 * 8-bit audio isn't a problem, however 16-bit audio is.
		 * If the file is an endian that is different from the machine
		 * then the bytes will need to be swapped.
		 *
		 * Note: Because the G.72X conversions produce 8bit output,
		 * they don't require a byte swap before display and so
		 * this scheme works just fine. If a conversion is added
		 * that produces a 16 bit result and therefore requires
		 * byte swapping before output, then a mechanism
		 * for chaining the two conversions will have to be built.
		 *
		 * Note: The following if() could be simplified, but then
		 * it gets to be very hard to read. So it's left as is.
		 */

		if (File_hdr.bytes_per_unit == 2 &&
		    ((!NetEndian && file_type == FILE_AIFF) ||
		    (!NetEndian && file_type == FILE_AU) ||
		    (NetEndian && file_type == FILE_WAV))) {
			swapBytes = TRUE;
		} else {
			swapBytes = FALSE;
		}

		if (swapBytes) {
			/* Read in interal number of sample frames. */
			frame = File_hdr.bytes_per_unit * File_hdr.channels;
			insiz = (SWAP_SIZE / frame) * frame;
			/* make the output buffer  the swap buffer. */
			outbuf = (char *)swap_buf;
		}

		/*
		 * At this point, we're all ready to copy the data.
		 */
		if (mapaddr == 0) { /* Not mmapped, do it a buffer at a time. */
			inbuf = buf;
			frame = File_hdr.bytes_per_unit * File_hdr.channels;
			rem = 0;
			while ((cnt = read(ifd, inbuf+rem, insiz-rem)) >= 0) {
				/*
				 * We need to ensure only an integral number of
				 * samples is ever written to the audio device.
				 */
				cnt = cnt + rem;
				rem = cnt % frame;
				cnt = cnt - rem;

				/*
				 * If decoding adpcm, or swapping bytes do it
				 * now.
				 *
				 * We treat the swapping like a separate
				 * encoding here because the G.72X encodings
				 * decode to single byte output samples. If
				 * another encoding is added and it produces
				 * multi-byte output samples this will have to
				 * be changed.
				 */
				if (Decode == AUDIO_ENCODING_G721) {
				    outsiz = 0;
				    demux(1, cnt / File_hdr.channels);
				    for (c = 0; c < File_hdr.channels; c++) {
					err = g721_decode(in_ch_data[c],
					    cnt / File_hdr.channels,
					    &File_hdr,
					    (void*)out_ch_data[c],
					    &tsize,
					    &adpcm_state[c]);
					outsiz = outsiz + tsize;
					if (err != AUDIO_SUCCESS) {
					    Error(stderr, MGET(
						"%s: error decoding g721\n"),
						prog);
						errorStatus++;
						break;
					}
				    }
				    mux(outbuf);
				    cnt = outsiz;
				} else if (Decode == AUDIO_ENCODING_G723) {
				    outsiz = 0;
				    demux(3, cnt / File_hdr.channels);
				    for (c = 0; c < File_hdr.channels; c++) {
					err = g723_decode(in_ch_data[c],
					    cnt / File_hdr.channels,
					    &File_hdr,
					    (void*)out_ch_data[c],
					    &tsize,
					    &adpcm_state[c]);
					outsiz = outsiz + tsize;
					if (err != AUDIO_SUCCESS) {
					    Error(stderr, MGET(
						"%s: error decoding g723\n"),
						prog);
					    errorStatus++;
					    break;
					}
				    }
				    mux(outbuf);
				    cnt = outsiz;
				} else if (swapBytes) {
					swab((char *)inbuf, outbuf, cnt);
				}

				/* If input EOF, write an eof marker */
				err = write(Audio_fd, outbuf, cnt);

				if (err < 0) {
					perror("write");
					errorStatus++;
					break;
				} else if (err != cnt) {
					Error(stderr,
					    MGET("%s: output error: "), prog);
					perror("");
					errorStatus++;
					break;
				}
				if (cnt == 0) {
					break;
				}
				/* Move remainder to the front of the buffer */
				if (rem != 0) {
					(void *)memcpy(inbuf, inbuf + cnt, rem);
				}

			}
			if (cnt < 0) {
				Error(stderr, MGET("%s: error reading "), prog);
				perror(Ifile);
				errorStatus++;
			}
		} else {	/* We're mmaped */
			if ((Decode != AUDIO_ENCODING_NONE) || swapBytes) {

				/* Transform data if we have to. */
				for (i = 0; i <= len; i += cnt) {
					cnt = insiz;
					if ((i + cnt) > len) {
						cnt = len - i;
					}
					if (Decode == AUDIO_ENCODING_G721) {
					    outsiz = 0;
					    demux(1, cnt / File_hdr.channels);
					    for (c = 0; c < File_hdr.channels;
						c++) {
						err = g721_decode(
						    in_ch_data[c],
						    cnt / File_hdr.channels,
						    &File_hdr,
						    (void*)out_ch_data[c],
						    &tsize,
						    &adpcm_state[c]);
						outsiz = outsiz + tsize;
						if (err != AUDIO_SUCCESS) {
						    Error(stderr, MGET(
							"%s: error decoding "
							"g721\n"), prog);
						    errorStatus++;
						    break;
						}
					    }
					    mux(outbuf);
					} else if
					    (Decode == AUDIO_ENCODING_G723) {
						outsiz = 0;
						demux(3,
						    cnt / File_hdr.channels);
						for (c = 0;
							c < File_hdr.channels;
							c++) {
						    err = g723_decode(
							in_ch_data[c],
							cnt /
							    File_hdr.channels,
							&File_hdr,
							(void*)out_ch_data[c],
							&tsize,
							&adpcm_state[c]);
						    outsiz = outsiz + tsize;
						    if (err != AUDIO_SUCCESS) {
							Error(stderr, MGET(
							    "%s: error "
							    "decoding g723\n"),
							    prog);
							errorStatus++;
							break;
						    }
						}
						mux(outbuf);
					} else if (swapBytes) {
						swab((char *)inbuf, outbuf,
						    cnt);
						outsiz = cnt;
					}
					inbuf += cnt;

					/* If input EOF, write an eof marker */
					err = write(Audio_fd, (char *)outbuf,
					    outsiz);
					if (err < 0) {
						perror("write");
						errorStatus++;
					} else if (outsiz == 0) {
						break;
					}

				}
			} else {
				/* write the whole thing at once!  */
				err = write(Audio_fd, inbuf, len);
				if (err < 0) {
					perror("write");
					errorStatus++;
				}
				if (err != len) {
					Error(stderr,
					    MGET("%s: output error: "), prog);
					perror("");
					errorStatus++;
				}
				err = write(Audio_fd, inbuf, 0);
				if (err < 0) {
					perror("write");
					errorStatus++;
				}
			}
		}

		/* Free memory if decoding ADPCM */
		switch (Decode) {
		case AUDIO_ENCODING_G721:
		case AUDIO_ENCODING_G723:
			freemux();
			break;
		default:
			break;
		}

closeinput:;
		if (mapaddr != 0)
			(void) munmap(mapaddr, st.st_size);
		(void) close(ifd);		/* close input file */
		if (Errdetect) {
			cnt = 0;
			audio_set_play_error(Audio_fd, (unsigned int *)&cnt);
			if (cnt) {
				Error(stderr,
				    MGET("%s: output underflow in %s\n"),
				    Ifile, prog);
				errorStatus++;
			}
		}
nextfile:;
	} while ((argc > 0) && (argc--, (Ifile = *argv++) != NULL));

	/*
	 * Though drain is implicit on close(), it's performed here
	 * to ensure that the volume is reset after all output is complete.
	 */
	(void) audio_drain(Audio_fd, FALSE);

	/* Flush any remaining audio */
	(void) ioctl(Audio_fd, I_FLUSH, FLUSHW);

	if (Volume != INT_MAX)
		(void) audio_set_play_gain(Audio_fd, &Savevol);
	if ((Audio_ctlfd >= 0) && (audio_cmp_hdr(&Save_hdr, &Dev_hdr) != 0)) {
		(void) audio_set_play_config(Audio_fd, &Save_hdr);
	}
	(void) close(Audio_fd);			/* close output */
	return (errorStatus);
}
Esempio n. 18
0
File: mlpx.c Progetto: bytemine/ut
/*
 *	demux()
 *
 *	analyse prefix and forward accordingly
 *	(to channel output queues or cmd input queue)
 */
void demux (msg_t *m, const chn_t *ch /* unused */)
{
int id;
(void)ch;/* avoid warnings */

#ifdef DEBUG
    if (PRFXLEN != 5) {
	/* huh! prefix length does not match the following part */
        tesc_emerg (CHN_MSG, MF_ERR, "demux(): internal error\n");
        tesc_emerg (CHN_MSG, MF_EOF, "\n");
	exit (1);
    }
    if (m->flags & MF_PLAIN) {
        tesc_emerg (CHN_MSG, MF_ERR, "demux(): plain message\n");
        tesc_emerg (CHN_MSG, MF_EOF, "\n");
	exit (1);
    }
#endif
    if (m->len < 6) {
	/* illegal input, expected at least prefix + '\n', i.e. len == 6 */
        mlpx_printf (CHN_MSG, MF_ERR,
		"demux(): illegal input (too short to have valid prefix)\n");
	free (m);
	return;
    }

    /* check prefix */
    if (m->prefix[0] != '<' || m->prefix[3] != '<' || m->prefix[4] != ' ') {
	/* illegal prefix, wrong framing chars for id */
        mlpx_printf (CHN_MSG, MF_ERR,
		"demux(): illegal prefix (wrong framing chars)\n");
	free (m);
	return;
    }

    /* check id part */
    if (! (ishexdigit (m->prefix[1]) && ishexdigit (m->prefix[2]))) { 
	/* illegal char for prefix */
        mlpx_printf (CHN_MSG, MF_ERR,
		"demux(): illegal prefix (garbled channel id)\n");
	free (m);
	return;
    }

    /* convert id */
    id = hexd2int (m->prefix[1]) * 16 + hexd2int (m->prefix[2]);

    /* check if channel is valid and open for writing */
    if (! chmap[id]) {
	/* channel does not exist */
        mlpx_printf (CHN_MSG, MF_ERR,
		"demux(): channel %02X does not exist\n", id);
	free (m);
	return;
    }
    if (chmap[id]->flags & CHN_F_IP) {
	/* open/connect still in progress */
	mlpx_printf (CHN_MSG, MF_ERR,
		"demux(): channel %02X not yet ready\n", id);
	free (m);
	return;
    }
    if (! (chmap[id]->flags & CHN_F_WR)) {
	/* channel is not writeable */
        mlpx_printf (CHN_MSG, MF_ERR,
		"demux(): channel %02X not open for writing\n", id);
	free (m);
	return;
    }

    /* ignore prefix from now on */
    m->flags |= MF_PLAIN;
    m->len -= PRFXLEN;

    /* forward to output or cmd */
    if (id == CHN_CMD) {
	cmdi_enque (m);
    } else if (id == CHN_MSG) {
	/* simply echo back */
	mux (m, chmap[CHN_MSG]);
    } else
        tesc_enq_wq (chmap[id], m);

    return;
}
Esempio n. 19
0
bool G1RemSet::refine_card(jbyte* card_ptr, uint worker_i,
                           bool check_for_refs_into_cset) {
  assert(_g1->is_in_exact(_ct_bs->addr_for(card_ptr)),
         err_msg("Card at "PTR_FORMAT" index "SIZE_FORMAT" representing heap at "PTR_FORMAT" (%u) must be in committed heap",
                 p2i(card_ptr),
                 _ct_bs->index_for(_ct_bs->addr_for(card_ptr)),
                 _ct_bs->addr_for(card_ptr),
                 _g1->addr_to_region(_ct_bs->addr_for(card_ptr))));

  // If the card is no longer dirty, nothing to do.
  if (*card_ptr != CardTableModRefBS::dirty_card_val()) {
    // No need to return that this card contains refs that point
    // into the collection set.
    return false;
  }

  // Construct the region representing the card.
  HeapWord* start = _ct_bs->addr_for(card_ptr);
  // And find the region containing it.
  HeapRegion* r = _g1->heap_region_containing(start);

  // Why do we have to check here whether a card is on a young region,
  // given that we dirty young regions and, as a result, the
  // post-barrier is supposed to filter them out and never to enqueue
  // them? When we allocate a new region as the "allocation region" we
  // actually dirty its cards after we release the lock, since card
  // dirtying while holding the lock was a performance bottleneck. So,
  // as a result, it is possible for other threads to actually
  // allocate objects in the region (after the acquire the lock)
  // before all the cards on the region are dirtied. This is unlikely,
  // and it doesn't happen often, but it can happen. So, the extra
  // check below filters out those cards.
  if (r->is_young()) {
    return false;
  }

  // While we are processing RSet buffers during the collection, we
  // actually don't want to scan any cards on the collection set,
  // since we don't want to update remembered sets with entries that
  // point into the collection set, given that live objects from the
  // collection set are about to move and such entries will be stale
  // very soon. This change also deals with a reliability issue which
  // involves scanning a card in the collection set and coming across
  // an array that was being chunked and looking malformed. Note,
  // however, that if evacuation fails, we have to scan any objects
  // that were not moved and create any missing entries.
  if (r->in_collection_set()) {
    return false;
  }

  // The result from the hot card cache insert call is either:
  //   * pointer to the current card
  //     (implying that the current card is not 'hot'),
  //   * null
  //     (meaning we had inserted the card ptr into the "hot" card cache,
  //     which had some headroom),
  //   * a pointer to a "hot" card that was evicted from the "hot" cache.
  //

  G1HotCardCache* hot_card_cache = _cg1r->hot_card_cache();
  if (hot_card_cache->use_cache()) {
    assert(!check_for_refs_into_cset, "sanity");
    assert(!SafepointSynchronize::is_at_safepoint(), "sanity");

    card_ptr = hot_card_cache->insert(card_ptr);
    if (card_ptr == NULL) {
      // There was no eviction. Nothing to do.
      return false;
    }

    start = _ct_bs->addr_for(card_ptr);
    r = _g1->heap_region_containing(start);

    // Checking whether the region we got back from the cache
    // is young here is inappropriate. The region could have been
    // freed, reallocated and tagged as young while in the cache.
    // Hence we could see its young type change at any time.
  }

  // Don't use addr_for(card_ptr + 1) which can ask for
  // a card beyond the heap.  This is not safe without a perm
  // gen at the upper end of the heap.
  HeapWord* end   = start + CardTableModRefBS::card_size_in_words;
  MemRegion dirtyRegion(start, end);

#if CARD_REPEAT_HISTO
  init_ct_freq_table(_g1->max_capacity());
  ct_freq_note_card(_ct_bs->index_for(start));
#endif

  G1ParPushHeapRSClosure* oops_in_heap_closure = NULL;
  if (check_for_refs_into_cset) {
    // ConcurrentG1RefineThreads have worker numbers larger than what
    // _cset_rs_update_cl[] is set up to handle. But those threads should
    // only be active outside of a collection which means that when they
    // reach here they should have check_for_refs_into_cset == false.
    assert((size_t)worker_i < n_workers(), "index of worker larger than _cset_rs_update_cl[].length");
    oops_in_heap_closure = _cset_rs_update_cl[worker_i];
  }
  G1UpdateRSOrPushRefOopClosure update_rs_oop_cl(_g1,
                                                 _g1->g1_rem_set(),
                                                 oops_in_heap_closure,
                                                 check_for_refs_into_cset,
                                                 worker_i);
  update_rs_oop_cl.set_from(r);

  G1TriggerClosure trigger_cl;
  FilterIntoCSClosure into_cs_cl(NULL, _g1, &trigger_cl);
  G1InvokeIfNotTriggeredClosure invoke_cl(&trigger_cl, &into_cs_cl);
  G1Mux2Closure mux(&invoke_cl, &update_rs_oop_cl);

  FilterOutOfRegionClosure filter_then_update_rs_oop_cl(r,
                        (check_for_refs_into_cset ?
                                (OopClosure*)&mux :
                                (OopClosure*)&update_rs_oop_cl));

  // The region for the current card may be a young region. The
  // current card may have been a card that was evicted from the
  // card cache. When the card was inserted into the cache, we had
  // determined that its region was non-young. While in the cache,
  // the region may have been freed during a cleanup pause, reallocated
  // and tagged as young.
  //
  // We wish to filter out cards for such a region but the current
  // thread, if we're running concurrently, may "see" the young type
  // change at any time (so an earlier "is_young" check may pass or
  // fail arbitrarily). We tell the iteration code to perform this
  // filtering when it has been determined that there has been an actual
  // allocation in this region and making it safe to check the young type.
  bool filter_young = true;

  HeapWord* stop_point =
    r->oops_on_card_seq_iterate_careful(dirtyRegion,
                                        &filter_then_update_rs_oop_cl,
                                        filter_young,
                                        card_ptr);

  // If stop_point is non-null, then we encountered an unallocated region
  // (perhaps the unfilled portion of a TLAB.)  For now, we'll dirty the
  // card and re-enqueue: if we put off the card until a GC pause, then the
  // unallocated portion will be filled in.  Alternatively, we might try
  // the full complexity of the technique used in "regular" precleaning.
  if (stop_point != NULL) {
    // The card might have gotten re-dirtied and re-enqueued while we
    // worked.  (In fact, it's pretty likely.)
    if (*card_ptr != CardTableModRefBS::dirty_card_val()) {
      *card_ptr = CardTableModRefBS::dirty_card_val();
      MutexLockerEx x(Shared_DirtyCardQ_lock,
                      Mutex::_no_safepoint_check_flag);
      DirtyCardQueue* sdcq =
        JavaThread::dirty_card_queue_set().shared_dirty_card_queue();
      sdcq->enqueue(card_ptr);
    }
  } else {
    _conc_refine_cards++;
  }

  // This gets set to true if the card being refined has
  // references that point into the collection set.
  bool has_refs_into_cset = trigger_cl.triggered();

  // We should only be detecting that the card contains references
  // that point into the collection set if the current thread is
  // a GC worker thread.
  assert(!has_refs_into_cset || SafepointSynchronize::is_at_safepoint(),
           "invalid result at non safepoint");

  return has_refs_into_cset;
}