int insert_tetri(t_tetri *tetri, int i, t_square *sq, int tetri_nb) { int x; int y; y = 0; while (y < sq->y_max) { x = 0; while (x < sq->x_max) { set_position(tetri, i, x, y); if (!is_outside(tetri[i], sq) && !is_overlapping(tetri, i)) { if (i == tetri_nb - 1) return (1); if (insert_tetri(tetri, i + 1, sq, tetri_nb)) return (1); } x++; } y++; } return (0); }
/** * \brief Search for elements in 'box' in the Rtree. Add them to 'result'. * If exact_match is true only return the elements having as * key the box 'box'. Otherwise return everything inside 'box'. */ virtual void find(Box const& box, std::deque<Value>& result, bool const exact_match) { for (typename node_map::const_iterator it = m_nodes.begin(); it != m_nodes.end(); ++it) { if (is_overlapping(it->first, box)) { it->second->find(box, result, exact_match); } } }
int is_valid_board(const board_t* board) { assert(NULL != board); // make sure no cell being occupied by both players for (size_t i = 0; i < ROWS; i++) { if (is_overlapping(board->b[W][i], board->b[B][i])) return 0; } return 1; }
/** * \brief Return in 'result' all the leaves inside 'box' */ void find_leaves(Box const& box, typename std::vector<node_pointer>& result) const { for (typename node_map::const_iterator it = m_nodes.begin(); it != m_nodes.end(); ++it) { if (is_overlapping(it->first, box)) { if (it->second->is_leaf()) { result.push_back(it->second); } else { it->second->find_leaves(box, result); } } } }
static sbd_status_t sbd_ats_do_handling_before_io(scsi_task_t *task, struct sbd_lu *sl, uint64_t lba, uint64_t count, uint32_t flags) { sbd_status_t ret = SBD_SUCCESS; ats_state_t *ats_state, *ats_state_ret; sbd_cmd_t *scmd = (sbd_cmd_t *)task->task_lu_private; uint8_t cdb0 = task->task_cdb[0]; if (HardwareAcceleratedLocking == 0) return (SBD_SUCCESS); mutex_enter(&sl->sl_lock); /* * if the list is empty then just add the element to the list and * return success. There is no overlap. This is done for every * read, write or compare and write. */ if (list_is_empty(&sl->sl_ats_io_list)) { goto done; } /* * There are inflight operations. As a result the list must be scanned * and if there are any overlaps then SBD_BUSY should be returned. * * Duplicate reads and writes are allowed and kept on the list * since there is no reason that overlapping IO operations should * be delayed. * * A command that conflicts with a running compare and write will * be rescheduled and rerun. This is handled by stmf_task_poll_lu. * There is a possibility that a command can be starved and still * return busy, which is valid in the SCSI protocol. */ for (ats_state = list_head(&sl->sl_ats_io_list); ats_state != NULL; ats_state = list_next(&sl->sl_ats_io_list, ats_state)) { if (is_overlapping(ats_state->as_cur_ats_lba, ats_state->as_cur_ats_len, lba, count) == 0) continue; /* if the task is already listed just return */ if (task == ats_state->as_cur_ats_task) { cmn_err(CE_WARN, "sbd_ats_handling_before_io: " "task %p already on list", (void *) task); ret = SBD_SUCCESS; goto exit; } /* * the current command is a compare and write, if there is any * overlap return error */ if ((cdb0 == SCMD_COMPARE_AND_WRITE) || (ats_state->as_cmd == SCMD_COMPARE_AND_WRITE)) { ret = SBD_BUSY; goto exit; } } done: ats_state_ret = (ats_state_t *)kmem_zalloc(sizeof (ats_state_t), KM_SLEEP); ats_state_ret->as_cur_ats_lba = lba; ats_state_ret->as_cur_ats_len = count; ats_state_ret->as_cmd = cdb0; ats_state_ret->as_cur_ats_task = task; if (list_is_empty(&sl->sl_ats_io_list)) { list_insert_head(&sl->sl_ats_io_list, ats_state_ret); } else { list_insert_tail(&sl->sl_ats_io_list, ats_state_ret); } scmd->flags |= SBD_SCSI_CMD_ATS_RELATED; scmd->ats_state = ats_state; sbd_list_length++; mutex_exit(&sl->sl_lock); return (SBD_SUCCESS); exit: mutex_exit(&sl->sl_lock); if (ret == SBD_SUCCESS) return (SBD_SUCCESS); /* * if the command cannot be allowed to be restarted then just * return an error. At the moment only unmap has this property. * Please refer to sbd_handle_unmap_xfer in sbd_scsi.c for full * details. */ if ((flags & SBD_ATS_NO_BUSY) != 0) return (ret); /* * at this point the command overlaps a running a compare and write. * It is either a compare and write overlapping a op or an op * overlapping a compare and write. It needs to be delayed. That * means it is not active so if the stmf_task_poll_lu works * turn off active */ if (stmf_task_poll_lu(task, 10) != STMF_SUCCESS) stmf_scsilib_send_status(task, STATUS_BUSY, 0); else scmd->flags &= ~SBD_SCSI_CMD_ACTIVE; return (ret); }
void NotificationWindow::SetPosition() { Layout(true); BRect bounds = DecoratorFrame(); float width = Bounds().Width() + 1; float height = Bounds().Height() + 1; float leftOffset = Frame().left - bounds.left; float topOffset = Frame().top - bounds.top + 1; float rightOffset = bounds.right - Frame().right; float bottomOffset = bounds.bottom - Frame().bottom; // Size of the borders around the window float x = Frame().left; float y = Frame().top; // If we cant guess, don't move... BPoint location(x, y); BDeskbar deskbar; // If notification and deskbar position are same // then follow deskbar position uint32 position = (is_overlapping(deskbar.Location(), fPosition)) ? B_FOLLOW_DESKBAR : fPosition; if (position == B_FOLLOW_DESKBAR) { BRect frame = deskbar.Frame(); switch (deskbar.Location()) { case B_DESKBAR_TOP: // In case of overlapping here or for bottom // use user's notification position y = frame.bottom + topOffset; x = (fPosition == (B_FOLLOW_LEFT | B_FOLLOW_TOP)) ? frame.left + rightOffset : frame.right - width + rightOffset; break; case B_DESKBAR_BOTTOM: y = frame.top - height - bottomOffset; x = (fPosition == (B_FOLLOW_LEFT | B_FOLLOW_BOTTOM)) ? frame.left + rightOffset : frame.right - width + rightOffset; break; case B_DESKBAR_RIGHT_TOP: y = frame.top - topOffset + 1; x = frame.left - width - rightOffset; break; case B_DESKBAR_LEFT_TOP: y = frame.top - topOffset + 1; x = frame.right + leftOffset; break; case B_DESKBAR_RIGHT_BOTTOM: y = frame.bottom - height + bottomOffset; x = frame.left - width - rightOffset; break; case B_DESKBAR_LEFT_BOTTOM: y = frame.bottom - height + bottomOffset; x = frame.right + leftOffset; break; default: break; } location = BPoint(x, y); } else if (position == (B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM)) { location = BScreen().Frame().RightBottom(); location -= BPoint(width, height); } else if (position == (B_FOLLOW_LEFT | B_FOLLOW_BOTTOM)) { location = BScreen().Frame().LeftBottom(); location -= BPoint(0, height); } else if (position == (B_FOLLOW_RIGHT | B_FOLLOW_TOP)) { location = BScreen().Frame().RightTop(); location -= BPoint(width, 0); } else if (position == (B_FOLLOW_LEFT | B_FOLLOW_TOP)) { location = BScreen().Frame().LeftTop(); } MoveTo(location); }