示例#1
0
void * transmitter (void * arg)
{

  /* Obtain multiple producer messages, combining into a single   */
  /* compound message for the receiver */

  unsigned int tstatus = 0, im, Retries = 0;
  T2R_MSG_TYPE t2r_msg = {0};
  msg_block_t p2t_msg;

  while (!ShutDown && !AllProduced) {
      t2r_msg.num_msgs = 0;
      /* pack the messages for transmission to the receiver */
      im = 0;
      while (im < TBLOCK_SIZE && !ShutDown && Retries < MAX_RETRY && !AllProduced) {
          tstatus = q_get (&p2tq, &p2t_msg, sizeof(p2t_msg), Q_TIMEOUT);
          if (0 == tstatus) {
              memcpy (&t2r_msg.messages[im], &p2t_msg, sizeof(p2t_msg));
              t2r_msg.num_msgs++;
              im++;
              Retries = 0;
          } else { /* Timed out.  */
              Retries++;
          }
      }
      tstatus = q_put (&t2rq, &t2r_msg, sizeof(t2r_msg), INFINITE);
      if (tstatus != 0) return NULL;
  }
  return NULL;
}
示例#2
0
void * receiver (void * arg)
{
  /* Obtain compound messages from the transmitter and unblock them       */
  /* and transmit to the designated consumer.                             */

  unsigned int tstatus = 0, im, ic, Retries = 0;
  T2R_MSG_TYPE t2r_msg;
  msg_block_t r2c_msg;

  while (!ShutDown && Retries < MAX_RETRY) {
      tstatus = q_get (&t2rq, &t2r_msg, sizeof(t2r_msg), Q_TIMEOUT);
      if (tstatus != 0) { /* Timeout - Have the producers shut down? */
          Retries++;
          continue;
      }
      Retries = 0;
      /* Distribute the packaged messages to the proper consumer */
      im = 0;
      while (im < t2r_msg.num_msgs) {
          memcpy (&r2c_msg, &t2r_msg.messages[im], sizeof(r2c_msg));
          ic = r2c_msg.destination; /* Destination consumer */
          tstatus = q_put (&r2cq_array[ic], &r2c_msg, sizeof(r2c_msg), INFINITE);
          if (0 == tstatus) im++;
      }
  }
  return NULL;
}
示例#3
0
文件: rfllcb.c 项目: bgtwoigu/1110
/*===========================================================================

FUNCTION  RFLLCB_INIT

DESCRIPTION
  Initializes the call back services.

DEPENDENCIES
  This function must be called before calling any other function
  exported by the call back services.
  
RETURN VALUE
  None

SIDE EFFECTS
  None

===========================================================================*/
void rfllcb_init( void )
{
  struct handler_struct *handler_ptr;
  rfllcb_struct_type *buf_ptr;
  int i;

  /* Initialize the free queue. */
  (void) q_init( &free_que );
  
  /* Initialize each element of handler array and free queue. */
  for ( i = 0; i < MAX_NUM_CB_SUPPORTED; i++ )
  {
    /* Initialize link for each item to be placed on free queue,
       initialize pointer to handler element, and place each item on
       free queue. */
    buf_ptr = &free_que_bufs[i];
    (void) q_link( buf_ptr, &buf_ptr->hdr.q_link );
    q_put( &free_que, &buf_ptr->hdr.q_link );
    handler_ptr = &handler[i];    
    buf_ptr->hdr.handler_ptr = (void*) handler_ptr;

    /* Initialize the fields of each handler element. */
    handler_ptr->cb_event_ptr = NULL;
    handler_ptr->current_event_ptr = NULL;
    clk_def( &handler_ptr->clock_cb );
    handler_ptr->clk_routine_ptr = clk_routine_ptrs[i];
  }
  
} /* rfllcb_init() */
示例#4
0
文件: dstask.c 项目: bgtwoigu/1110
void  dsi_task_init( void )
{
  uint8    i;                                                /* Loop index */

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/


  /*-------------------------------------------------------------------------
    Initialize the command queue and the free command queue, and link the
    command items onto the free command queue.
  -------------------------------------------------------------------------*/  
  (void)q_init( &dsi_cmd_q );
  (void)q_init( &dsi_cmd_free_q );

  for( i = 0; i < DSI_CMD_BUF_COUNT; i++ )
  {
    (void)q_link( &dsi_cmd_buf[i], &dsi_cmd_buf[i].hdr.link );
    q_put( &dsi_cmd_free_q, &dsi_cmd_buf[i].hdr.link );
  }

  /*-------------------------------------------------------------------------
    Define the watchdog timer, and start the timer.
  -------------------------------------------------------------------------*/
  rex_def_timer( &ds_dog_rpt_timer, &ds_tcb, DS_DOG_RPT_TIMER_SIG );
  (void)rex_set_timer( &ds_dog_rpt_timer, DOG_DS_RPT_TIME );

} /* dsi_task_init() */
示例#5
0
/* enqueue server reply for this connection's worker thread to send to client */
void
mock_server_reply_multi (request_t           *request,
                         mongoc_reply_flags_t flags,
                         const bson_t        *docs,
                         int                  n_docs,
                         int64_t              cursor_id)
{
   reply_t *reply;
   int i;

   BSON_ASSERT (request);

   reply = bson_malloc0 (sizeof (reply_t));

   reply->flags = flags;
   reply->n_docs = n_docs;
   reply->docs = bson_malloc0 (n_docs * sizeof (bson_t));

   for (i = 0; i < n_docs; i++) {
      bson_copy_to (&docs[i], &reply->docs[i]);
   }

   reply->cursor_id = cursor_id;
   reply->client_port = request_get_client_port (request);
   reply->request_opcode = (mongoc_opcode_t) request->request_rpc.header.opcode;
   reply->query_flags = (mongoc_query_flags_t) request->request_rpc.query.flags;
   reply->response_to = request->request_rpc.header.request_id;

   q_put (request->replies, reply);
}
示例#6
0
void * producer (void * arg)
{
  THARG * parg;
  unsigned int ithread, tstatus = 0;
  msg_block_t msg;

  parg = (THARG *)arg;
  ithread = parg->thread_number;

  while (parg->work_done < parg->work_goal && !ShutDown) {
      /* Periodically produce work units until the goal is satisfied */
      /* messages receive a source and destination address which are */
      /* the same in this case but could, in general, be different. */
      sleep (rand()/100000000);
      message_fill (&msg, ithread, ithread, parg->work_done);

      /* put the message in the queue - Use an infinite timeout to assure
       * that the message is inserted, even if consumers are delayed */
      tstatus = q_put (&p2tq, &msg, sizeof(msg), INFINITE);
      if (0 == tstatus) {
          parg->work_done++;
      }
  }

  return 0;
}
示例#7
0
文件: listener.c 项目: pepa65/weborf
int main(int argc, char *argv[]) {
    int s, s1; // Socket descriptors

    init_logger();
    init_thread_info();

    configuration_load(argc,argv);

    if (weborf_conf.is_inetd) inetd();

    print_start_disclaimer(argc,argv);

    s=net_create_server_socket();
    net_bind_and_listen(s);

    set_new_gid(weborf_conf.gid);
    set_new_uid(weborf_conf.uid);

    // init the queue for opened sockets
    if (q_init(&queue, MAXTHREAD + 1)!=0)
        exit(NOMEM);

    // Starts the 1st group of threads
    init_thread_attr();
    init_threads(INITIALTHREAD);
    init_thread_shaping();
    init_signals();

    // Infinite cycle, accept connections
    while (1) {
        s1=accept(s, NULL,NULL);

        if (s1 >= 0 && q_put(&queue, s1)!=0) { // Adds s1 to the queue
#ifdef REQUESTDBG
            syslog(LOG_ERR,"Not enough resources, dropping connection...");
#endif
            close(s1);
        }

        // Start new thread if needed
        if (thread_info.free <= LOWTHREAD && thread_info.free<MAXTHREAD) {
            // Need to start new thread
            if (thread_info.count + INITIALTHREAD < MAXTHREAD) {
                // Starts a group of threads
                init_threads(INITIALTHREAD);
            } else { // Can't start a group because the limit is close, starting less than a whole group
                init_threads(MAXTHREAD - thread_info.count);
            }
        }

    }
    return 0;

}
示例#8
0
static int do_band(struct spectgen_struct *handle, float *buf)
{
	int i;
	float *band;
	float *out;
	int out_num = handle->session->nbands;
	float * norm_table = handle->session->norm_table;
	float window_size = (float)handle->session->window_size;
	unsigned int *barkband_table = handle->barkband_table;

	if(!handle->barkband_table_inited)
	      return -1;

	out = band = (float *)calloc(out_num, sizeof(float));
	if(!out)
	      return -1;

	if(handle->session->method == CEPSTOGRAM) {
		band = handle->session->fft_in_post;
		out_num = (out_num - 1) * 2;
		memset(band, 0, sizeof(float) * out_num);
	}

	for(i = 1; i < handle->session->numfreqs; i++) {
		float real = buf[2 * i];
		float imag = buf[2 * i + 1];
		band[barkband_table[i]] += ((real * real) + (imag * imag));
	}

	for(i = 0; i < out_num; i++) {
		band[i] = SCALING_FACTOR * norm_table[i] * sqrt(band[i]) / window_size;
	}

	if(handle->session->method == CEPSTOGRAM) {
		for(i = 0; i < out_num; i++) {
			if(band[i] != 0)
				band[i] = log(band[i]);
		}
		fftwf_execute(handle->session->plan_post);
		buf = (float *)handle->session->fft_out_post;
		for(i = 0; i < handle->session->nbands; i++) {
			float real = buf[2 * i];
			float imag = buf[2 * i + 1];
			out[i] = SCALING_FACTOR * sqrt((real * real) + (imag * imag)) / (float)(out_num);
		}
	}

	q_put(&handle->queue, out);

	return 0;
}
示例#9
0
文件: listener.c 项目: pepa65/weborf
// This function, executed as a thread, terminates threads if there are too
// much free threads. It works polling the number of free threads and writing
// an order of termination if too much of them are free. Policies of this
// function (polling frequence and limit for free threads) are defined in
// options.h
void *t_shape(void *nulla) {

    for (;;) {
        sleep(THREADCONTROL);

        ///pthread_mutex_lock(&thread_info.mutex);
        if (thread_info.free > MAXFREETHREAD) {
            // Too many free threads, terminates one of them
            // Write the termination order to the queue, the thread who will read it, will terminate
            q_put(&queue,-1);
        }
        ///pthread_mutex_unlock(&thread_info.mutex);
    }
    return NULL; // make gcc happy
}
示例#10
0
文件: dstask.c 项目: bgtwoigu/1110
void  ds_put_cmd
(
  ds_cmd_type    *cmd_ptr                 /* Pointer to command to be sent */
)
{

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/


  /*-------------------------------------------------------------------------
    Put the command on the command queue, and set the command queue signal.
  -------------------------------------------------------------------------*/
  q_put( &dsi_cmd_q, &cmd_ptr->hdr.link );
  (void)rex_set_sigs( &ds_tcb, DS_CMD_Q_SIG );

} /* ds_put_cmd() */
示例#11
0
static int decoder_backend_push_internal(struct decoder_handle_struct *handle, 
			float *data, unsigned int len, long frate)
{
	struct decoder_buffer_type *buf;

	buf = (struct decoder_buffer_type *)malloc(sizeof(struct decoder_buffer_type));
	if((!buf))
	      return -1;
	buf->buffer = data;
	buf->len = len;
	buf->frate = frate;
	if(q_put(handle->queue, buf)) {
		free(buf);
		return -1;
	}
	return 0;
}
示例#12
0
文件: mccsrch.c 项目: bgtwoigu/1110
void mccsrch_init( void )
{
  word i;
    /* index through array of free buffers */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

  ( void )q_init( &mcc_srch_q );
  ( void )q_init( &mcc_srch_free_q);

  /* Fill mcc_srch_free_q */
  for( i=0; i< MCCSRCH_NUM_RPTS; i++ )
  {
    mccsrch_bufs[i].hdr.rpt_hdr.done_q_ptr = &mcc_srch_free_q;
    q_put( &mcc_srch_free_q, q_link( &mccsrch_bufs[i],
                                &mccsrch_bufs[i].hdr.rpt_hdr.link ));
  }

}/* mccsrch_init */
示例#13
0
文件: mccrxtx.c 项目: bgtwoigu/1110
void mccrxtx_init( void )
{
  word i;
    /* index through array of free buffers */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

  ( void )q_init( &mcc_rxtx_q ) ;
  ( void )q_init( &mcc_rxtx_ack_q );
  ( void )q_init( &mcc_rxtx_free_q );

  /* Fill mc_rxtx_free_q */
  for( i=0; i< MCCRXTX_NUM_BUFS; i++ )
  {
    mcc_rxtx_bufs[i].hdr.cmd_hdr.done_q_ptr = &mcc_rxtx_free_q;
    q_put( &mcc_rxtx_free_q, q_link( &mcc_rxtx_bufs[i],
                                  &mcc_rxtx_bufs[i].hdr.cmd_hdr.link) );
  }

}/* mccrxtx_init */
示例#14
0
文件: mccrxtx.c 项目: bgtwoigu/1110
void mccrxtx_cmd
(
  mccrxtx_cmd_type  *cmd_ptr   /* Pointer to MCCRXTX message buffer */
)
{
#ifdef FEATURE_MC_QUEUE_WATERMARK
  /* Usually RXTX takes a free buffer from MCC_RXTX_FREE_Q and  */
  /* put it onto mcc_rxtx_q by calling the function. It also    */
  /* takes a free buffer from MC_CMD_FREE_Q. So we need to      */
  /* update watermark for both these queues.                    */
  mc_update_watermark(MCWM_CMD_FREE_Q);
  mc_update_watermark(MCWM_RXTX_FREE_Q);
#endif

  /* Set the request status to busy. initialize and link the command  */
  /* onto the MC command queue, set a signal to the MC task and exit. */

  cmd_ptr->hdr.status = MCCRXTX_BUSY_S;
  (void) q_link(cmd_ptr, &cmd_ptr->hdr.cmd_hdr.link);
  q_put(&mcc_rxtx_q, &cmd_ptr->hdr.cmd_hdr.link);
  (void) rex_set_sigs( &mc_tcb, MCC_Q_SIG );

} /* mccrxtx_cmd */
示例#15
0
文件: rfllcb.c 项目: bgtwoigu/1110
/*===========================================================================

FUNCTION  GENERATE_CB_EVENTS  

DESCRIPTION
  Calls call back handler each time an event expires and registers
  next event with clock services.  Note: This function is called from
  interrupt level.

DEPENDENCIES
  None
  
RETURN VALUE
  None

SIDE EFFECTS
  Places event structure on free queue after the last event in event
  sequence has been generated.

===========================================================================*/
static void generate_cb_events
(
  struct handler_struct *handler_ptr
    /* Pointer to handler array element defining events to generate */
)
{
  rfllcb_struct_type *cb_event_ptr;

  /* Set pointer to call back event structure in handler. */
  cb_event_ptr = handler_ptr->cb_event_ptr;
  
  /* Call the call back handler for the current event. */
  cb_event_ptr->cb_handler( handler_ptr->current_event_ptr->event,
                            (void*) cb_event_ptr->user_data_ptr );

  /* Determine if there are more events to generate. */
  if ( cb_event_ptr->num_events > 0 )
  {
    /* More events need to be generated so increment pointer to the next
       event, decrement number of events remaining, and register clock
       services call back routine at time next event should occur. */
    --cb_event_ptr->num_events;
    ++handler_ptr->current_event_ptr;

    /* Regisiter clock services routine to be called at the next event
       time rounded up to the nearest millisecond. */
    clk_reg( &handler_ptr->clock_cb, handler_ptr->clk_routine_ptr,
             ((int)(handler_ptr->current_event_ptr->event) + 999) / 1000,
             0, FALSE );
  }
  else
  {
    /* Free the event buffer to indicate all events have been generated. */
    q_put( &free_que, &cb_event_ptr->hdr.q_link );
  }
  
} /* generate_cb_events() */
示例#16
0
static void *
worker_thread (void *data)
{
   worker_closure_t *closure = (worker_closure_t *) data;
   mock_server_t *server = closure->server;
   mongoc_stream_t *client_stream = closure->client_stream;
   mongoc_buffer_t buffer;
   mongoc_rpc_t *rpc = NULL;
   bool handled;
   bson_error_t error;
   int32_t msg_len;
   sync_queue_t *requests;
   sync_queue_t *replies;
   request_t *request;
   mongoc_array_t autoresponders;
   ssize_t i;
   autoresponder_handle_t handle;
   reply_t *reply;

#ifdef MONGOC_ENABLE_SSL
   bool ssl;
#endif

   ENTRY;

   /* queue of client replies sent over this worker's connection */
   replies = q_new ();

#ifdef MONGOC_ENABLE_SSL
   mongoc_mutex_lock (&server->mutex);
   ssl = server->ssl;
   mongoc_mutex_unlock (&server->mutex);

   if (ssl) {
      if (!mongoc_stream_tls_handshake_block (client_stream, "localhost",
                                              TIMEOUT, &error)) {
         mongoc_stream_close (client_stream);
         mongoc_stream_destroy (client_stream);
         RETURN (NULL);
      }
   }
#endif

   _mongoc_buffer_init (&buffer, NULL, 0, NULL, NULL);
   _mongoc_array_init (&autoresponders, sizeof (autoresponder_handle_t));

again:
   /* loop, checking for requests to receive or replies to send */
   bson_free (rpc);
   rpc = NULL;

   if (_mongoc_buffer_fill (&buffer, client_stream, 4, 10, &error) > 0) {
      assert (buffer.len >= 4);

      memcpy (&msg_len, buffer.data + buffer.off, 4);
      msg_len = BSON_UINT32_FROM_LE (msg_len);

      if (msg_len < 16) {
         MONGOC_WARNING ("No data");
         GOTO (failure);
      }

      if (_mongoc_buffer_fill (&buffer, client_stream, (size_t) msg_len, -1,
                               &error) == -1) {
         MONGOC_WARNING ("%s():%d: %s", BSON_FUNC, __LINE__, error.message);
         GOTO (failure);
      }

      assert (buffer.len >= (unsigned) msg_len);

      /* copies message from buffer */
      request = request_new (&buffer, msg_len, server, client_stream,
                             closure->port, replies);

      memmove (buffer.data, buffer.data + buffer.off + msg_len,
               buffer.len - msg_len);
      buffer.off = 0;
      buffer.len -= msg_len;

      mongoc_mutex_lock (&server->mutex);
      _mongoc_array_copy (&autoresponders, &server->autoresponders);
      mongoc_mutex_unlock (&server->mutex);

      test_suite_mock_server_log ("%5.2f  %hu -> %hu %s",
                                  mock_server_get_uptime_sec (server),
                                  closure->port, server->port, request->as_str);

      /* run responders most-recently-added-first */
      handled = false;

      for (i = server->autoresponders.len - 1; i >= 0; i--) {
         handle = _mongoc_array_index (&server->autoresponders,
                                       autoresponder_handle_t,
                                       i);

         if (handle.responder (request, handle.data)) {
            /* responder destroyed request and enqueued a reply in "replies" */
            handled = true;
            request = NULL;
            break;
         }
      }

      if (!handled) {
         /* pass to the main thread via the queue */
         requests = mock_server_get_queue (server);
         q_put (requests, (void *) request);
      }
   }

   if (_mock_server_stopping (server)) {
      GOTO (failure);
   }

   reply = q_get (replies, 10);
   if (reply) {
      _mock_server_reply_with_stream (server, reply, client_stream);
      _reply_destroy (reply);
   }

   if (_mock_server_stopping (server)) {
      GOTO (failure);
   }

   GOTO (again);

failure:
   _mongoc_array_destroy (&autoresponders);
   _mongoc_buffer_destroy (&buffer);

   mongoc_stream_close (client_stream);
   mongoc_stream_destroy (client_stream);
   bson_free (rpc);
   bson_free (closure);
   _mongoc_buffer_destroy (&buffer);

   while ((reply = q_get_nowait (replies))) {
      _reply_destroy (reply);
   }

   q_destroy (replies);

   RETURN (NULL);
}
示例#17
0
文件: dssicmp.c 项目: bgtwoigu/1110
/*===========================================================================
FUNCTION DSSICMP_PS_INPUT()

DESCRIPTION
  When an ICMP message is arrived, if it is NOT ECHO, INFO_RQST or 
  TIMESTAMP, the ICMP message will be handled by this fuction in the
  ps context. NOTE: the packet is not released in this should an 
  error occured. Instead DSS_ERROR is returned and the packet will 
  be freed by icmp_input(). 
                         
DEPENDENCIES
  None. 

RETURN VALUE
  DSS_SUCCESS on success; DSS_ERROR otherwise. 

SIDE EFFECTS
  None. 
  
===========================================================================*/
extern sint15 dssicmp_ps_input
( 
  struct icmp           *icmp_hdr,               /* ptr to the icmp header */
  dsm_item_type         *pkt_ptr,          /* ptr to the arriving ICMP pkt */
  ip4a                  *ip_src_addr                     /* source address */
)
{
  struct scb_s *  scb_ptr;                  /* Ptr to socket control block */
  int             index;                                     /* loop index */
  uint32          int_sav;       /* temporary variable for interrupt state */
  boolean         success;
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

  /*-------------------------------------------------------------------------
    Looping through the array of open ICMP socket control blocks and find
    whose type/code filed matches that of icmp_hdr. 
  -------------------------------------------------------------------------*/
  success = FALSE; 
  for (index = 0; index < DSS_MAX_ICMP_SOCKS; index++)
  {
    INTLOCK_SAV(int_sav);
    /*----------------------------------------------------------------------- 
      Only the sockets in OPEN state are being considered. 
    -----------------------------------------------------------------------*/
    scb_ptr = icmp_cb_array[index].scb_ptr;
    if(( scb_ptr != NULL) && (scb_ptr->socket_state == DSSOCKI_OPEN))
    {
      /*---------------------------------------------------------------------
        Check for matching type filed. NOTE: !! By default, code filed is
        not filtered. 
      ---------------------------------------------------------------------*/
      if ( icmp_cb_array[index].type == icmp_hdr->info.type ) 
      {
        /*--------------------------------------------------------------------
          Check if there's still memory in the dsm pool, this will prevent
          the receive queue on the icmp socket from becoming a bottleneck. 
        --------------------------------------------------------------------*/
        if (((DSM_LESS_THAN_FEW_FREE_ITEMS(DSM_DS_SMALL_ITEM_POOL) == TRUE) ||
            ((DSM_LESS_THAN_FEW_FREE_ITEMS(DSM_DS_LARGE_ITEM_POOL) == TRUE) )))
        {
          INTFREE_SAV(int_sav);
          MSG_HIGH("Low in memory: Discarding the ICMP packet", 0,0,0);
          break;
        }

        /*--------------------------------------------------------------------
          Push the IP source address, on the item ptr. This informationis 
          required by the application layer.
        --------------------------------------------------------------------*/
        if (dsm_pushdown( &pkt_ptr, 
                          ip_src_addr, 
                          4,
                          DSM_DS_SMALL_ITEM_POOL) == FALSE)
        {
          INTFREE_SAV(int_sav);
          ERR("Out of Memory!",0,0,0);
          break;
        }

        /*--------------------------------------------------------------------
          Put the packet on queue. 
        --------------------------------------------------------------------*/
#ifdef FEATURE_DSM_MEM_CHK
	pkt_ptr->tracer = DSM_ICMP_RCVQ;
#endif //FEATURE_DSM_MEM_CHK

	q_put( &(icmp_cb_array[index].rcvq), &(pkt_ptr->link) );
        
        /*-------------------------------------------------------------------
          There are bytes in the data payload, so indicate that a socket 
          event has occurred.  
        -------------------------------------------------------------------*/
        icmp_cb_array[index].scb_ptr->data_available = TRUE;
        INTFREE_SAV(int_sav);

        dssocki_socket_event_occurred( icmp_cb_array[index].scb_ptr, NULL );


        success = TRUE;
        break;
      } /* if (matched type) */
      else
      {
        INTFREE_SAV(int_sav);
      }
    } /* if (OPEN socket) */
    else
    {
      INTFREE_SAV(int_sav);
    }
  } /* for (all ICMP sockets) */

  /*-------------------------------------------------------------------------
    Process return value. 
  -------------------------------------------------------------------------*/
  if (success == 1) 
  {
    return (DSS_SUCCESS);
  }
  else
  {
    return (DSS_ERROR);
  }
}/* dssicmp_ps_input () */
示例#18
0
文件: dstask.c 项目: bgtwoigu/1110
/*===========================================================================

FUNCTION DSI_PROCESS_CMDS

DESCRIPTION
  This function de-queues commands from the Data Services Task's command
  queue, and dispataches commands to the appropriate entity for further
  processing, if necessary. Commands are de-queued until the command queue is
  empty.

DEPENDENCIES
  This function should be called when the DS_CMD_Q_SIG is set.

RETURN VALUE
  None

SIDE EFFECTS
  None

===========================================================================*/
void dsi_process_cmds( void )
{
  ds_cmd_type  *cmd_ptr;                             /* Pointer to command */

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/


  /*-------------------------------------------------------------------------
    Get commands from the command queue until the queue is empty. For each
    command received, dispatch the command to the appropriate sub-task.
  -------------------------------------------------------------------------*/
  while( (cmd_ptr = (ds_cmd_type *)q_get( &dsi_cmd_q )) != NULL )
  {

    switch( cmd_ptr->hdr.cmd_id )
    {
      /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3G Dsmgr Commands
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
      case DS_CM_CALL_END_CMD:
      case DS_CM_CALL_INCOM_CMD:
      case DS_CM_CALL_CONNECTED_CMD:
      case DS_CM_CALL_SETUP_CMD:
      case DS_CM_CALL_CONF_CMD:
#ifdef FEATURE_WCDMA
#error code not present
#endif /* FEATURE_WCDMA */
      case DS_TIMER_EXPIRED_CMD:
      case DS_COMPLETE_LL_CONNECT_CMD:
      case DS_COMPLETE_LL_DISCONNECT_CMD:
      case DS_INITIATE_CALL_CMD:
      case DS_RELEASE_CALL_CMD:
      case DS_CM_SS_SRV_CHG_CMD:
        ds3g_process_cmds( cmd_ptr );
        break;
      #ifndef FEATURE_DATA_STRIP_ATCOP
      /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        3G SIOLIB Commands
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
      case DS_RDM_OPEN_CMD:
      case DS_RDM_CLOSE_CMD:
      case DS_ENTER_ONLINE_CMD_TX_FLUSH_CMD:
      case DS_ENTER_ONLINE_CMD_NO_TX_FLUSH_CMD:
      case DS_ENTER_ONLINE_DATA_TX_FLUSH_CMD:
      case DS_ENTER_ONLINE_DATA_NO_TX_FLUSH_CMD:
      case DS_COMPLETE_ONLINE_CMD_SWITCH_CMD:
      case DS_COMPLETE_ONLINE_DATA_SWITCH_CMD:
        ds3g_siolib_process_cmds( cmd_ptr );
        break;
      #endif

#if ((defined(FEATURE_WCDMA) && defined(FEATURE_DATA_WCDMA_CS)) || \
     (defined(FEATURE_GSM) && defined(FEATURE_DATA_GCSD)))
#error code not present
#endif

      /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        ATCoP Commands
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
#ifndef FEATURE_DATA_STRIP_ATCOP
      case DS_AT_CM_CALL_CMD:
      case DS_AT_CM_CALL_INFO_CMD:
      case DS_AT_TIMER_EXPIRED_CMD:
      case DS_AT_STATUS_CMD:
#if defined(FEATURE_WCDMA) || defined(FEATURE_GSM)
#error code not present
#endif /* defined(FEATURE_WCDMA) || defined(FEATURE_GSM) */

#if defined(FEATURE_ETSI_PBM) || defined(FEATURE_DSAT_CDMA_PBM)
      case DS_AT_PBM_CB_CMD:
#endif /* defined(FEATURE_ETSI_PBM) || defined(FEATURE_DSAT_CDMA_PBM) */

#if defined(FEATURE_ETSI_SMS) || defined(FEATURE_CDMA_SMS)
      case DS_AT_SMS_ERR_CMD:
      case DS_AT_SMS_MSG_CMD:
      case DS_AT_SMS_CFG_CMD:
      case DS_AT_SMS_ABT_CMD:
#endif /* defined(FEATURE_ETSI_SMS) || defined(FEATURE_CDMA_SMS) */

#ifdef FEATURE_DATA_GCSD_FAX
#error code not present
#endif  /* FEATURE_DATA_GCSD_FAX */

#ifdef FEATURE_DATA_ETSI_SUPSERV 
      case DS_AT_CM_SUPS_CMD:
      case DS_AT_CM_SUPS_INFO_CMD:
#endif /* FEATURE_DATA_ETSI_SUPSERV */
#ifdef FEATURE_MMGSDI
      case DS_AT_MMGSDI_INFO_CMD:
#endif /* FEATURE_MMGSDI */
        dsat_process_async_cmd( cmd_ptr );
        break;
#endif /* FEATURE_DATA_STRIP_ATCOP */
#ifdef FEATURE_UIM_SUPPORT_3GPD
      case DS_AT_GSDI_INFO_CMD:
#ifdef FEATURE_DATA_STRIP_ATCOP
        (void)dsatprofile_gsdi_event_handler(DSAT_CMD,cmd_ptr);
#else
        (void)dsatme_gsdi_event_handler(DSAT_CMD,cmd_ptr);
#endif
        break;
#endif /*FEATURE_UIM_SUPPORT_3GPD*/


#ifdef FEATURE_DATA_IS707
      /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        IS707-PKT Commands
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
      case DS_707_PKT_PZID_CHANGE_CMD:
      case DS_707_PKT_SID_CHANGE_CMD:
      case DS_707_PKT_NID_CHANGE_CMD:
      case DS_707_PKT_CTA_TIMER_EXPIRED_CMD:
      case DS_707_PKT_HOLDDOWN_TIMER_EXPIRED_CMD:
      case DS_707_PKT_PZID_DELAY_TIMER_EXPIRED_CMD:
      case DS_707_PKT_PZID_HYSTERESIS_TIMER_EXPIRED_CMD:
      case DS_707_PKT_PHYS_LINK_UP_CMD:
      case DS_707_PKT_PHYS_LINK_DOWN_CMD:
      case DS_707_PKT_IFACE_UP_CMD:
      case DS_707_PKT_IFACE_DOWN_CMD:
      case DS_707_PKT_IFACE_DOWN_IND_CBACK_CMD:
      case DS_707_PKT_IFACE_UP_IND_CBACK_CMD:
      case DS_707_PKT_IFACE_ROUTEABLE_IND_CBACK_CMD:
      case DS_707_TOGGLE_QNC_ENABLE_CMD:
      case DS_707_PKT_PZID_HYS_DATA_READY_CMD:
      case DS_707_PKT_PZID_HYS_SDB_DATA_CMD:
        ds707_pkt_process_cmd(cmd_ptr);
        break;

      /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        RMSM IS707-PKT Commands
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/      
      #ifndef FEATURE_DATA_STRIP_ATCOP
      case DS_707_RMSM_RM_WANTS_PKT_CALL_CMD:
      case DS_707_RMSM_RM_IFACE_DOWN_CMD:
      case DS_707_RMSM_UM_IFACE_DOWN_CMD:
      case DS_707_RMSM_UM_PHYS_LINK_UP_CMD:
      case DS_707_RMSM_UM_PHYS_LINK_DOWN_CMD:
      case DS_707_RMSM_UM_PPP_DOWN_CMD:

#ifdef FEATURE_DS_MOBILE_IP
      case DS_707_RMSM_RM_PPP_UP_CMD:
      case DS_707_RMSM_UM_MIP_UP_CMD:
      case DS_707_RMSM_UM_MIP_DOWN_CMD:
#endif /* FEATURE_DS_MOBILE_IP */ 
 
        ds707_rmsm_process_cmd(cmd_ptr);
        break;
      #endif

#ifndef FEATURE_ASYNC_DATA_NOOP
      /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        IS707-Async Commands
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
      case DS_707_ASYNC_IFACE_BRING_UP_CMD:
      case DS_707_ASYNC_IFACE_TEAR_DOWN_CMD:
      case DS_707_ASYNC_PHYS_LINK_TEAR_DOWN_CMD:
      case DS_707_ASYNC_PTCL_OPENING_TIMER_EXPIRED_CMD:
      case DS_707_ASYNC_PTCL_OPENED_CMD:
      case DS_707_ASYNC_PTCL_CLOSED_CMD:
      case DS_707_ASYNC_ATZ_CMD:
        ds707_async_process_cmd(cmd_ptr);
        break;
#endif  /*FEATURE_ASYNC_DATA_NOOP*/

#endif /* FEATURE_DATA_IS707 */
#if defined(FEATURE_DATA_WCDMA_PS) || defined(FEATURE_GSM_GPRS)
#error code not present
#endif /* FEATURE_DATA_WCDMA_PS || FEATURE_GSM_GPRS */

#if defined(FEATURE_DATA_WCDMA_PS) || defined(FEATURE_GSM_GPRS)
#error code not present
#endif /* FEATURE_DATA_WCDMA_PS || FEATURE_GSM_GPRS */

#ifdef FEATURE_HDR
#error code not present
#endif /* FEATURE_HDR */

      default:
        ERR_FATAL( "Invalid DS task command: %d", cmd_ptr->hdr.cmd_id, 0,0);

    } /* switch */

    /*-----------------------------------------------------------------------
      Return the command buffer to the free command queue.
    -----------------------------------------------------------------------*/
    q_put( &dsi_cmd_free_q, &cmd_ptr->hdr.link );

  } /* while */

} /* dsi_process_cmds() */
示例#19
0
/* TODO: factor */
static void *
worker_thread (void *data)
{
   worker_closure_t *closure = (worker_closure_t *) data;
   mock_server_t *server = closure->server;
   mongoc_stream_t *client_stream = closure->client_stream;
   mongoc_buffer_t buffer;
   mongoc_rpc_t *rpc = NULL;
   bool handled;
   bson_error_t error;
   int32_t msg_len;
   bool stopped;
   sync_queue_t *q;
   request_t *request;
   mongoc_array_t autoresponders;
   ssize_t i;
   autoresponder_handle_t handle;

#ifdef MONGOC_ENABLE_SSL
   bool ssl;
#endif

   ENTRY;

   BSON_ASSERT(closure);

#ifdef MONGOC_ENABLE_SSL
   mongoc_mutex_lock (&server->mutex);
   ssl = server->ssl;
   mongoc_mutex_unlock (&server->mutex);

   if (ssl) {
      if (!mongoc_stream_tls_handshake_block (client_stream, "localhost", TIMEOUT, &error)) {
         MONGOC_ERROR("Blocking TLS handshake failed");
         mongoc_stream_close (client_stream);
         mongoc_stream_destroy (client_stream);
         RETURN (NULL);
      }
   }
#endif

   _mongoc_buffer_init (&buffer, NULL, 0, NULL, NULL);
   _mongoc_array_init (&autoresponders, sizeof (autoresponder_handle_t));

again:
   bson_free (rpc);
   rpc = NULL;
   handled = false;

   mongoc_mutex_lock (&server->mutex);
   stopped = server->stopped;
   mongoc_mutex_unlock (&server->mutex);

   if (stopped) {
      GOTO(failure);
   }

   if (_mongoc_buffer_fill (&buffer, client_stream, 4, TIMEOUT, &error) == -1) {
      GOTO (again);
   }

   assert (buffer.len >= 4);

   memcpy (&msg_len, buffer.data + buffer.off, 4);
   msg_len = BSON_UINT32_FROM_LE (msg_len);

   if (msg_len < 16) {
      MONGOC_WARNING ("No data");
      GOTO (failure);
   }

   if (_mongoc_buffer_fill (&buffer, client_stream, (size_t) msg_len, -1,
                            &error) == -1) {
      MONGOC_WARNING ("%s():%d: %s", BSON_FUNC, __LINE__, error.message);
      GOTO (failure);
   }

   assert (buffer.len >= (unsigned) msg_len);

   /* copies message from buffer */
   request = request_new (&buffer, msg_len, server, client_stream,
                          closure->port);

   mongoc_mutex_lock (&server->mutex);
   _mongoc_array_copy (&autoresponders, &server->autoresponders);
   mongoc_mutex_unlock (&server->mutex);

   if (mock_server_get_verbose (server)) {
      printf ("%5.2f  %hu -> %hu %s\n",
              mock_server_get_uptime_sec (server),
              closure->port, server->port, request->as_str);
      fflush (stdout);
   }

   /* run responders most-recently-added-first */
   for (i = server->autoresponders.len - 1; i >= 0; i--) {
      handle = _mongoc_array_index (&server->autoresponders,
                                    autoresponder_handle_t,
                                    i);
      if (handle.responder (request, handle.data)) {
         handled = true;
         /* responder should destroy the request */
         request = NULL;
         break;
      }
   }

   if (!handled) {
      q = mock_server_get_queue (server);
      q_put (q, (void *) request);
      request = NULL;
   }

   memmove (buffer.data, buffer.data + buffer.off + msg_len,
            buffer.len - msg_len);
   buffer.off = 0;
   buffer.len -= msg_len;

   GOTO (again);

failure:
   _mongoc_array_destroy (&autoresponders);
   _mongoc_buffer_destroy (&buffer);

   mongoc_stream_close (client_stream);
   mongoc_stream_destroy (client_stream);
   bson_free (rpc);
   bson_free (closure);
   _mongoc_buffer_destroy (&buffer);

   RETURN (NULL);
}
示例#20
0
static void spectgen_worker(void *_handle)
{
	float *decode_buffer;
	unsigned int decode_len;
	unsigned int frate;
	unsigned int old_frate = 0;
	unsigned int leftover_len = 0;
	float *buf = NULL;
	int i;
	struct spectgen_struct *handle = (struct spectgen_struct *)_handle;
	if(!handle)
	      goto bailout;

	
	while(1) {
		decode_len = 0;
		decoder_data_pull(handle->session->d_handle, 
					&decode_buffer, &decode_len, &frate);
		if(decode_len == 0)
		      break;

		/* Handle the case when the frame rate changes in the middle.
		 * This is an odd case, but we need to handle it */
		if(!handle->barkband_table_inited || old_frate != frate) {
			old_frate = frate;
			setup_barkband_table(handle, frate);
		}
		/* Compute the weighted sum, this is done in order to 
		 * calculate the average frame rate */
		handle->average_frate += (double)(frate * decode_len);
		handle->total_samples += (double)(decode_len);

		buf = decode_buffer;
		if(leftover_len > 0) {
			buf = malloc(sizeof(float) * (decode_len + leftover_len));
			if(!buf) {
				goto failed_in_loop;
			}
			memcpy(buf, handle->leftover, sizeof(float) * leftover_len);
			memcpy(&buf[leftover_len], decode_buffer, sizeof(float) * decode_len);
			decode_len += leftover_len;
			leftover_len = 0;
			free(decode_buffer);
		}
		if(decode_len >= handle->session->window_size) {
			for(i = 0; i < decode_len - handle->session->window_size; 
						i+=handle->step_size) {
				process_window(handle, &buf[i]);
			}
			if(i < decode_len) {
				memcpy(handle->leftover, &buf[i], 
					sizeof(float) * (decode_len - i));
				leftover_len = decode_len - i;
			}
		} else {
			memcpy(handle->leftover, buf, decode_len * sizeof(float));
			leftover_len = decode_len;
		}
		free(buf);
	}
bailout:
failed_in_loop:
	q_put(&handle->queue, NULL);
}