示例#1
0
文件: stubs.cpp 项目: gaoxiaojun/dync
Stub* StubQueue::request(int requested_code_size) {
    assert(requested_code_size > 0, "requested_code_size must be > 0");
    if (_mutex != NULL) _mutex->lock();
    Stub* s = current_stub();
    int requested_size = round_to(stub_code_size_to_size(requested_code_size), CodeEntryAlignment);
    if (requested_size <= available_space()) {
        if (is_contiguous()) {
            // Queue: |...|XXXXXXX|.............|
            //        ^0  ^begin  ^end          ^size = limit
            assert(_buffer_limit == _buffer_size, "buffer must be fully usable");
            if (_queue_end + requested_size <= _buffer_size) {
                // code fits in at the end => nothing to do
                CodeStrings strings;
                stub_initialize(s, requested_size, strings);
                return s;
            } else {
                // stub doesn't fit in at the queue end
                // => reduce buffer limit & wrap around
                assert(!is_empty(), "just checkin'");
                _buffer_limit = _queue_end;
                _queue_end = 0;
            }
        }
    }
    if (requested_size <= available_space()) {
        assert(!is_contiguous(), "just checkin'");
        assert(_buffer_limit <= _buffer_size, "queue invariant broken");
        // Queue: |XXX|.......|XXXXXXX|.......|
        //        ^0  ^end    ^begin  ^limit  ^size
        s = current_stub();
        CodeStrings strings;
        stub_initialize(s, requested_size, strings);
        return s;
    }
    // Not enough space left
    if (_mutex != NULL) _mutex->unlock();
    return NULL;
}
示例#2
0
DataPageSlotIndex HashDataPage::reserve_record(
  HashValue hash,
  const BloomFilterFingerprint& fingerprint,
  const char* key,
  uint16_t key_length,
  uint16_t payload_length) {
  ASSERT_ND(header_.page_version_.is_locked());
  ASSERT_ND(available_space() >= HashDataPage::required_space(key_length, payload_length));
  DataPageSlotIndex index = get_record_count();
  Slot& slot = get_slot(index);
  slot.offset_ = next_offset();
  slot.hash_ = hash;
  slot.key_length_ = key_length;
  slot.physical_record_length_ = assorted::align8(key_length) + assorted::align8(payload_length);
  slot.payload_length_ = 0;
  char* record = record_from_offset(slot.offset_);
  std::memcpy(record, key, key_length);
  if (key_length % 8 != 0) {
    std::memset(record + key_length, 0, 8 - (key_length % 8));
  }
  xct::XctId initial_id;
  initial_id.set(
    Epoch::kEpochInitialCurrent,  // TODO(Hideaki) this should be something else
    0);
  initial_id.set_deleted();
  slot.tid_.xct_id_ = initial_id;

  // we install the fingerprint to bloom filter BEFORE we increment key count.
  // it's okay for concurrent reads to see false positives, but false negatives are wrong!
  bloom_filter_.add(fingerprint);

  // we increment key count AFTER installing the key because otherwise the optimistic read
  // might see the record but find that the key doesn't match. we need a fence to prevent it.
  assorted::memory_fence_release();
  header_.increment_key_count();

  return index;
}
示例#3
0
		int write(char* data, int length)
		{
			if (available_data() == 0)
			{
				this->start = this->end = 0;
			}
			
			if (length > available_space())
			{
				return E_NO_SPACE;
			}
			
			void* result = memcpy(ends_at(), data, length);
			if (result == nullptr)
			{
				return E_WRITE_FAILED;
			}
			
			// commit write
			this->end = (this->end + length) % this->size;
			// return length written
			return length;
		}
示例#4
0
/*************************************************************************
 *
 *N  draw_selected_features
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    This function draws the selected features from a specified feature
 *    class based upon a query (either an expression or the pre-compiled
 *    results of an expression).
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *     view     <inout>==(view_type *) view structure.
 *     themenum <input>==(int) theme number.
 *     library  <input>==(library_type *) VPF library structure.
 *     mapenv   <input>==(map_environment_type *) map environment structure.
 *     return  <output>==(int) completion status:
 *                                1 if completed successfully,
 *                                0 if an error occurred.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels   August 1991                        DOS Turbo C
 *E
 *************************************************************************/
int draw_selected_features( view_type *view,
			    int themenum,
			    library_type *library,
			    map_environment_type *mapenv )
{
   int status, fcnum, finished, cov, tilecover, TILEPATH_, prim;
   int outline, color1, color2, color3, color4;
   vpf_table_type rngtable,edgtable,fbrtable, tile_table;
   row_type row;
   char *ptable[] = {"","edg","fac","txt","end","cnd"};
   register rspf_int32 i, j, p, pclass, tile;
   int display_order[] = {FACE,EDGE,ENTITY_NODE,CONNECTED_NODE,TEXT};
   register rspf_int32 starttile, endtile, startprim, endprim;
   rspf_int32 count;
   char path[255], covpath[255], tiledir[255], *buf, str[255];
   char *drive, rngpath[255],edgpath[255],edxpath[255],fbrpath[255];
   boolean rng_rdisk,edg_rdisk,fbr_rdisk;
   set_type primitives, feature_rows;
   fcrel_type fcrel;
   window_type info;
   struct viewporttype vp;

   getviewsettings(&vp);

   fcnum = view->theme[themenum].fcnum;

   sprintf(path,"%stileref\\tileref.aft",library->path);
   if (access(path,0) != 0) {
      tilecover = FALSE;
   } else {
      tile_table = vpf_open_table(path,disk,"rb",NULL);
      TILEPATH_ = table_pos("TILE_NAME",tile_table);
      tilecover = TRUE;
   }

   feature_rows = get_selected_features( view, themenum, *library );

   for (p=0;p<5;p++) {
      pclass = display_order[p];

      if ((pclass != library->fc[fcnum].primclass) &&
	  (library->fc[fcnum].primclass != COMPLEX_FEATURE)) continue;

      if ((library->fc[fcnum].primclass == COMPLEX_FEATURE) &&
	  (!library->fc[fcnum].cprim[pclass])) continue;

      /* Set up the feature class table relate chain.        */
      /* The feature table is fcrel.table[0].                */
      /* The primitive table is the last table in the chain: */
      /*    fcrel.table[ fcrel.nchain-1 ].                   */

      j = 0;
      for (i=0;i<strlen(library->fc[fcnum].table);i++)
	 if (library->fc[fcnum].table[i] == '\\') j = i+1;
      strcpy( str, &(library->fc[fcnum].table[j]));
      fcrel = select_feature_class_relate(fcnum, library, str,
					  ptable[pclass]);
      prim = fcrel.nchain-1;

      /*** 'Tile' number 1 is the universe polygon for
	   the tileref cover ***/
      starttile = set_min(library->tile_set);
      if (starttile < 2) starttile = 2;
      endtile = set_max(library->tile_set);
      if (endtile < 2) endtile = 2;

      for (tile = starttile; tile <= endtile; tile++ ) {

	 if (!set_member(tile,library->tile_set)) continue;

	 if (tilecover) {
	    row = get_row(tile,tile_table);
	    buf = (char *)get_table_element(TILEPATH_,row,tile_table,
					     NULL,&count);
	    free_row(row,tile_table);
	    strcpy(tiledir,buf);
	    rightjust(tiledir);
	    strcat(tiledir,"\\");
	    free(buf);
	 } else {
	    strcpy(tiledir,"");
	 }

	 cov = library->fc[fcnum].coverage;
	 strcpy( covpath, library->cover[cov].path );

	 finished = TRUE;

	 sprintf(path,"%s%s%s",covpath,tiledir,ptable[pclass]);

	 if (access(path,0) != 0) continue;
	 fcrel.table[prim] = vpf_open_table(path,disk,"rb",NULL);

	 info = info_window("Searching...");

	 primitives = get_selected_tile_primitives( library,
						    fcnum, fcrel,
						    feature_rows,
						    mapenv,
						    tile, tiledir,
						    &status );
	 delete_window(&info);
	 setviewport(vp.left,vp.top,vp.right,vp.bottom,vp.clip);

	 /* Reset plate-carree parameters (changed in  */
	 /* get_selected_tile_primitives() )           */
	 if (mapenv->projection == PLATE_CARREE)
	    set_plate_carree_parameters( central_meridian(
					 mapenv->mapextent.x1,
					 mapenv->mapextent.x2),
					 0.0, 1.0 );

	 if (primitives.size < 1) {
	    vpf_close_table(&fcrel.table[prim]);
	    continue;
	 }

	 if (!status) {
	    set_nuke(&primitives);
	    vpf_close_table(&fcrel.table[prim]);
	    break;
	 }

	 if (pclass == FACE) {
	    /* Must also open RNG, EDG, and FBR for drawing faces. */
	    /* If a RAM disk is specified, copy these to it and open */
	    /* them there. */
	    rng_rdisk = FALSE;
	    edg_rdisk = FALSE;
	    fbr_rdisk = FALSE;
	    drive = getenv("TMP");
	    buf = (char *)vpfmalloc(255);

	    sprintf(path,"%s%srng",covpath,tiledir);
	    strcpy(rngpath,path);
	    if (drive && filesize(path) < available_space(drive)) {
	       sprintf(rngpath,"%s\\RNG",drive);
	       sprintf(buf,"COPY %s %s > NUL",path,rngpath);
	       system(buf);
	       rng_rdisk = TRUE;
	    }
	    rngtable = vpf_open_table(rngpath,disk,"rb",NULL);

	    sprintf(path,"%s%sedg",covpath,tiledir);
	    strcpy(edgpath,path);
            sprintf(edxpath,"%s%sedx",covpath,tiledir);
	    if (drive &&
	       (filesize(path)+filesize(edxpath))<available_space(drive)) {
	       sprintf(edgpath,"%s\\EDG",drive);
	       sprintf(buf,"COPY %s %s > NUL",path,edgpath);
	       system(buf);
	       sprintf(edxpath,"%s\\EDX",drive);
	       sprintf(buf,"COPY %s%sedx %s > NUL",covpath,tiledir,edxpath);
	       system(buf);
	       edg_rdisk = TRUE;
	    }
	    edgtable = vpf_open_table(edgpath,disk,"rb",NULL);

	    sprintf(path,"%s%sfbr",covpath,tiledir);
	    strcpy(fbrpath,path);
	    if (drive && filesize(path) < available_space(drive)) {
	       sprintf(fbrpath,"%s\\FBR",drive);
	       sprintf(buf,"COPY %s %s > NUL",path,fbrpath);
	       system(buf);
	       fbr_rdisk = TRUE;
	    }
	    fbrtable = vpf_open_table(fbrpath,disk,"rb",NULL);

	    free(buf);
	 }

	 finished = 1;

	 startprim = set_min(primitives);
	 endprim = set_max(primitives);

	 /* It turns out to be MUCH faster off of a CD-ROM to */
	 /* read each row and discard unwanted ones than to   */
	 /* forward seek past them.  It's about the same off  */
	 /* of a hard disk.				      */

	 fseek(fcrel.table[prim].fp,
	       index_pos(startprim,fcrel.table[prim]),
	       SEEK_SET);

	 for (i=startprim;i<=endprim;i++) {

	    row = read_next_row(fcrel.table[prim]);

	    if (set_member( i, primitives )) {
	       /* Draw the primitive */
	       switch (pclass) {
		  case EDGE:
		     finished = draw_edge_row(row,fcrel.table[prim]);
		     break;
		  case ENTITY_NODE:
		  case CONNECTED_NODE:
		     finished = draw_point_row(row,fcrel.table[prim]);
		     break;
		  case FACE:
		     gpgetlinecolor( &outline );
		     gpgetpattern( &color1, &color2, &color3, &color4 );
		     hidemousecursor();
		     draw_face_row( row,fcrel.table[prim],
				    rngtable, edgtable, fbrtable,
				    outline,
				    color1, color2, color3, color4 );
		     showmousecursor();
		     finished = 1;
		     if (kbhit()) {
			if (getch()==27) finished = 0;
		     }
		     break;
		  case TEXT:
		     finished = draw_text_row(row,fcrel.table[prim]);
		     break;
	       }
	    }

	    free_row(row,fcrel.table[prim]);

	    if (!finished) {
	       status = 0;
	       break;
	    }
	 }

	 if (pclass == FACE) {
	    vpf_close_table(&rngtable);
	    if (rng_rdisk) remove(rngpath);
	    vpf_close_table(&edgtable);
	    if (edg_rdisk) {
	       remove(edgpath);
	       remove(edxpath);
	    }
	    vpf_close_table(&fbrtable);
	    if (fbr_rdisk) remove(fbrpath);
	 }

	 vpf_close_table(&fcrel.table[prim]);

	 set_nuke(&primitives);

	 if (!finished) {
	    status = 0;
	    break;
	 }

      }

      if (!finished) {
	 status = 0;
	 deselect_feature_class_relate( &fcrel );
	 break;
      }

      status = 1;

      if (kbhit()) {
	 if (getch()==27) {
	    status = 0;
	    deselect_feature_class_relate( &fcrel );
	    break;
	 }
      }

      deselect_feature_class_relate(&fcrel);
   }

   if (tilecover) {
      vpf_close_table(&tile_table);
   }

   set_nuke(&feature_rows);

   return status;
}
示例#5
0
// **********************************************************
// Add a new record to the page. Returns OK if everything went OK
// otherwise, returns DONE if sufficient space does not exist
// RID of the new record is returned via rid parameter.
Status HFPage::insertRecord(char* recPtr, int recLen, RID& rid)
{
		int i;
		int slot_n;
		//slot_t *curr;
    if(available_space() < (int)(recLen + sizeof(slot_t)))
			return DONE;

		// find an empty slot
		// int slot_n = findEmptySlot();
		slot_n = ALL_SLOTS_FULL;
		for(i = 0; i < slotCnt; i++) {
			if(slot[i].length == EMPTY_SLOT) {
				slot_n = i;
				break;
			}
		}
		/*
		if(slotCnt > 0) {
			if(slot[0].length == EMPTY_SLOT) {
				slot_n = 0;
			} else {
				for(i = 1; i < slotCnt; i++) {
					curr = (slot_t*) (data + i*sizeof(slot_t));
					if(curr->length == EMPTY_SLOT) {
						slot_n = i;
						break;
					}
				}
			}
		}*/
		
		if(slot_n == ALL_SLOTS_FULL) {				// Add a new slot and add data to `front` of data[]
			usedPtr -= recLen;
			memcpy(data+usedPtr, recPtr, recLen);
	
			/*slot_t *newSlot = slotCnt ? (slot_t*) (data + (slotCnt-1)*sizeof(slot_t)) : slot; */
			slot_t *newSlot = slot + slotCnt;
			newSlot->offset = usedPtr;
			newSlot->length = recLen;
			//if(slotCnt != 0)
				freeSpace -= sizeof(slot_t); 			/// ??????? 
			
			rid.slotNo = slotCnt; 		
			slotCnt++;
	
		} else {
			rid.slotNo = slot_n;
			// slot_t* s = slot_n ? (slot_t*) (data + (slot_n-1) * sizeof(slot_t)) : slot; 
			slot_t *s = slot + slot_n;

			// shiftRecordOffsets(s+1, -recLen);
			for(i = slot_n+1; i < slotCnt; i++) {
				//slot_t* curr = (slot_t*) (data + i*sizeof(slot_t));
				slot_t *curr = slot + i;
				curr->offset -= recLen;
			}

			memmove(data + usedPtr-recLen, data + usedPtr, s->offset - usedPtr);		// critical: s->offset must be equal to the offset of the `next` record
			s->length = recLen;																										// (the one with the previous slot number, next in memory)
			s->offset -= recLen;

			memcpy(data + s->offset, recPtr, recLen);
		}

		rid.pageNo = curPage;
		freeSpace -= recLen;
    return OK;
}