示例#1
0
thread_return_t CALLING_CONVENTION queue_test_internal_thread_simple_dequeuer( void *queue_test_dequeuing_state )
{
  struct queue_test_dequeuing_state
    *qtds;

  lfds611_atom_t
    *prev_user_data,
    *user_data;

  assert( queue_test_dequeuing_state != NULL );

  qtds = (struct queue_test_dequeuing_state *) queue_test_dequeuing_state;

  lfds611_queue_use( qtds->qs );

  lfds611_queue_dequeue( qtds->qs, (void *) &prev_user_data );

  while( lfds611_queue_dequeue(qtds->qs, (void *) &user_data) )
  {
    if( user_data <= prev_user_data )
      qtds->error_flag = RAISED;

    prev_user_data = user_data;
  }

  return( (thread_return_t) EXIT_SUCCESS );
}
//-----------------------------------------------------------------------------
int
pdcp_netlink_dequeue_element(
    const protocol_ctxt_t* const  ctxt_pP,
    struct pdcp_netlink_element_s** data_ppP
)
//-----------------------------------------------------------------------------
{
    int ret = 0;

    if (ctxt_pP->enb_flag) {
        ret = lfds611_queue_dequeue(pdcp_netlink_queue_enb[ctxt_pP->module_id], (void**)data_ppP);

        if (ret != 0) {
            LOG_D(PDCP,"[NETLINK]De-queueing packet for eNB instance %d\n", ctxt_pP->module_id);
        }
    } else {
        ret = lfds611_queue_dequeue(pdcp_netlink_queue_ue[ctxt_pP->module_id], (void**)data_ppP);

        if (ret != 0) {
            LOG_D(PDCP, "[NETLINK]De-queueing packet for UE instance %d\n", ctxt_pP->module_id);
        }
    }

    return ret;
}
示例#3
0
文件: lkfq.c 项目: BillTheBest/laguna
lkfqRead(lkfq_tc_t * pQ)
{
    lkfq_data_p  _pD = NULL;

    CCURASSERT(pQ);

    if(pQ)
    {
#if TRANSC_LKFQ_LOCKCK
        /* pQ->tQAlloc Mutex here */
        if(pQ->bLock)
            pthread_mutex_lock(&(pQ->tQAlloc.tLock));
#endif /* TRANSC_LKFQ_LOCKCK */
        if(MISC_LKFQ_STS_FAIL ==
                lfds611_queue_dequeue( pQ->tQAlloc.pRbQs, &_pD ))
        {
            _pD = NULL;
        }
#if TRANSC_LKFQ_LOCKCK
        /* pQ->tQAlloc Mutex here */
        if(pQ->bLock)
            pthread_mutex_unlock(&(pQ->tQAlloc.tLock));
#endif /* TRANSC_LKFQ_LOCKCK */
    }

    return _pD;
}
示例#4
0
文件: lkfq.c 项目: BillTheBest/laguna
lkfqFlushFreeList(lkfq_tc_t * pQ)
{
    lkfq_data_p  _pD;
    BOOL         _bElemAvail = TRUE;

    CCURASSERT(pQ);

    if(pQ)
    {
#if TRANSC_LKFQ_LOCKCK
        /* pQ->tQFree Mutex here */
        if(pQ->bLock)
            pthread_mutex_lock(&(pQ->tQFree.tLock));
#endif /* TRANSC_LKFQ_LOCKCK */
        while(_bElemAvail)
        {
            if(MISC_LKFQ_STS_FAIL ==
                    lfds611_queue_dequeue( pQ->tQFree.pRbQs, &_pD ))
            {
                _bElemAvail = FALSE;
            }
            else
            {
                cp_mempool_free(pQ->pMp, _pD);
                _bElemAvail = TRUE;
            }
        }
#if TRANSC_LKFQ_LOCKCK
        /* pQ->tQFree Mutex here */
        if(pQ->bLock)
            pthread_mutex_unlock(&(pQ->tQFree.tLock));
#endif /* TRANSC_LKFQ_LOCKCK */
    }
}
示例#5
0
thread_return_t CALLING_CONVENTION queue_test_internal_thread_rapid_enqueuer_and_dequeuer( void *queue_test_rapid_enqueuing_and_dequeuing_state )
{
  struct queue_test_rapid_enqueuing_and_dequeuing_state
    *qtreds;

  time_t
    start_time;

  lfds611_atom_t
    user_data;

  assert( queue_test_rapid_enqueuing_and_dequeuing_state != NULL );

  qtreds = (struct queue_test_rapid_enqueuing_and_dequeuing_state *) queue_test_rapid_enqueuing_and_dequeuing_state;

  lfds611_queue_use( qtreds->qs );

  time( &start_time );

  while( time(NULL) < start_time + 10 )
  {
    lfds611_queue_enqueue( qtreds->qs, (void *) (qtreds->counter++) );
    lfds611_queue_dequeue( qtreds->qs, (void *) &user_data );
  }

  return( (thread_return_t) EXIT_SUCCESS );
}
示例#6
0
BasePacket* SFTCPNetwork::GetRPCResult()
{
	BasePacket* pPacket = NULL;

	lfds611_queue_dequeue(m_pQueue, (void**)&pPacket);
	
	return pPacket;
}
struct lfds611_freelist_element *lfds611_ringbuffer_get_read_element( struct lfds611_ringbuffer_state *rs, struct lfds611_freelist_element **fe )
{
  assert( rs != NULL );
  assert( fe != NULL );

  lfds611_queue_dequeue( rs->qs, (void **) fe );

  return( *fe );
}
示例#8
0
BOOL P2PManager::Update()
{
	P2PData* pP2PData = NULL;

	while (lfds611_queue_dequeue(m_pQueue, (void**)&pP2PData))
	{
		m_pUDPCallback->HandleUDPNetworkMessage(pP2PData->GetData(), pP2PData->GetDataSize());
		delete pP2PData;
		pP2PData = NULL;
	}

	return TRUE;
}
示例#9
0
thread_return_t CALLING_CONVENTION queue_test_internal_thread_enqueuer_and_dequeuer( void *queue_test_enqueuing_and_dequeuing_state )
{
  struct queue_test_enqueuing_and_dequeuing_state
    *qteds;

  time_t
    start_time;

  lfds611_atom_t
    thread,
    count,
    user_data;

  assert( queue_test_enqueuing_and_dequeuing_state != NULL );

  qteds = (struct queue_test_enqueuing_and_dequeuing_state *) queue_test_enqueuing_and_dequeuing_state;

  lfds611_queue_use( qteds->qs );

  time( &start_time );

  while( time(NULL) < start_time + 10 )
  {
    lfds611_queue_enqueue( qteds->qs, (void *) (qteds->counter++) );
    lfds611_queue_dequeue( qteds->qs, (void *) &user_data );

    thread = user_data >> (sizeof(lfds611_atom_t)*8-8);
    count = (user_data << 8) >> 8;

    if( thread >= qteds->cpu_count )
      qteds->error_flag = RAISED;
    else
    {
      if( count < qteds->per_thread_counters[thread] )
        qteds->error_flag = RAISED;

      if( count >= qteds->per_thread_counters[thread] )
        qteds->per_thread_counters[thread] = count+1;
    }
  }

  return( (thread_return_t) EXIT_SUCCESS );
}
示例#10
0
/** @brief Receive a message from other module or a timeout event. 
 *  @param[in] rcvMod Which module to receive message.
 *  @param[in] ppMsg Would return the pointer of received message. 
 *  @return 0: success
 ****************************************************************************/
int
FwkMsg::recv(tModId rcvMod, tMsg **ppMsg)
{
    int epoll_ret = 0;
    int epoll_timeout = -1;//$ -1 causes the epoll_wait to wait indefinitely.
    FwkTask *pTask = stFwkCtx.aTasks[rcvMod];
    
    *ppMsg = NULL;

    do 
    {
        epoll_ret = epoll_wait(pTask->epoll_fd, pTask->events, pTask->nb_events, epoll_timeout);
    } while (epoll_ret < 0 && errno == EINTR);

    if (epoll_ret < 0) 
    {
        AssertFatal(0, "epoll_wait failed for task %d: %s!\n", rcvMod, strerror(errno));
    }

    pTask->epoll_nb_events = epoll_ret;

    {
        tMsg *pMsg = NULL;
        eventfd_t  sem_counter;
        ssize_t    read_ret;
        //$ Read will always return 1 
        read_ret = read(pTask->task_event_fd, &sem_counter, sizeof (sem_counter));
        AssertFatal(read_ret == sizeof(sem_counter), "Read from task message FD (%d) failed (%d/%d)!\n", rcvMod, (int)read_ret, (int)sizeof (sem_counter));
        if (lfds611_queue_dequeue(pTask->msgQ, (void **)&pMsg) == 0) 
        {
            //$ No element in list -> this should not happen 
            AssertFatal(0, "No message in queue for task %d while there are %d events and some for the messages queue!\n", rcvMod, epoll_ret);
        }

        AssertFatal(pMsg != NULL, "Message from message queue is NULL!\n");
        *ppMsg = pMsg;
      
        //$ Mark that the event has been processed 
        pTask->events[0].events &= ~EPOLLIN;            
    }
    return 0;
}
示例#11
0
//------------------------------------------------------------------------------
void
msc_flush_messages (
  void)
//------------------------------------------------------------------------------
{
  int                                     rv;
  msc_queue_item_t                       *item_p = NULL;

  while ((rv = lfds611_queue_dequeue (g_msc_message_queue_p, (void **)&item_p)) == 1) {
    if (NULL != item_p->message_str) {
      fputs (item_p->message_str, g_msc_fd);
      // TODO BIN DATA
      rv = lfds611_stack_guaranteed_push (g_msc_memory_stack_p, item_p->message_str);
    }
    // TODO FREE BIN DATA
    free (item_p);
  }

  fflush (g_msc_fd);
}
示例#12
0
void queue_test_rapid_enqueuing_and_dequeuing( void )
{
  unsigned int
    loop,
    cpu_count;

  thread_state_t
    *thread_handles;

  struct lfds611_queue_state
    *qs;

  struct queue_test_rapid_enqueuing_and_dequeuing_state
    *qtreds;

  struct lfds611_validation_info
    vi = { 50000, 50000 };

  lfds611_atom_t
    user_data,
    thread,
    count,
    *per_thread_counters;

  enum lfds611_data_structure_validity
    dvs[2];

  internal_display_test_name( "Rapid enqueuing and dequeuing (10 seconds)" );

  cpu_count = abstraction_cpu_count();

  lfds611_queue_new( &qs, 100000 );

  for( loop = 0 ; loop < 50000 ; loop++ )
    lfds611_queue_enqueue( qs, NULL );

  qtreds = malloc( sizeof(struct queue_test_rapid_enqueuing_and_dequeuing_state) * cpu_count );

  for( loop = 0 ; loop < cpu_count ; loop++ )
  {
    (qtreds+loop)->qs = qs;
    (qtreds+loop)->counter = (lfds611_atom_t) loop << (sizeof(lfds611_atom_t)*8-8);
  }

  thread_handles = malloc( sizeof(thread_state_t) * cpu_count );

  for( loop = 0 ; loop < cpu_count ; loop++ )
    abstraction_thread_start( &thread_handles[loop], loop, queue_test_internal_thread_rapid_enqueuer_and_dequeuer, qtreds+loop );

  for( loop = 0 ; loop < cpu_count ; loop++ )
    abstraction_thread_wait( thread_handles[loop] );

  free( thread_handles );

  lfds611_queue_query( qs, LFDS611_QUEUE_QUERY_VALIDATE, (void *) &vi, (void *) dvs );

  // TRD : now check results
  per_thread_counters = malloc( sizeof(lfds611_atom_t) * cpu_count );

  for( loop = 0 ; loop < cpu_count ; loop++ )
    *(per_thread_counters+loop) = 0;

  while( dvs[0] == LFDS611_VALIDITY_VALID and dvs[1] == LFDS611_VALIDITY_VALID and lfds611_queue_dequeue(qs, (void *) &user_data) )
  {
    thread = user_data >> (sizeof(lfds611_atom_t)*8-8);
    count = (user_data << 8) >> 8;

    if( thread >= cpu_count )
    {
      dvs[0] = LFDS611_VALIDITY_INVALID_TEST_DATA;
      break;
    }

    if( per_thread_counters[thread] == 0 )
      per_thread_counters[thread] = count;

    if( count < per_thread_counters[thread] )
      dvs[0] = LFDS611_VALIDITY_INVALID_ADDITIONAL_ELEMENTS;

    if( count >= per_thread_counters[thread] )
      per_thread_counters[thread] = count+1;
  }

  free( per_thread_counters );

  free( qtreds );

  lfds611_queue_delete( qs, NULL, NULL );

  internal_display_test_result( 2, "queue", dvs[0], "queue freelist", dvs[1] );

  return;
}
示例#13
0
void queue_test_enqueuing( void )
{
  unsigned int
    loop,
    cpu_count;

  thread_state_t
    *thread_handles;

  struct lfds611_queue_state
    *qs;

  struct queue_test_enqueuing_state
    *qtes;

  lfds611_atom_t
    user_data,
    thread,
    count,
    *per_thread_counters;

  struct lfds611_validation_info
    vi = { 1000000, 1000000 };

  enum lfds611_data_structure_validity
    dvs[2];

  /* TRD : create an empty queue with 1,000,000 elements in its freelist
           then run one thread per CPU
           where each thread busy-works, enqueuing elements (until there are no more elements)
           each element's void pointer of user data is (thread number | element number)
           where element_number is a thread-local counter starting at 0
           where the thread_number occupies the top byte

           when we're done, we check that all the elements are present
           and increment on a per-thread basis
  */

  internal_display_test_name( "Enqueuing" );

  cpu_count = abstraction_cpu_count();

  lfds611_queue_new( &qs, 1000000 );

  qtes = malloc( sizeof(struct queue_test_enqueuing_state) * cpu_count );

  for( loop = 0 ; loop < cpu_count ; loop++ )
  {
    (qtes+loop)->qs = qs;
    (qtes+loop)->counter = (lfds611_atom_t) loop << (sizeof(lfds611_atom_t)*8-8);
  }

  thread_handles = malloc( sizeof(thread_state_t) * cpu_count );

  for( loop = 0 ; loop < cpu_count ; loop++ )
    abstraction_thread_start( &thread_handles[loop], loop, queue_test_internal_thread_simple_enqueuer, qtes+loop );

  for( loop = 0 ; loop < cpu_count ; loop++ )
    abstraction_thread_wait( thread_handles[loop] );

  free( thread_handles );

  free( qtes );

  /* TRD : first, validate the queue

           then dequeue
           we expect to find element numbers increment on a per thread basis
  */

  lfds611_queue_query( qs, LFDS611_QUEUE_QUERY_VALIDATE, &vi, dvs );

  per_thread_counters = malloc( sizeof(lfds611_atom_t) * cpu_count );

  for( loop = 0 ; loop < cpu_count ; loop++ )
    *(per_thread_counters+loop) = 0;

  while( dvs[0] == LFDS611_VALIDITY_VALID and dvs[1] == LFDS611_VALIDITY_VALID and lfds611_queue_dequeue(qs, (void *) &user_data) )
  {
    thread = user_data >> (sizeof(lfds611_atom_t)*8-8);
    count = (user_data << 8) >> 8;

    if( thread >= cpu_count )
    {
      dvs[0] = LFDS611_VALIDITY_INVALID_TEST_DATA;
      break;
    }

    if( count < per_thread_counters[thread] )
      dvs[0] = LFDS611_VALIDITY_INVALID_ADDITIONAL_ELEMENTS;

    if( count > per_thread_counters[thread] )
      dvs[0] = LFDS611_VALIDITY_INVALID_MISSING_ELEMENTS;

    if( count == per_thread_counters[thread] )
      per_thread_counters[thread]++;
  }

  free( per_thread_counters );

  lfds611_queue_delete( qs, NULL, NULL );

  internal_display_test_result( 2, "queue", dvs[0], "queue freelist", dvs[1] );

  return;
}