Ejemplo n.º 1
0
	void bin_index_t::file_node::remove_oldest()
	{
		for(page_wptr wp=last_page;pages.size()>=max_pages&&!wp.expired();)
		{
			page_ptr r;
			page_ptr l;

			{
				page_ptr p=wp.lock();
				r=p->right.lock();
				l=p->left.lock();
				flush_page(*p);
				pages.erase(p->page_offset);
				remove_from_list(p);
			}

			//Somebody still use this page and we can't delete it
			if(!wp.expired())
			{
				page_ptr p=wp.lock();
				pages[p->page_offset]=p;
				insert_into_list(p,r);
			}

			wp=l;
		}
	}
Ejemplo n.º 2
0
	void bin_index_t::file_node::flush()
	{
		pages_t::iterator from=pages.begin();
		pages_t::iterator to=pages.end();
		for(;from!=to;++from)
			flush_page(*from->second);
	}
Ejemplo n.º 3
0
/* Free bandlist memory waits until the rasterizer runs enough to free some mem */
static int			/* -ve err,  0 if no pages remain to rasterize, 1 if more pages to go */
gdev_prn_async_write_free_up_bandlist_memory(gx_device * pdev, bool flush_current)
{
    gx_device_printer *const pwdev = (gx_device_printer *) pdev;

    if (flush_current) {
        int code = flush_page(pwdev, true);

        if (code < 0)
            return code;
    }
    return gx_page_queue_wait_one_page(pwdev->page_queue);
}
Ejemplo n.º 4
0
int check_and_flush(int *lastSize, int *curSize,  unsigned char* lastBuf, 
					unsigned char* curBuf)
{
	int ret = 0;
	unsigned char outBuf[PAGE_SIZE];
	memset(outBuf, 0, PAGE_SIZE);// clean up
	//Four cases.
	if((*curSize) > PAGE_SIZE){
		flush_page(lastBuf, *lastSize, 0);
		flush_page(curBuf, *curSize, 0);
		memset(lastBuf,0, OUT_BUF_SIZE); 
		*lastSize=0;
		memset(curBuf,0, OUT_BUF_SIZE); 
		*curSize=0;
	}else if((*curSize) + (*lastSize) >PAGE_SIZE){
		flush_page(lastBuf, *lastSize, 0);
		memcpy(lastBuf, curBuf, OUT_BUF_SIZE);
		(*lastSize)=(*curSize);
		memset(curBuf, 0, OUT_BUF_SIZE);
		*curSize = 0;
	}else if((*lastSize) == 0){
		memcpy(lastBuf, curBuf, OUT_BUF_SIZE);
		*lastSize = *curSize;
		memset(curBuf, 0, OUT_BUF_SIZE);
		*curSize = 0;
	}else{
		//combine two pages. copy cur to last, will flush next time.
		memcpy(outBuf, lastBuf, *lastSize);
		memcpy(outBuf + *lastSize, curBuf, *curSize);
		flush_page(outBuf, *lastSize+*curSize, 1);
		memset(outBuf, 0, PAGE_SIZE);
		memset(lastBuf, 0, OUT_BUF_SIZE);
		*lastSize=0;
		memset(curBuf, 0, OUT_BUF_SIZE);
		*curSize=0;
	}
	return ret;
}
Ejemplo n.º 5
0
void FileSystemApi::balance_cache(DBC &conf) {
    if (ccache_size <= conf.cache_size) {
        return;
    }
    
    while (ccache_size > conf.cache_size) {
        //std::cerr << lru.back().get_page_num() << std::endl;
        ccache_size -= lru.back().num_bytes();
        cached.erase(lru.back().get_page_num());
        flush_page(conf, lru.back());
        lru.pop_back();
    }
    return;
}
Ejemplo n.º 6
0
void FileSystemApi::sync(DBC &conf) {
    for (std::list<Page>::iterator it = lru.begin(); it != lru.end(); ++it) {
        flush_page(conf, *it);
    }
    return;
}
Ejemplo n.º 7
0
/* Put parameters. */
static int
gdev_prn_async_write_put_params(gx_device * pdev, gs_param_list * plist)
{
    gx_device_clist_writer *const pclwdev =
        &((gx_device_clist *) pdev)->writer;
    gx_device_printer *const pwdev = (gx_device_printer *) pdev;
    gdev_prn_space_params save_sp = pwdev->space_params;
    int save_height = pwdev->height;
    int save_width = pwdev->width;
    int code, ecode;

    if (!pwdev->is_open)
        return (*pwdev->orig_procs.put_params) (pdev, plist);

    /*
     * First, cascade to real device's put_params.
     * If that put_params made any changes that require re-opening
     * the device, just flush the page; the parameter block at the
     * head of the next page will reflect the changes just made.
     * If the put_params requires no re-open, just slip it into the
     * stream in the command buffer. This way, the
     * writer device should parallel the renderer status at the same point
     * in their respective executions.
     *
     * NB. that all this works only because we take the position that
     * put_params can make no change that actually affects hardware's state
     * before the final output_page on the RASTERIZER.
     */
    /* Call original procedure, but "closed" to prevent closing device */
    pwdev->is_open = false;	/* prevent put_params from closing device */
    code = (*pwdev->orig_procs.put_params) (pdev, plist);
    pwdev->is_open = true;
    pwdev->OpenOutputFile = 0;	/* This is wrong, because it causes the same thing in the renderer */

    /* Flush device or emit to command list, depending if device changed geometry */
    if (memcmp(&pwdev->space_params, &save_sp, sizeof(save_sp)) != 0 ||
        pwdev->width != save_width || pwdev->height != save_height
        ) {
        int pageq_remaining;
        int new_width = pwdev->width;
        int new_height = pwdev->height;
        gdev_prn_space_params new_sp = pwdev->space_params;

        /* Need to start a new page, reallocate clist memory */
        pwdev->width = save_width;
        pwdev->height = save_height;
        pwdev->space_params = save_sp;

        /* First, get rid of any pending partial pages */
        code = flush_page(pwdev, false);

        /* Free and reallocate the printer memory. */
        pageq_remaining = 1;	/* assume there are pages left in queue */
        do {
            ecode =
                gdev_prn_reallocate_memory(pdev,
                                           &new_sp, new_width, new_height);
            if (ecode >= 0)
                break;		/* managed to recover enough memory */
            if (!pdev->is_open) {
                /* Disaster! Device was forced closed, which async drivers */
                /* aren't suppsed to do. */
                gdev_prn_async_write_close_device(pdev);
                return ecode;	/* caller 'spozed to know could be closed now */
            }
            pclwdev->error_is_retryable = (ecode == gs_error_VMerror);
        }
        while (pageq_remaining >= 1 &&
               (pageq_remaining = ecode =
                clist_VMerror_recover(pclwdev, ecode)) >= 0);
        if (ecode < 0) {
            gdev_prn_free_memory(pdev);
            pclwdev->is_open = false;
            code = ecode;
        }
    } else if (code >= 0) {
        do
            if ((ecode = cmd_put_params(pclwdev, plist)) >= 0)
                break;
        while ((ecode = clist_VMerror_recover(pclwdev, ecode)) >= 0);
        if (ecode < 0 && pclwdev->error_is_retryable &&
            pclwdev->driver_call_nesting == 0
            )
            ecode = clist_VMerror_recover_flush(pclwdev, ecode);
        if (ecode < 0)
            code = ecode;
    }
    /* Reset fields that got trashed by gdev_prn_put_params and/or gdev_prn_open */
    reinit_printer_into_printera(pwdev);

    return code;
}
Ejemplo n.º 8
0
int main()
{
    /* We need an Ogg stream to write to */

    ogg_stream_state os;
    ogg_packet op;

    /*
      First, a kate_info structure needs to be created and setup for the stream to create.
      A kate_comment structure also has to be created.
      Information from both of these will get encoded into the stream headers.
      Last, we also need a kate_state structure, which will be initialized later.
      */

    kate_info ki;
    kate_comment kc;
    kate_state k;

    kate_info_init(&ki);
    kate_comment_init(&kc);

    /*
      The most important part of the kate_info structure on encoding is the granule
      encoding information, which describes how granules and time are mapped.
      Here, we map one granule to one millisecond.
     */

    ki.granule_shift=32;
    ki.gps_numerator=1000;
    ki.gps_denominator=1;

    /* With that done, we can initialize libkate for encoding, and initialize libogg as well: */

    kate_encode_init(&k,&ki);
    ogg_stream_init(&os,0x12345678);

    /* for the benefit of windows, which mangles data otherwise */
    set_binary_file(stdout);

    /*
      Before you can create events, headers need to be sent. Here, we'll just send
      the headers directly, but you will usually want to add regions, styles, etc to
      the headers before doing so:
      */

    while (kate_ogg_encode_headers(&k,&kc,&op)==0) {
        ogg_stream_packetin(&os,&op);
        ogg_packet_clear(&op);
    }
    flush_page(&os);

    /*
      Events can now be created, and we'll just create and send a single one here,
      starting at time 10 seconds, and stopping at time 15 seconds.
      */

#define text "Hello, world!"
    kate_ogg_encode_text(&k,10.0,15.0,text,strlen(text)+1,&op);
    ogg_stream_packetin(&os,&op);
    ogg_packet_clear(&op);
    flush_page(&os);

    /*
      When we're done, we can tell libkate so an "end of stream" packet will be generated,
      and clear the resources we've been using:
      */

    kate_ogg_encode_finish(&k,-1,&op);
    ogg_stream_packetin(&os,&op);
    ogg_packet_clear(&op);
    flush_page(&os);
    ogg_stream_clear(&os);
    kate_clear(&k);
    kate_info_clear(&ki);
    kate_comment_clear(&kc);

    /*
      That's it, we now have created a full kate stream. You may now want to decode it,
      or multiplex it with a Theora video, etc.
      */

    return 0;
}
Ejemplo n.º 9
0
//======================Compress buf to target=============
// Given: buf and size
// Write the compressed segments to pOut.
// fd is the file descriptor. 
int testCompress(int pOut, unsigned char* buf, size_t size)
{
	int ret = 0;
	z_stream c_stream; /* compression stream */
	int err;
	uLong len = size;
	uLong lastTotal=0;
	int blkCnt = (size%PAGE_SIZE == 0) ? (size/PAGE_SIZE-1):(size/PAGE_SIZE);

	int curSize = 0, lastSize = 0;
	unsigned char lastBuf[OUT_BUF_SIZE];
	unsigned char outBuf[OUT_BUF_SIZE];

	int total_In = 0, Avail_In = 0;
	// unsigned char * curPos_In = NULL; //current input segment pos.
	
	while(total_In < len){

		// Initializing Segments
		c_stream.zalloc = Z_NULL;
		c_stream.zfree = Z_NULL;
		c_stream.opaque = (voidpf)0;
		c_stream.avail_in = 0;
		c_stream.next_in = Z_NULL;

		err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
		CHECK_ERR(err, "deflateInit");

		c_stream.next_in  = (z_const unsigned char *)buf + total_In; 
		
		memset(outBuf, 0, OUT_BUF_SIZE);
		c_stream.next_out = outBuf;
		c_stream.avail_in = PAGE_SIZE;
		c_stream.avail_out = PAGE_SIZE;

		// call deflate, Z_FULL_FLUSH is to reset the dict each time.
		err = deflate(&c_stream, Z_FULL_FLUSH);
		CHECK_ERR(err, "deflate");
		curSize = c_stream.total_out;
		total_In += c_stream.total_in;
		if(DEBUG)	printf("[C] Compressed size is: %d. \n", curSize);

		//try_decomp_W(outBuf);

		//Flush to file.
		check_and_flush(&lastSize, &curSize, lastBuf, outBuf);
		//need to reset lastTotal to calculate the compressed seg size each time
		lastTotal = c_stream.total_out;
		//check the potential errors:
		err = deflateEnd(&c_stream);
		CHECK_ERR(err, "deflateEnd");
	}
	//Still need to check the last un-flushed one.
	if(lastSize || curSize){
		if(DEBUG) printf("[Warning!] the last piece left.\n");
		flush_page(lastBuf, lastSize, 0);
	}
	
	
	/*If store in buffer, then no file writing.*/
	//write_file(pOut, mark, wrBuf, blk);
	/*  */
	
	
	if(DEBUG) printf("Total effective bit written into file: %d, total compressed is: %ld\n", 
						 totalW, lastTotal);
	if(DEBUG) printf("Actual Write: %d ; Request Write: %ld", totalW, size);
	return PAGE_SIZE * blk;
}