// Allocates a new block and updates core id => block mapping. 'old_block' // points to the block that the caller thinks is attached to // 'core_id'. 'old_block' may be NULL. Returns true if: // - allocated a new block OR // - 'core_id' => 'old_block' mapping changed (another thread allocated a // block before lock was acquired). static bool cl_allocate_core_local_block(uint32_t core_id, cl_block* old_block) { // Now that we have the lock, check if core-local mapping has changed. cl_core_local_block* core_local_block = &g_log.core_local_blocks[core_id]; cl_block* block = cl_core_local_block_get_block(core_local_block); if ((block != NULL) && (block != old_block)) { return true; } if (block != NULL) { cl_core_local_block_set_block(core_local_block, NULL); cl_block_list_insert_at_tail(&g_log.dirty_block_list, block); } block = cl_allocate_block(); if (block == NULL) { return false; } cl_core_local_block_set_block(core_local_block, block); cl_block_enable_access(block); return true; }
/* Allocates a new block and updates core id => block mapping. 'old_block' points to the block that the caller thinks is attached to 'core_id'. 'old_block' may be NULL. Returns non-zero if: - allocated a new block OR - 'core_id' => 'old_block' mapping changed (another thread allocated a block before lock was acquired). */ static int cl_allocate_core_local_block(gpr_int32 core_id, cl_block *old_block) { /* Now that we have the lock, check if core-local mapping has changed. */ cl_core_local_block *core_local_block = &g_log.core_local_blocks[core_id]; cl_block *block = cl_core_local_block_get_block(core_local_block); if ((block != NULL) && (block != old_block)) { return 1; } if (block != NULL) { cl_core_local_block_set_block(core_local_block, NULL); cl_block_list_insert_at_tail(&g_log.dirty_block_list, block); } block = cl_allocate_block(); if (block == NULL) { gpr_atm_rel_store(&g_log.is_full, 1); return 0; } cl_core_local_block_set_block(core_local_block, block); cl_block_enable_access(block); return 1; }