コード例 #1
0
int main(int argc, char* argv[])
{
	if (argc != 2)
	{
		std::cout << "USAGE: <Interfaces|Callbacks>" << std::endl;
		return EXIT_SUCCESS;
	}

	auto c = std::make_shared<int>(3);
	const int ciclesB = 1000000 * 5;
	const int ciclesC = 1000000 * 5;

	if (std::string("interfaces") == argv[1])
	{
		auto listener = std::make_shared<ConcreteListener>();
		auto generator = std::make_shared<AsyncGenerator>(listener);

		Timer.start();

		for (int i = 0; i < ciclesB; ++i)
		{
			generator->makeB(1);
		}
		for (int i = 0; i < ciclesC; ++i)
		{
			generator->makeC(c);
		}
		generator->makeB(0);

		Mutex.lock();
	}
	else if (std::string("callbacks") == argv[1])
	{
		auto generator = std::make_shared<CallbackGenerator>(ReceiverB, ReceiverC);

		Timer.start();

		for (int i = 0; i < ciclesB; ++i)
		{
			generator->makeB(1);
		}
		for (int i = 0; i < ciclesC; ++i)
		{
			generator->makeC(c);
		}
		generator->makeB(0);

		Mutex.lock();
	}

	std::cout << "ElapsedTime: " << boost::timer::format(ElapsedTime) << std::endl;
	std::cin.get();
	return EXIT_SUCCESS;
}
コード例 #2
0
void doTurn(Unit *u[NUM]) {
    Unit tu;
    int m;
    SitRep sitRep;
    Action a;
    int hits;
    int lr, lc;
    int i, j, t, next[NUM];

    //come up witha a randome ordering of pieces for this turn
    for (i = 0; i < NUM; ++i)next[i] = i;
    for (i = NUM - 1; i > 0; --i) {
        j = rand() % i;
        t = next[j];
        next[j] = next[i];
        next[i] = t;
    }

    for (i = 0; i < NUM; ++i) {
        m = next[i];
        if (oneLeft(u))return;;
        if (u[m] && !u[m]->getDead()) {
            makeB(u);
            sitRep = makeSitRep(u, m);
            int tseed = rand();  //Save the current state of rand...
            tu = *u[m];
            a = u[m]->Recommendation(sitRep);
            checkNoMods(u[m], tu);
            srand(tseed);  //...and reset it.
            switch (a.action) {
                case turn:
                    u[m]->Turn(a.dirToFace);
                    break;
                case moveFwd:
                    lr = u[m]->getR();
                    lc = u[m]->getC();
                    if (!clear(u, m, a.maxDist))break;
                    if (u[m]->getRank() == archer || u[m]->getRank() == infantry)
                        a.maxDist = 1;
                    u[m]->Move(clear(u, m, a.maxDist));
                    break;
                case attack:
                    hits = u[m]->Attack();
                    if (u[m]->getRank() == archer)
                        arrowSuffer(u, m, a.archerRow, a.archerCol, hits);
                    else
                        makeSuffer(u, m, hits);
                    break;
                case nothing:
                    break;
            }
        }
    }
    return;
}
コード例 #3
0
ファイル: exceptions.cpp プロジェクト: AlexDenisov/clang
 A *i() {
   // CHECK:    define [[A:%.*]]* @_ZN5test11iEv()
   // CHECK:      [[X:%.*]] = alloca [[A]]*, align 8
   // CHECK:      [[ACTIVE:%.*]] = alloca i1
   // CHECK:      [[NEW:%.*]] = call i8* @_Znwm(i64 8)
   // CHECK-NEXT: store i1 true, i1* [[ACTIVE]] 
   // CHECK-NEXT: [[CAST:%.*]] = bitcast i8* [[NEW]] to [[A]]*
   // CHECK-NEXT: invoke void @_ZN5test15makeBEv([[B:%.*]]* sret [[T0:%.*]])
   // CHECK:      [[T1:%.*]] = invoke i32 @_ZN5test11BcviEv([[B]]* [[T0]])
   // CHECK:      invoke void @_ZN5test11AC1Ei([[A]]* [[CAST]], i32 [[T1]])
   // CHECK:      store i1 false, i1* [[ACTIVE]]
   // CHECK-NEXT: store [[A]]* [[CAST]], [[A]]** [[X]], align 8
   // CHECK:      invoke void @_ZN5test15makeBEv([[B:%.*]]* sret [[T2:%.*]])
   // CHECK:      [[RET:%.*]] = load [[A]]*, [[A]]** [[X]], align 8
   // CHECK:      invoke void @_ZN5test11BD1Ev([[B]]* [[T2]])
   // CHECK:      invoke void @_ZN5test11BD1Ev([[B]]* [[T0]])
   // CHECK:      ret [[A]]* [[RET]]
   // CHECK:      [[ISACTIVE:%.*]] = load i1, i1* [[ACTIVE]]
   // CHECK-NEXT: br i1 [[ISACTIVE]]
   // CHECK:      call void @_ZdlPv(i8* [[NEW]])
   A *x;
   return (x = new A(makeB()), makeB(), x);
 }
コード例 #4
0
ファイル: kfilter_impl.hpp プロジェクト: Exadios/g-meter
  void KFilter<T, OQ, OVR, DBG>::makeProcess() {

    // x = Ax + Bu + Ww    n.1 = n.n * n.1 + n.nu * nu.1
    makeB();

    K_UINT_32 i, j;
    x__.resize(EKFilter<T, OQ, OVR, DBG>::n);

    for (i = 0; i < EKFilter<T, OQ, OVR, DBG>::n; ++i) {

      x__(i) = T(0.0);

      for (j = 0; j < EKFilter<T, OQ, OVR, DBG>::n; ++j)
        x__(i) += EKFilter<T, OQ, OVR, DBG>::A(i,j) * EKFilter<T, OQ, OVR, DBG>::x(j);

      for (j = 0; j < EKFilter<T, OQ, OVR, DBG>::nu; ++j)
        x__(i) += B(i,j) * EKFilter<T, OQ, OVR, DBG>::u(j);

    }

    EKFilter<T, OQ, OVR, DBG>::x.swap(x__);

  }
コード例 #5
0
ファイル: kfilter_impl.hpp プロジェクト: shijinqiao/KFilter
  void KFilter<T, BEG, OQ, OVR, DBG>::makeProcess() {

    // x = Ax + Bu + Ww    n.1 = n.n * n.1 + n.nu * nu.1
    makeB();

    K_UINT_32 i, j;
    x__.resize(this->n);

    for (i = BEG; i < this->n + BEG; ++i) {

      x__(i) = T(0.0);

      for (j = BEG; j < this->n + BEG; ++j)
        x__(i) += this->A(i,j) * this->x(j);

      for (j = BEG; j < this->nu + BEG; ++j)
        x__(i) += B(i,j) * this->u(j);

    }

    this->x.swap(x__);

  }
コード例 #6
0
ファイル: exceptions.cpp プロジェクト: siwuxian/cheerp-clang
 A *h() {
   return new A(makeB(), makeB());
 }
コード例 #7
0
ファイル: exceptions.cpp プロジェクト: siwuxian/cheerp-clang
 A *g() {
   return new A(makeB());
 }
コード例 #8
0
ファイル: exceptions.cpp プロジェクト: siwuxian/cheerp-clang
 A *f() {
   return new A(makeB().x);
 }