Example #1
0
void TRI_ReleaseConnectionStatistics (TRI_connection_statistics_t* statistics) {
  if (statistics == nullptr) {
    return;
  }
  
  {
    MUTEX_LOCKER(ConnectionDataLock);

    if (statistics->_http) {
      if (statistics->_connStart != 0.0) {
        if (statistics->_connEnd == 0.0) {
          TRI_HttpConnectionsStatistics.incCounter();
        }
        else {
          TRI_HttpConnectionsStatistics.decCounter();

          double totalTime = statistics->_connEnd - statistics->_connStart;
          TRI_ConnectionTimeDistributionStatistics->addFigure(totalTime);
        }
      }
    }
  }

  // clear statistics
  statistics->reset();

  // put statistics item back onto the freelist
#ifdef TRI_ENABLE_MAINTAINER_MODE  
  bool ok = ConnectionFreeList.push(statistics);
  TRI_ASSERT(ok);
#else
  ConnectionFreeList.push(statistics);
#endif
}
Example #2
0
static void ProcessRequestStatistics (TRI_request_statistics_t* statistics) {
  {
    MUTEX_LOCKER(RequestDataLock);

    TRI_TotalRequestsStatistics.incCounter();

    if (statistics->_async) {
      TRI_AsyncRequestsStatistics.incCounter();
    }

    TRI_MethodRequestsStatistics[(int) statistics->_requestType].incCounter();

    // check that the request was completely received and transmitted
    if (statistics->_readStart != 0.0 && statistics->_writeEnd != 0.0) {
      double totalTime = statistics->_writeEnd - statistics->_readStart;
      TRI_TotalTimeDistributionStatistics->addFigure(totalTime);

      double requestTime = statistics->_requestEnd - statistics->_requestStart;
      TRI_RequestTimeDistributionStatistics->addFigure(requestTime);

      double queueTime = 0.0;

      if (statistics->_queueStart != 0.0 && statistics->_queueEnd != 0.0) {
        queueTime = statistics->_queueEnd - statistics->_queueStart;
        TRI_QueueTimeDistributionStatistics->addFigure(queueTime);
      }

      double ioTime = totalTime - requestTime - queueTime;

      if (ioTime >= 0.0) {
        TRI_IoTimeDistributionStatistics->addFigure(ioTime);
      }

      TRI_BytesSentDistributionStatistics->addFigure(statistics->_sentBytes);
      TRI_BytesReceivedDistributionStatistics->addFigure(statistics->_receivedBytes);
    }
  }

  // clear statistics
  statistics->reset(); 

  // put statistics item back onto the freelist
#ifdef TRI_ENABLE_MAINTAINER_MODE
  bool ok = RequestFreeList.push(statistics);
  TRI_ASSERT(ok);
#else
  RequestFreeList.push(statistics);
#endif
}
Example #3
0
bool ElmoDriver::iPA(float degree)
{
	static TPCANMsg message;

	message.ID = 6*128+id;
	message.LEN = 8;

    int temp = (int) (2000.0*degree/180.0*gear_m);
	//cout << "angle = " << temp << endl; 
	BYTE value[4];

	memcpy(value, &temp, sizeof(int));

	message.DATA[0] = 'O';
	message.DATA[1] = 'V';

	message.DATA[2] = 0x13;
	message.DATA[3] = 0;

	for(int i=0; i<4; i++)
		message.DATA[4+i] = value[i];

	return CAN_Write_Queue.push(message);
 
}
Example #4
0
bool ElmoDriver::TCEqualMinusOne()
{

	static TPCANMsg message;

	message.ID = 6*128+id;
	message.LEN = 8;

	float temp = -0.5;

	BYTE current[4];

	memcpy(current, &temp, sizeof(float));

	message.DATA[0] = 'T';
	message.DATA[1] = 'C';
	message.DATA[2] = 0x0;
	message.DATA[3] = 128;

	//for(int i=0; i<3; i++)
	//	message.DATA[4+i] = current[i];

	message.DATA[4] = current[0];
	message.DATA[5] = current[1];
	message.DATA[6] = current[2];
	message.DATA[7] = current[3];

	return CAN_Write_Queue.push(message);

}
Example #5
0
bool ElmoDriver::SetIPMode()
{
	static TPCANMsg message;
	
	message.ID = 6*128+id;
	message.LEN = 8;

	message.DATA[0] = 'O';
	message.DATA[1] = 'F';
	message.DATA[2] = 0x07;

	for(int i=3; i<8; i++)
		message.DATA[i] = (i == 4 ? 0x07 : 0);
	/*
	CAN_Write_Queue.push(message);

	message.DATA[0] = 'O';
	message.DATA[1] = 'V';
	message.DATA[2] = 0x17;

	for(int i=3; i<8; i++)
		message.DATA[i] = (i == 4 ? 0x0A : 0);
	*/
	return CAN_Write_Queue.push(message); 
}
Example #6
0
bool ElmoDriver::GetCurrent()
{

    static TPCANMsg message;
    message.ID = 6*128+id;
    message.LEN = 4;
    message.DATA[0] = 'I';
    message.DATA[1] = 'Q';
    message.DATA[2] = 0;
    message.DATA[3] = 0;
    return CAN_Write_Queue.push(message);
/*
    int temppos = 0x00;
if (data1[0]=='I' && data1[1]=='Q')
    {
    temppos |= (data1[7] << 24);
    temppos |= (data1[6] << 16);
    temppos |= (data1[5] << 8);
    temppos |= (data1[4]);
    val= *(float *)&temppos;
    return 1;
    }
    val=temppos;
    return 0;
*/
}
Example #7
0
bool ElmoDriver::DC(float dcc, bool set)
{
	static TPCANMsg message;

	message.ID = 6*128+id;
    if (set == true)
    {
        message.LEN = 8;
        int temp = (int) (dcc*gear_m);
        BYTE value[4];
        memcpy(value, &temp, sizeof(int));
        for(int i=0; i<4; i++)
        message.DATA[4+i] = value[i];
    }
    else
    {
        message.LEN = 4;
    }




    message.DATA[0] = 'D';
    message.DATA[1] = 'C';

    message.DATA[2] = 0;
    message.DATA[3] = 0;



	return CAN_Write_Queue.push(message);
 
}
Example #8
0
 /* Push a work, it will run automatically. */
 bool push_work(work_t w) {
     if (w->c && work_queue.push(w)) {
         cv.notify_one();
         return true;
     }
     return false;
 }
Example #9
0
bool ElmoDriver::PA(int count)
{
//	float deg = (float) degree;
//	return PA(deg);

	static TPCANMsg message;

	message.ID = 6*128+id;
	message.LEN = 8;

	int temp = count;
	//cout << "angle = " << temp << endl; 
	BYTE value[4];

	memcpy(value, &temp, sizeof(int));

	message.DATA[0] = 'P';
	message.DATA[1] = 'A';

	message.DATA[2] = 0;
	message.DATA[3] = 0;

	for(int i=0; i<4; i++)
		message.DATA[4+i] = value[i];

	return CAN_Write_Queue.push(message);
}
Example #10
0
bool ElmoDriver::MotorOn()
{
	static TPCANMsg message;

	message.ID = 6*128+id;
	message.LEN = 8;

	message.DATA[0] = 'M';
	message.DATA[1] = 'O';

	//for(int i=2; i<8; i++)
	//	message.DATA[i] = (i == 4 ? 1 : 0);

	message.DATA[2] = 0;
	message.DATA[3] = 0;

	message.DATA[4] = 1;
	message.DATA[5] = 0;
	message.DATA[6] = 0;
	message.DATA[7] = 0;


	return CAN_Write_Queue.push(message);
	
}
Example #11
0
bool ElmoDriver::TCEqualZero()
{

	static TPCANMsg message;

	message.ID = 6*128+id;
	message.LEN = 8;

	float temp = 0.0;

	BYTE current[4];

	memcpy(current, &temp, sizeof(float));

	message.DATA[0] = 'T';
	message.DATA[1] = 'C';
	message.DATA[2] = 0x0;
	message.DATA[3] = 128;

	for(int i=0; i<3; i++)
		message.DATA[4+i] = current[i];

	return CAN_Write_Queue.push(message);

}
Example #12
0
void producer(void)
{
    for (int i = 0; i != iterations; ++i) {
        int value = ++producer_count;
        while (!queue.push(value))
            ;
    }
}
void producer(void)
{
    for(int i=0; i < iterations; ++i)
    {
        //原子计数---多线程不存在计数不上的情况
        int value = ++p_count;
        cout<<"+"<<endl;   //观察生产类型: 纯生产还是同时有消费者的情况
        while(!queue.push(value));
    }
}
Example #14
0
bool FT_Sensor::RequestData()
{
	static TPCANMsg message;
	message.ID = id;
	message.LEN = 1;
	message.DATA[0] = 0x02;

	if (!handle)
		return CAN_ERRMASK_ILLHANDLE;

	return CAN_Write_Queue.push(message);
}
Example #15
0
bool ElmoDriver::GotoOpMode()
{

	static TPCANMsg message;

	message.ID = 0;
	message.LEN = 2;

	message.DATA[0] = 1;
	message.DATA[1] = 0;

	return CAN_Write_Queue.push(message);
	
}
Example #16
0
bool ElmoDriver::ResetComm()
{

	static TPCANMsg message;

	message.ID = 0;
	message.LEN = 2;
	message.DATA[0] = 130;
	message.DATA[1] = id;

	return CAN_Write_Queue.push(message);
	

}
Example #17
0
 void allocate(void)
 {
     for (long i = 0; i != operations_per_thread; ++i)  {
         for (;;) {
             dummy * node = fl.template construct<true, bounded>();
             if (node) {
                 bool success = working_set.insert(node);
                 assert(success);
                 allocated_nodes.push(node);
                 break;
             }
         }
     }
 }
Example #18
0
void TRI_ReleaseRequestStatistics (TRI_request_statistics_t* statistics) {
  if (statistics == nullptr) {
    return;
  }
 
  if (! statistics->_ignore) {
#ifdef TRI_ENABLE_MAINTAINER_MODE
    bool ok = RequestFinishedList.push(statistics);
    TRI_ASSERT(ok);
#else
    RequestFinishedList.push(statistics);
#endif
  }
  else {
    statistics->reset(); 

#ifdef TRI_ENABLE_MAINTAINER_MODE
    bool ok = RequestFreeList.push(statistics);
    TRI_ASSERT(ok);
#else
    RequestFreeList.push(statistics);
#endif
  }
}
Example #19
0
bool ElmoDriver::UMEqualFive()
{
	static TPCANMsg message;
	
	message.ID = 6*128+id;
	message.LEN = 8;

	message.DATA[0] = 'U';
	message.DATA[1] = 'M';

	for(int i=2; i<8; i++)
		message.DATA[i] = (i == 4 ? 5 : 0);
    return CAN_Write_Queue.push(message);

}
Example #20
0
bool ElmoDriver::BG()
{
	static TPCANMsg message;

	message.ID = 6*128+id;
	message.LEN = 8;

	message.DATA[0] = 'B';
	message.DATA[1] = 'G';

	for(int i=2; i<4; i++)
		message.DATA[i] = (i==4 ? 1 : 0);

	return CAN_Write_Queue.push(message);
 
}
Example #21
0
bool ElmoDriver::CW()
{
	static TPCANMsg message;
	
	message.ID = 6*128+id;
	message.LEN = 8;

	message.DATA[0] = 'C';
	message.DATA[1] = 'W';

	for(int i=2; i<8; i++)
		message.DATA[i] = (i == 4 ? 0x1F : 0);

	return CAN_Write_Queue.push(message);

 
}
Example #22
0
//TPCANMsg message;
bool AbsoluteEncoder::RequestData()
{
	static TPCANMsg message;
	message.ID = id;
	message.LEN = 1;
	message.DATA[0] = 2;
//	for (int i=0; i<8; i++)
//		message.DATA[i] = (i==0 ? 0x02 : 0); 

	if (!handle)
		return CAN_ERRMASK_ILLHANDLE;

	//return CAN_Write(handle, &message);
	
	return CAN_Write_Queue.push(message);

}
Example #23
0
bool ElmoDriver::MotorOff()
{
	static TPCANMsg message;

	message.ID = 6*128+id;
	message.LEN = 8;

	message.DATA[0] = 'M';
	message.DATA[1] = 'O';

	for(int i=2; i<8; i++)
		message.DATA[i] = 0;


	return CAN_Write_Queue.push(message);
	
}
Example #24
0
bool ElmoDriver::ResetNode()
{
	static TPCANMsg message;

	message.ID = 0;
	message.LEN = 2;

	message.DATA[0] = 129;
	message.DATA[1] = id;


	cout << "in reset nod id = " << id << endl;


	return CAN_Write_Queue.push(message);

	
}
Example #25
0
bool ElmoDriver::ProfilePositionMode()
{
	static TPCANMsg message;
	
	message.ID = 6*128+id;
	message.LEN = 8;

	message.DATA[0] = 'O';
	message.DATA[1] = 'F';
	message.DATA[2] = 0x07;

	for(int i=3; i<8; i++)
		message.DATA[i] = (i == 4 ? 1 : 0);

	return CAN_Write_Queue.push(message);

 
}
Example #26
0
bool ElmoDriver::PA()
{
	static TPCANMsg message;

	message.ID = 6*128+id;
	message.LEN = 8;

	int temp = 2000;
	BYTE value[4];

	memcpy(value, &temp, sizeof(int));

	message.DATA[0] = 'P';
	message.DATA[1] = 'A';

	message.DATA[2] = 0;
	message.DATA[3] = 0;

	for(int i=0; i<4; i++)
		message.DATA[4+i] = value[i];

	return CAN_Write_Queue.push(message);
 
}
Example #27
0
bool ElmoDriver::PR(float degree)
{
	static TPCANMsg message;

	message.ID = 6*128+id;
	message.LEN = 8;

    int temp = (int) (2000.0*degree/180.0*gear_m);
	BYTE value[4];

	memcpy(value, &temp, sizeof(int));

	message.DATA[0] = 'P';
	message.DATA[1] = 'R';

	message.DATA[2] = 0;
	message.DATA[3] = 0;

	for(int i=0; i<4; i++)
		message.DATA[4+i] = value[i];

	return CAN_Write_Queue.push(message);
 
}
 void return_memory( void* c )
 {
     while ( !stack_.push(c) );
 }
Example #29
0
void TRI_InitializeStatistics () {
  TRI_ServerStatistics._startTime = TRI_microtime();

  // .............................................................................
  // sets up the statistics
  // .............................................................................

  TRI_ConnectionTimeDistributionVectorStatistics << (0.1) << (1.0) << (60.0);

  TRI_BytesSentDistributionVectorStatistics << (250) << (1000) << (2 * 1000) << (5 * 1000) << (10 * 1000);
  TRI_BytesReceivedDistributionVectorStatistics << (250) << (1000) << (2 * 1000) << (5 * 1000) << (10 * 1000);
  TRI_RequestTimeDistributionVectorStatistics << (0.01) << (0.05) << (0.1) << (0.2) << (0.5) << (1.0);

  TRI_ConnectionTimeDistributionStatistics = new StatisticsDistribution(TRI_ConnectionTimeDistributionVectorStatistics);
  TRI_TotalTimeDistributionStatistics = new StatisticsDistribution(TRI_RequestTimeDistributionVectorStatistics);
  TRI_RequestTimeDistributionStatistics = new StatisticsDistribution(TRI_RequestTimeDistributionVectorStatistics);
  TRI_QueueTimeDistributionStatistics = new StatisticsDistribution(TRI_RequestTimeDistributionVectorStatistics);
  TRI_IoTimeDistributionStatistics = new StatisticsDistribution(TRI_RequestTimeDistributionVectorStatistics);
  TRI_BytesSentDistributionStatistics = new StatisticsDistribution(TRI_BytesSentDistributionVectorStatistics);
  TRI_BytesReceivedDistributionStatistics = new StatisticsDistribution(TRI_BytesReceivedDistributionVectorStatistics);

  // initialize counters for all HTTP request types
  TRI_MethodRequestsStatistics.clear();

  for (int i = 0; i < ((int) triagens::rest::HttpRequest::HTTP_REQUEST_ILLEGAL) + 1; ++i) {
    StatisticsCounter c;
    TRI_MethodRequestsStatistics.emplace_back(c);
  }

  // .............................................................................
  // generate the request statistics queue
  // .............................................................................

  for (size_t i = 0; i < QUEUE_SIZE; ++i) {
    auto entry = new TRI_request_statistics_t;
#ifdef TRI_ENABLE_MAINTAINER_MODE    
    bool ok = RequestFreeList.push(entry);
    TRI_ASSERT(ok);
#else
    RequestFreeList.push(entry);
#endif    
  }

  // .............................................................................
  // generate the connection statistics queue
  // .............................................................................
  
  for (size_t i = 0; i < QUEUE_SIZE; ++i) {
    auto entry = new TRI_connection_statistics_t;
#ifdef TRI_ENABLE_MAINTAINER_MODE    
    bool ok = ConnectionFreeList.push(entry);
    TRI_ASSERT(ok);
#else
    ConnectionFreeList.push(entry);
#endif
  }

  // .............................................................................
  // use a separate thread for statistics
  // .............................................................................

  Shutdown = false;
  TRI_StartThread(&StatisticsThread, nullptr, "[statistics]", StatisticsQueueWorker, 0);
}