示例#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
}
示例#2
0
void consumer(void)
{
    int value;
    while (!done) {
        while (queue.pop(value))
            ++consumer_count;
    }

    while (queue.pop(value))
        ++consumer_count;
}
示例#3
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
}
示例#4
0
    /* 
     * The worker_thread blocks in this loop. 
     * As a member function, it must be binded with this ptr.
     */
    void worker_thread() {

        for (;;) {
            boost::mutex::scoped_lock lock(this->tp_mutex);
            cv.wait(lock);
            if (work_queue.empty())
                continue;
            work_t w;
            if (work_queue.pop(w))
                w->run();
            else
                thread_run_error();
        }

    }
示例#5
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);
	
}
示例#6
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);
 
}
示例#7
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); 
}
示例#8
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;
*/
}
示例#9
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);
 
}
示例#10
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);
}
示例#11
0
int main(int argc, char* argv[])
{
    using namespace std;
    cout << "boost::lockfree::queue is ";
    if (!queue.is_lock_free())
        cout << "not ";
    cout << "lockfree" << endl;
    
    boost::chrono::steady_clock::time_point start = boost::chrono::steady_clock::now();
    
    

    boost::thread_group producer_threads, consumer_threads;

    for (int i = 0; i != producer_thread_count; ++i)
        producer_threads.create_thread(producer);

    for (int i = 0; i != consumer_thread_count; ++i)
        consumer_threads.create_thread(consumer);

    producer_threads.join_all();
    done = true;

    consumer_threads.join_all();
    boost::chrono::duration<double> sec = boost::chrono::steady_clock::now() - start;
    cout << "f() took " << sec.count() << " seconds\n";

    cout << "produced " << producer_count << " objects." << endl;
    cout << "consumed " << consumer_count << " objects." << endl;
}
示例#12
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;
 }
示例#13
0
  // Must NOT be called without first calling wait()
  T get_withoutWaiting(){
    T ret = 0;
    
    R_ASSERT(queue.pop(ret));

    return ret;
  }
示例#14
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);

}
示例#15
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);

}
 void clear()
 {
     void * p;
     while ( stack_.unsynchronized_pop(p) )
     {
         znn_free(p);
     }
 }
示例#17
0
  // returns false if queue was full
  bool tryPut(T t){
    if (queue.bounded_push(t)) {
      ready.signal();
      return true;
    }

    return false;
  }
示例#18
0
void producer(void)
{
    for (int i = 0; i != iterations; ++i) {
        int value = ++producer_count;
        while (!queue.push(value))
            ;
    }
}
void consumer(void)
{
    int value;
    //当没有生产完毕,则边消费边生产
    while(!done)
    {
        while(queue.pop(value))
        {
            cout<<"-"<<endl;
            ++c_count;
        }
    }
    //如果生产完毕则消费
    while(queue.pop(value))
    {
        ++c_count;
    }
}
示例#20
0
TRI_connection_statistics_t* TRI_AcquireConnectionStatistics () {
  TRI_connection_statistics_t* statistics = nullptr;

  if (TRI_ENABLE_STATISTICS && ConnectionFreeList.pop(statistics)) {
    return statistics;
  }

  return nullptr;
}
示例#21
0
TRI_request_statistics_t* TRI_AcquireRequestStatistics () {
  TRI_request_statistics_t* statistics = nullptr;

  if (TRI_ENABLE_STATISTICS && RequestFreeList.pop(statistics)) {
    return statistics;
  }

  return nullptr;
}
示例#22
0
static void StatisticsQueueWorker (void* data) {
  while (! Shutdown && TRI_ENABLE_STATISTICS) {
    size_t count = ProcessAllRequestStatistics();

    if (count == 0) {
      usleep(100 * 1000);
    }
    else if (count < 10) {
      usleep(10 * 1000);
    }
    else if (count < 100) {
      usleep(1 * 1000);
    }
  }

  delete TRI_ConnectionTimeDistributionStatistics;
  delete TRI_TotalTimeDistributionStatistics;
  delete TRI_RequestTimeDistributionStatistics;
  delete TRI_QueueTimeDistributionStatistics;
  delete TRI_IoTimeDistributionStatistics;
  delete TRI_BytesSentDistributionStatistics;
  delete TRI_BytesReceivedDistributionStatistics;

  {
    TRI_request_statistics_t* entry = nullptr;
    while (RequestFreeList.pop(entry)) {
      delete entry;
    }
  }

  {
    TRI_request_statistics_t* entry = nullptr;
    while (RequestFinishedList.pop(entry)) {
      delete entry;
    }
  }

  {
    TRI_connection_statistics_t* entry = nullptr;
    while (ConnectionFreeList.pop(entry)) {
      delete entry;
    }
  }
}
void producer(void)
{
    for(int i=0; i < iterations; ++i)
    {
        //原子计数---多线程不存在计数不上的情况
        int value = ++p_count;
        cout<<"+"<<endl;   //观察生产类型: 纯生产还是同时有消费者的情况
        while(!queue.push(value));
    }
}
示例#24
0
文件: Device.cpp 项目: geniuskpj/usrc
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);
}
示例#25
0
    void deallocate(void)
    {
        for (;;) {
            dummy * node;
            if (allocated_nodes.pop(node)) {
                bool success = working_set.erase(node);
                assert(success);
                fl.template destruct<true>(node);
            }

            if (running.load() == false)
                break;
        }

        dummy * node;
        while (allocated_nodes.pop(node)) {
            bool success = working_set.erase(node);
            assert(success);
            fl.template destruct<true>(node);
        }
    }
示例#26
0
static size_t ProcessAllRequestStatistics () {
  TRI_request_statistics_t* statistics = nullptr;
  size_t count = 0;

  while (RequestFinishedList.pop(statistics)) {
    if (statistics != nullptr) {
      ProcessRequestStatistics(statistics);
      ++count;
    }
  }

  return count;
}
示例#27
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;
             }
         }
     }
 }
示例#28
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);
	

}
示例#29
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);
	
}
示例#30
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
  }
}