/*消除行后用递归标记分隔的块组*/ static void mark_block(Uchar map[BLOCK_MAP_H][BLOCK_MAP_W], block_group_t * blocks_list, int mark, int x, int y, int bottom) { if (x < 0 || x == BLOCK_MAP_W || y < 0 || y == bottom) return; if (map[y][x] == 1) { block_list_t * list; list = (block_list_t *)malloc(sizeof(block_list_t)); list->x = x; list->y = y; list->next = blocks_list->head; blocks_list->head = list; if (y < blocks_list->top) blocks_list->top = y; if (y > blocks_list->bottom) blocks_list->bottom = y; map[y][x] = mark; mark_block(map, blocks_list, mark, x + 1, y, bottom); mark_block(map, blocks_list, mark, x, y + 1, bottom); mark_block(map, blocks_list, mark, x - 1, y, bottom); mark_block(map, blocks_list, mark, x, y - 1, bottom); } }
int i915_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_i915_private *dev_priv = dev->dev_private; struct drm_i915_mem_free *memfree = data; struct mem_block *block, **heap; if (!dev_priv) { DRM_ERROR("%s called with no initialization\n", __FUNCTION__); return -EINVAL; } heap = get_heap(dev_priv, memfree->region); if (!heap || !*heap) return -EFAULT; block = find_block(*heap, memfree->region_offset); if (!block) return -EFAULT; if (block->file_priv != file_priv) return -EPERM; mark_block(dev, block, 0); free_block(block); return 0; }
/* Free all blocks associated with the releasing file. */ void i915_mem_release(struct drm_device * dev, struct drm_file *file_priv, struct mem_block *heap) { struct mem_block *p; if (!heap || !heap->next) return; for (p = heap->next; p != heap; p = p->next) { if (p->file_priv == file_priv) { p->file_priv = NULL; mark_block(dev, p, 0); } } /* Assumes a single contiguous range. Needs a special file_priv in * 'heap' to stop it being subsumed. */ for (p = heap->next; p != heap; p = p->next) { while (p->file_priv == NULL && p->next->file_priv == NULL) { struct mem_block *q = p->next; p->size += q->size; p->next = q->next; p->next->prev = p; drm_free(q, sizeof(*q), DRM_MEM_BUFLISTS); } } }
int i915_mem_free(DRM_IOCTL_ARGS) { DRM_DEVICE; drm_i915_private_t *dev_priv = dev->dev_private; drm_i915_mem_free_t memfree; struct mem_block *block, **heap; if (!dev_priv) { DRM_ERROR("%s called with no initialization\n", __FUNCTION__); return DRM_ERR(EINVAL); } DRM_COPY_FROM_USER_IOCTL(memfree, (drm_i915_mem_free_t __user *) data, sizeof(memfree)); heap = get_heap(dev_priv, memfree.region); if (!heap || !*heap) return DRM_ERR(EFAULT); block = find_block(*heap, memfree.region_offset); if (!block) return DRM_ERR(EFAULT); if (block->filp != filp) return DRM_ERR(EPERM); mark_block(dev, block, 0); free_block(block); return 0; }
int i915_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv) { drm_i915_private_t *dev_priv = dev->dev_private; drm_i915_mem_alloc_t *alloc = data; struct mem_block *block, **heap; if (!dev_priv) { DRM_ERROR("called with no initialization\n"); return -EINVAL; } heap = get_heap(dev_priv, alloc->region); if (!heap || !*heap) return -EFAULT; if (alloc->alignment < 12) alloc->alignment = 12; block = alloc_block(*heap, alloc->size, alloc->alignment, file_priv); if (!block) return -ENOMEM; mark_block(dev, block, 1); if (DRM_COPY_TO_USER(alloc->region_offset, &block->start, sizeof(int))) { DRM_ERROR("copy_to_user\n"); return -EFAULT; } return 0; }
void i915_mem_release(struct drm_device * dev, struct drm_file *file_priv, struct mem_block *heap) { struct mem_block *p; if (!heap || !heap->next) return; for (p = heap->next; p != heap; p = p->next) { if (p->file_priv == file_priv) { p->file_priv = NULL; mark_block(dev, p, 0); } } for (p = heap->next; p != heap; p = p->next) { while (p->file_priv == NULL && p->next->file_priv == NULL) { struct mem_block *q = p->next; p->size += q->size; p->next = q->next; p->next->prev = p; kfree(q); } } }
// Adjust BOT to show that a previously whole block has been split // into two. void G1BlockOffsetArray::split_block(HeapWord* blk, size_t blk_size, size_t left_blk_size) { // Verify that the BOT shows [blk, blk + blk_size) to be one block. verify_single_block(blk, blk_size); // Update the BOT to indicate that [blk + left_blk_size, blk + blk_size) // is one single block. mark_block(blk + left_blk_size, blk + blk_size); }
static int mark_block_group(Player * player, block_group_t * group_list, int * mark_nr) { int y; int bottom = 0; int mark = 2; for (y = BLOCK_MAP_H - 1; y >= 0; y--) { int x, xx = 0; for (x = 0; x < BLOCK_MAP_W; x++) if (player->block_map[y][x] > 0) { player->block_map[y][x] = 1; xx++; } if (xx == BLOCK_MAP_W) { player->grade++; for (x = 0; x < BLOCK_MAP_W; x++) player->block_map[y][x] = 0; if (bottom == 0) bottom = y; } } while (bottom > 0) { int left = 0; int top = 0; for (; top < bottom; top++) { for (left = 0; left < BLOCK_MAP_W && player->block_map[top][left] != 1; left++); if (left < BLOCK_MAP_W) break; } if (left == BLOCK_MAP_W) break; mark_block(player->block_map, &group_list[mark-2], mark, left, top, bottom); (*mark_nr)++; mark++; } if (mark > 2) return 1; return 0; }
void egc_mark_pointer_array(void **pointer_array, size_t size) { t_block *block; t_statics *statics; char *char_array; void *p; if (size < sizeof(void *)) return ; char_array = (char *)pointer_array; statics = STATICS; size -= sizeof(void *); while (size) { p = *(void **)(char_array + size); block = egc_find_pointed_to_block(statics, p); if (block) mark_block(block); size--; } }
int i915_mem_alloc(DRM_IOCTL_ARGS) { DRM_DEVICE; drm_i915_private_t *dev_priv = dev->dev_private; drm_i915_mem_alloc_t alloc; struct mem_block *block, **heap; if (!dev_priv) { DRM_ERROR("%s called with no initialization\n", __FUNCTION__); return DRM_ERR(EINVAL); } DRM_COPY_FROM_USER_IOCTL(alloc, (drm_i915_mem_alloc_t __user *) data, sizeof(alloc)); heap = get_heap(dev_priv, alloc.region); if (!heap || !*heap) return DRM_ERR(EFAULT); /* Make things easier on ourselves: all allocations at least * 4k aligned. */ if (alloc.alignment < 12) alloc.alignment = 12; block = alloc_block(*heap, alloc.size, alloc.alignment, filp); if (!block) return DRM_ERR(ENOMEM); mark_block(dev, block, 1); if (DRM_COPY_TO_USER(alloc.region_offset, &block->start, sizeof(int))) { DRM_ERROR("copy_to_user\n"); return DRM_ERR(EFAULT); } return 0; }
int i915_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_i915_private *dev_priv = dev->dev_private; struct drm_i915_mem_alloc *alloc = data; struct mem_block *block, **heap; if (!dev_priv) { DRM_ERROR("%s called with no initialization\n", __FUNCTION__); return -EINVAL; } heap = get_heap(dev_priv, alloc->region); if (!heap || !*heap) return -EFAULT; /* Make things easier on ourselves: all allocations at least * 4k aligned. */ if (alloc->alignment < 12) alloc->alignment = 12; block = alloc_block(*heap, alloc->size, alloc->alignment, file_priv); if (!block) return -ENOMEM; mark_block(dev, block, 1); if (DRM_COPY_TO_USER(alloc->region_offset, &block->start, sizeof(int))) { DRM_ERROR("copy_to_user\n"); return -EFAULT; } return 0; }
// The block [blk_start, blk_end) has been allocated; // adjust the block offset table to represent this information; // right-open interval: [blk_start, blk_end) void G1BlockOffsetArray::alloc_block(HeapWord* blk_start, HeapWord* blk_end) { mark_block(blk_start, blk_end); allocated(blk_start, blk_end); }
SHORT block_end(void) { mark_block(1); }
SHORT block_start(void) { mark_block(0); }
int TorrentFile::unmark_block(uint32_t piece_index, uint32_t block_index) { return mark_block(piece_index, block_index, NULL); }