int main() { boost::thread pop_sync1(&popper_sync); boost::thread pop_sync2(&popper_sync); boost::thread pop_sync3(&popper_sync); boost::thread push1(&pusher); boost::thread push2(&pusher); boost::thread push3(&pusher); // Waiting for all the tasks to push push1.join(); push2.join(); push3.join(); g_queue.flush(); // Waiting for all the tasks to pop pop_sync1.join(); pop_sync2.join(); pop_sync3.join(); // Asserting that no tasks remained, // and falling though without blocking assert(!g_queue.try_pop_task()); g_queue.push_task(&do_nothing); // Asserting that there is a task, // and falling though without blocking assert(g_queue.try_pop_task()); }
t_lst *algo(t_lst *lst_a, t_lst *lst_b, t_lst *tmp, int c) { lst_a = tmp; while (ft_check(lst_a, lst_b, tmp) == 0) { if (ft_check(lst_a = swap(lst_a, tmp, lst_b), lst_b, tmp) == 1) return (lst_a); c = add(lst_a, tmp, c); lst_a = add2(lst_a, lst_b, tmp, c); if (lst_a->content == c && ft_check(tmp, lst_b, tmp) == 0) { lst_a = tmp; lst_b = push(lst_b, lst_a, tmp, "pb "); lst_a = push2(lst_a, lst_b, tmp); } if (lst_a == NULL) while (lst_b != NULL) { if (lst_b->next == NULL) lst_a = push(lst_a, lst_b, tmp, "pa\n"); else lst_a = push(lst_a, lst_b, tmp, "pa "); lst_a = tmp; lst_b = push3(lst_b, lst_a, tmp); } } return (lst_a); }
Calculator::Calculator(QWidget *parent) : QWidget(parent), ui(new Ui::Calculator) { ui->setupUi(this); pastNumber = 0; currentNumber = ui->lcd->value(); state = '\0'; point = false; in = false; count = 0; connect(ui->button0, SIGNAL(clicked()), this, SLOT(push0())); connect(ui->button1, SIGNAL(clicked()), this, SLOT(push1())); connect(ui->button2, SIGNAL(clicked()), this, SLOT(push2())); connect(ui->button3, SIGNAL(clicked()), this, SLOT(push3())); connect(ui->button4, SIGNAL(clicked()), this, SLOT(push4())); connect(ui->button5, SIGNAL(clicked()), this, SLOT(push5())); connect(ui->button6, SIGNAL(clicked()), this, SLOT(push6())); connect(ui->button7, SIGNAL(clicked()), this, SLOT(push7())); connect(ui->button8, SIGNAL(clicked()), this, SLOT(push8())); connect(ui->button9, SIGNAL(clicked()), this, SLOT(push9())); connect(ui->buttonDot, SIGNAL(clicked()), this, SLOT(pushpoint())); connect(ui->buttonCE, SIGNAL(clicked()), this, SLOT(ce())); connect(ui->buttonC, SIGNAL(clicked()), this, SLOT(c())); connect(ui->buttonPlus, SIGNAL(clicked()), this, SLOT(pushPlus())); connect(ui->buttonSub, SIGNAL(clicked()), this, SLOT(pushSub())); connect(ui->buttonTimes, SIGNAL(clicked()), this, SLOT(pushTimes())); connect(ui->buttonDiv, SIGNAL(clicked()), this, SLOT(pushDiv())); connect(ui->buttonEqual, SIGNAL(clicked()), this, SLOT(pushEqual())); QFont font = ui->button0->font(); font.setPointSize(40); ui->button0->setFont(font); ui->button1->setFont(font); ui->button2->setFont(font); ui->button3->setFont(font); ui->button4->setFont(font); ui->button5->setFont(font); ui->button6->setFont(font); ui->button7->setFont(font); ui->button8->setFont(font); ui->button9->setFont(font); ui->buttonC->setFont(font); ui->buttonCE->setFont(font); ui->buttonEqual->setFont(font); ui->buttonDiv->setFont(font); ui->buttonTimes->setFont(font); ui->buttonPlus->setFont(font); ui->buttonSub->setFont(font); ui->buttonDot->setFont(font); }
static void getHeightData(rcContext* ctx, const rcCompactHeightfield& chf, const unsigned short* poly, const int npoly, const unsigned short* verts, const int bs, rcHeightPatch& hp, rcIntArray& queue, int region) { // Note: Reads to the compact heightfield are offset by border size (bs) // since border size offset is already removed from the polymesh vertices. queue.resize(0); // Set all heights to RC_UNSET_HEIGHT. memset(hp.data, 0xff, sizeof(unsigned short)*hp.width*hp.height); bool empty = true; // We cannot sample from this poly if it was created from polys // of different regions. If it was then it could potentially be overlapping // with polys of that region and the heights sampled here could be wrong. if (region != RC_MULTIPLE_REGS) { // Copy the height from the same region, and mark region borders // as seed points to fill the rest. for (int hy = 0; hy < hp.height; hy++) { int y = hp.ymin + hy + bs; for (int hx = 0; hx < hp.width; hx++) { int x = hp.xmin + hx + bs; const rcCompactCell& c = chf.cells[x + y*chf.width]; for (int i = (int)c.index, ni = (int)(c.index + c.count); i < ni; ++i) { const rcCompactSpan& s = chf.spans[i]; if (s.reg == region) { // Store height hp.data[hx + hy*hp.width] = s.y; empty = false; // If any of the neighbours is not in same region, // add the current location as flood fill start bool border = false; for (int dir = 0; dir < 4; ++dir) { if (rcGetCon(s, dir) != RC_NOT_CONNECTED) { const int ax = x + rcGetDirOffsetX(dir); const int ay = y + rcGetDirOffsetY(dir); const int ai = (int)chf.cells[ax + ay*chf.width].index + rcGetCon(s, dir); const rcCompactSpan& as = chf.spans[ai]; if (as.reg != region) { border = true; break; } } } if (border) push3(queue, x, y, i); break; } } } } } // if the polygon does not contain any points from the current region (rare, but happens) // or if it could potentially be overlapping polygons of the same region, // then use the center as the seed point. if (empty) seedArrayWithPolyCenter(ctx, chf, poly, npoly, verts, bs, hp, queue); static const int RETRACT_SIZE = 256; int head = 0; // We assume the seed is centered in the polygon, so a BFS to collect // height data will ensure we do not move onto overlapping polygons and // sample wrong heights. while (head*3 < queue.size()) { int cx = queue[head*3+0]; int cy = queue[head*3+1]; int ci = queue[head*3+2]; head++; if (head >= RETRACT_SIZE) { head = 0; if (queue.size() > RETRACT_SIZE*3) memmove(&queue[0], &queue[RETRACT_SIZE*3], sizeof(int)*(queue.size()-RETRACT_SIZE*3)); queue.resize(queue.size()-RETRACT_SIZE*3); } const rcCompactSpan& cs = chf.spans[ci]; for (int dir = 0; dir < 4; ++dir) { if (rcGetCon(cs, dir) == RC_NOT_CONNECTED) continue; const int ax = cx + rcGetDirOffsetX(dir); const int ay = cy + rcGetDirOffsetY(dir); const int hx = ax - hp.xmin - bs; const int hy = ay - hp.ymin - bs; if ((unsigned int)hx >= (unsigned int)hp.width || (unsigned int)hy >= (unsigned int)hp.height) continue; if (hp.data[hx + hy*hp.width] != RC_UNSET_HEIGHT) continue; const int ai = (int)chf.cells[ax + ay*chf.width].index + rcGetCon(cs, dir); const rcCompactSpan& as = chf.spans[ai]; hp.data[hx + hy*hp.width] = as.y; push3(queue, ax, ay, ai); } } }