/** * Close any open files and destroy the shared memory segment. This must be the last method of this library called. * * Parameters: sys_key - the unique ID of the shared memory segment used in sfs_init and sfs_declare * Returns: 1 on success, 0 otherwise */ int sfs_destroy(int sys_key) { // Reattach to shared memory segment_id = get_segment_id(sys_key); if(segment_id == -1) return 0; shared_memory = (char *) shmat(segment_id, NULL, 0); if(shared_memory == (void *)-1) return 0; memory = (memory_layout *) shared_memory; // Close leftover files // For each resource, if it has outgoing edges, close that file node *cur_resource = memory->resources; while(cur_resource != NULL) { // For each outgoing edge if(cur_resource->out_edges != NULL) { // Close file int result = fclose(cur_resource->fp); if(result == EOF) return 0; } } // Detach and destroy shared memory segment int result = shmdt(shared_memory); if(result == -1) return 0; result = shmctl(segment_id, IPC_RMID, NULL); // Remove the shared memory block forever if(result == -1) return 0; return 1; }
/** * Called once to initialize the shared memory data structures for this library. * * Parameters: sys_key - The ID of the shared memory segment all participating processes should use. * Returns: 1 on success, 0 otherwise */ int sfs_init(int sys_key) { // Initialize shared memory int id = get_segment_id(sys_key); if(id == -1) return 0; char *shared_mem = (char *) shmat(id, NULL, 0); if(shared_mem == (void *)-1) return 0; shared_mem_init(shared_mem); int result = shmdt(shared_mem); if(result == -1) return 0; return 1; }
static void count_segs(const AV1_COMMON *cm, MACROBLOCKD *xd, const TileInfo *tile, MODE_INFO **mi, unsigned *no_pred_segcounts, unsigned (*temporal_predictor_count)[2], unsigned *t_unpred_seg_counts, int bw, int bh, int mi_row, int mi_col) { int segment_id; if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) return; xd->mi = mi; segment_id = xd->mi[0]->mbmi.segment_id; #if CONFIG_DEPENDENT_HORZTILES set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, cm->mi_rows, cm->mi_cols, cm->dependent_horz_tiles); #else set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, cm->mi_rows, cm->mi_cols); #endif // Count the number of hits on each segment with no prediction no_pred_segcounts[segment_id]++; // Temporal prediction not allowed on key frames if (cm->frame_type != KEY_FRAME) { const BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type; // Test to see if the segment id matches the predicted value. const int pred_segment_id = get_segment_id(cm, cm->last_frame_seg_map, bsize, mi_row, mi_col); const int pred_flag = pred_segment_id == segment_id; const int pred_context = av1_get_pred_context_seg_id(xd); // Store the prediction status for this mb and update counts // as appropriate xd->mi[0]->mbmi.seg_id_predicted = pred_flag; temporal_predictor_count[pred_context][pred_flag]++; // Update the "unpredicted" segment count if (!pred_flag) t_unpred_seg_counts[segment_id]++; } }
/** * Declares the shared memory segment this process will be using and the files it will ever possibly open. This must be called before sfs_fopen(). * * Parameters: sys_key - The ID of the shared memory segment initialized in sfs_init. * file_num - The number of files this process might open (or size of filenames) * filenames - The names of the files this process wishes to open (in the future). * Returns: 1 on success, 0 otherwise */ int sfs_declare(int sys_key, int file_num, char *filenames[]) { // Initialize shared memory pointers segment_id = get_segment_id(sys_key); if(segment_id == -1) return 0; shared_memory = (char *) shmat(segment_id, NULL, 0); if(shared_memory == (void *)-1) return 0; memory = (memory_layout *) shared_memory; mutex_lock(memory); // Create process node for this process node *process = create_process_node(memory); if(process == NULL) { mutex_unlock(memory); return 0; } // Create or get resource nodes for all files int i; for(i = 0; i < file_num; i++) { char *name = filenames[i]; node *resource = find_or_create_file_node(memory, name); if(resource == NULL) { mutex_unlock(memory); return 0; } // Record that this process has claim edges to the given files node *list_node_cur = create_list_node(memory, resource, &process->out_edges); if(list_node_cur == NULL) { mutex_unlock(memory); return 0; } } mutex_unlock(memory); return 1; }