Пример #1
0
STATICFNDEF int4 bml_find_busy_recycled(int4 hint, uchar_ptr_t base_addr, int4 blks_in_lmap, int *bml_status_ptr)
{
	uchar_ptr_t	ptr, top;
	int		status;
	int4		base_blk, blknum, i;

	top = base_addr + DIVIDE_ROUND_UP(blks_in_lmap, BML_BLKS_PER_UCHAR);
	for (ptr = base_addr + DIVIDE_ROUND_DOWN(hint, BML_BLKS_PER_UCHAR); ptr < top; ptr++)
	{
		if (FOUR_BLKS_FREE == *ptr)
			continue;
		base_blk = (int4)((ptr - base_addr) * (8 / BML_BITS_PER_BLK));
		/* loop through 4 blocks corresponding to this byte */
		for (i = 0; i < BML_BLKS_PER_UCHAR; i++)
		{
			blknum = i + base_blk;
			if (blknum < hint || blks_in_lmap <= blknum)
				continue;
			GET_STATUS(*ptr, i, status);
			if (status != BLK_FREE)
			{
				assert((t_tries < CDB_STAGNATE) || (status == BLK_BUSY) || (status == BLK_RECYCLED));
				*bml_status_ptr = status;
				return blknum;
			}
		}
	}
	return -1;
}
Пример #2
0
static void pollSDO(void)
{
	// wait until SDO goes high
	while (0 == GET_STATUS(COIO_SDO_CFG))
	{
	}
}
Пример #3
0
int serial_getchar(void)
{
    unsigned int Status;
    unsigned int Ch;

	Ch=0;
    //Ch = lib_support_getchar();
    if (Ch == 0)
    {
#if defined(SEMIHOSTED)
	// Use the debugger if the ports are the same
	if (HOST_COMPORT == OS_COMPORT)
	    Ch = (int)SWI_READC();
	else
#endif
	{	    
		do
		{
			Status = GET_STATUS(OS_COMPORT);
	    }
	    while (!RX_DATA(Status));	// wait until ready

	    Ch = GET_CHAR(OS_COMPORT);
	}
    }
    return ((int)Ch);
}				
Пример #4
0
static int
cyg_hal_plf_serial_isr(void *__ch_data, int* __ctrlc, 
                       CYG_ADDRWORD __vector, CYG_ADDRWORD __data)
{
    int res = 0;
    channel_data_t* chan = (channel_data_t*)__ch_data;
    char c;
    cyg_uint32 status;
    CYGARC_HAL_SAVE_GP();

    cyg_drv_interrupt_acknowledge(chan->isr_vector);

    *__ctrlc = 0;
    status = GET_STATUS(chan->base);

    if ( RX_DATA(status) ) {
        c = GET_CHAR(chan->base);

        if( cyg_hal_is_break( &c , 1 ) )
            *__ctrlc = 1;

        res = CYG_ISR_HANDLED;
    }

    CYGARC_HAL_RESTORE_GP();
    return res;
}
Пример #5
0
/**
 * Function: module_imgbase_port_check_caps_unreserve
 *
 * Description: This method is used to unreserve the port
 *
 * Arguments:
 *   @identity: identitity for the session and stream
 *   @port: mct port pointer
 *   @peer: peer mct port pointer
 *
 * Return values:
 *     error/success
 *
 * Notes: none
 **/
boolean module_imgbase_port_check_caps_unreserve(mct_port_t *port,
  unsigned int identity)
{
  int rc = IMG_SUCCESS;
  mct_module_t *p_mct_mod = NULL;
  module_imgbase_t *p_mod = NULL;
  imgbase_client_t *p_client = NULL;
  uint32_t *p_identity = NULL;

  if (!port) {
    IDBG_ERROR("%s:%d invalid input", __func__, __LINE__);
    return FALSE;
  }

  IDBG_MED("%s:%d] E %d", __func__, __LINE__, MCT_PORT_DIRECTION(port));

  p_mct_mod = MCT_MODULE_CAST((MCT_PORT_PARENT(port))->data);
  if (!p_mct_mod) {
    IDBG_ERROR("%s:%d invalid module", __func__, __LINE__);
    return FALSE;
  }

  p_mod = (module_imgbase_t *)p_mct_mod->module_private;
  if (NULL == p_mod) {
    IDBG_ERROR("%s:%d] imgbase module NULL", __func__, __LINE__);
    return FALSE;
  }

  p_client = (imgbase_client_t *)port->port_private;
  if (NULL == p_client) {
    IDBG_ERROR("%s:%d] imgbase client NULL", __func__, __LINE__);
    return FALSE;
  }

  /* lock the module */
  pthread_mutex_lock(&p_mod->mutex);

  if (MCT_PORT_IS_SRC(port)) {
    port->port_private = NULL;
  } else {
    module_imgbase_port_release_client(p_mod, port, p_client, identity);
    port->port_private = NULL;
    if (p_mod->subdevfd >= 0) {
      close(p_mod->subdevfd);
      p_mod->subdevfd = -1;
    }
  }
  pthread_mutex_unlock(&p_mod->mutex);

  /*Todo: free port??*/
  IDBG_MED("%s:%d] X", __func__, __LINE__);
  return GET_STATUS(rc);

error:
  pthread_mutex_unlock(&p_mod->mutex);
  IDBG_MED("%s:%d] Error rc = %d X", __func__, __LINE__, rc);
  return FALSE;

}
Пример #6
0
/*
 * Interrupts on.
 */
void
cpu_irqon(void)
{
        uint32_t x;

        GET_STATUS(x);
        x |= CST_IEc;
        SET_STATUS(x);
}
Пример #7
0
/*
 * Interrupts off.
 */
void
cpu_irqoff(void)
{
        uint32_t x;

        GET_STATUS(x);
        x &= ~(uint32_t)CST_IEc;
        SET_STATUS(x);
}
Пример #8
0
/**
 * Function: module_imgbase_port_ext_link
 *
 * Description: This method is called when the user establishes
 *              link.
 *
 * Arguments:
 *   @identity: identitity for the session and stream
 *   @port: mct port pointer
 *   @peer: peer mct port pointer
 *
 * Return values:
 *     error/success
 *
 * Notes: none
 **/
boolean module_imgbase_port_ext_link(unsigned int identity,
  mct_port_t* port, mct_port_t *peer)
{
  int rc = IMG_SUCCESS;
  unsigned int *p_identity = NULL;
  mct_list_t *p_temp_list = NULL;
  mct_module_t *p_mct_mod = NULL;
  module_imgbase_t *p_mod = NULL;
  imgbase_client_t *p_client = NULL;

  if (!port || !peer) {
    IDBG_ERROR("%s:%d invalid input", __func__, __LINE__);
    return FALSE;
  }

  IDBG_MED("%s:%d] port %p E", __func__, __LINE__, port);
  p_mct_mod = MCT_MODULE_CAST((MCT_PORT_PARENT(port))->data);
  if (!p_mct_mod) {
    IDBG_ERROR("%s:%d invalid module", __func__, __LINE__);
    return FALSE;
  }

  p_mod = (module_imgbase_t *)p_mct_mod->module_private;
  if (NULL == p_mod) {
    IDBG_ERROR("%s:%d] imgbase module NULL", __func__, __LINE__);
    return FALSE;
  }

  p_client = (imgbase_client_t *)port->port_private;
  if (NULL == p_client) {
    IDBG_ERROR("%s:%d] invalid client", __func__, __LINE__);
    return FALSE;
  }

  if (MCT_PORT_PEER(port)) {
    IDBG_ERROR("%s:%d] link already established", __func__, __LINE__);
    return FALSE;
  }

  MCT_PORT_PEER(port) = peer;

  /* check if its sink port*/
  if (MCT_PORT_IS_SINK(port)) {
    /* start imgbase client in case of dynamic module */
  } else {
    /* do nothing for source port */
  }
  IDBG_MED("%s:%d] X", __func__, __LINE__);
  return GET_STATUS(rc);

error:
  IDBG_MED("%s:%d] Error X", __func__, __LINE__);
  return FALSE;

}
Пример #9
0
/**
 * Function: module_imgbase_port_acquire
 *
 * Description: This function is used to acquire the port
 *
 * Arguments:
 *   @p_mct_mod: mct module pointer
 *   @port: mct port pointer
 *   @stream_info: stream information
 *
 * Return values:
 *     true/false
 *
 * Notes: none
 **/
boolean module_imgbase_port_acquire(mct_module_t *p_mct_mod,
  mct_port_t *port,
  mct_stream_info_t *stream_info)
{
  int rc = IMG_SUCCESS;
  unsigned int p_identity ;
  mct_list_t *p_temp_list = NULL;
  imgbase_client_t *p_client = NULL;
  module_imgbase_t *p_mod = NULL;

  IDBG_MED("%s:%d] E", __func__, __LINE__);

  p_mod = (module_imgbase_t *)p_mct_mod->module_private;
  if (NULL == p_mod) {
    IDBG_ERROR("%s:%d] imgbase module NULL", __func__, __LINE__);
    return FALSE;
  }
  p_identity =  stream_info->identity;

  /* check if its sink port*/
  if (MCT_PORT_IS_SINK(port)) {

    rc = module_imglib_common_get_bfr_mngr_subdev(&p_mod->subdevfd);
    if (!rc || p_mod->subdevfd < 0) {
      IDBG_ERROR("%s:%d] Error rc %d fd %d", __func__, __LINE__, rc,
        p_mod->subdevfd);
      goto error;
    }
    /* create imgbase client */
    rc = module_imgbase_client_create(p_mct_mod, port, p_identity, stream_info);

  } else {
    /* update the internal connection with source port */
    p_temp_list = mct_list_find_custom(p_mod->imgbase_client, &p_identity,
      module_imgbase_find_client);
    if (NULL != p_temp_list) {
      p_client = p_temp_list->data;
      p_client->p_srcport = port;
      port->port_private = p_client;
      IDBG_MED("%s:%d] found client %p", __func__, __LINE__, p_client);
    } else {
      IDBG_ERROR("%s:%d] cannot find the client", __func__, __LINE__);
      goto error;
    }
  }
  IDBG_MED("%s:%d] port %p port_private %p X", __func__, __LINE__,
    port, port->port_private);
  return GET_STATUS(rc);

error:

  IDBG_MED("%s:%d] Error X", __func__, __LINE__);
  return FALSE;

}
Пример #10
0
static tU08 transferByte_U08(tU08 data_U08, tU08 instruction_U08)
{
	tU08 i_U08;
	tU08 byteRead_U08 = 0;

	/* first bit is zero */
	SDI_LO;
	SII_LO;
	clockit();

	for (i_U08 = 0; i_U08 < 8; i_U08++)
	{
		/* read one bit form SDO */
		byteRead_U08 <<= 1;   // shift one bit, this clears LSB
		if (GET_STATUS(COIO_SDO_CFG) != 0)
		{
			byteRead_U08 |= 1;
		}

		/* output next data bit on SDI */
		if (data_U08 & 0x80)
		{
			SDI_HI;
		}
		else
		{
			SDI_LO;
		}

		/* output next instruction bit on SII */
		if (instruction_U08 & 0x80)
		{
			SII_HI;
		}
		else
		{
			SII_LO;
		}

		clockit();

		/* prepare for processing next bit */
		data_U08 <<= 1;
		instruction_U08 <<= 1;
	}

	/* Last two bits are zero */
	SDI_LO;
	SII_LO;
	clockit();
	clockit();

	return byteRead_U08;

}
Пример #11
0
int putchar_uart0(int ch)
{
    /* Place your implementation of fputc here     */
    /* e.g. write a character to a UART, or to the */
    /* debugger console with SWI WriteC            */   

	while ( TX_READY(GET_STATUS(UART0_BASE))==0);
	    PUT_CHAR(UART0_BASE, ch);
	    
   return ch;
}
Пример #12
0
/*
 * Used below.
 */
static
void
cpu_irqonoff(void)
{
        uint32_t x, xon, xoff;

        GET_STATUS(x);
        xon = x | CST_IEc;
        xoff = x & ~(uint32_t)CST_IEc;
        SET_STATUS(xon);
	__asm volatile("nop; nop; nop; nop");
        SET_STATUS(xoff);
}
Пример #13
0
void sendchar( char *ch )
{
	char Ch;
	unsigned int Status;
	Ch=*ch;
    do
    {
		Status = GET_STATUS(OS_COMPORT);
    }
    while (!TX_READY(Status));	// wait until ready

    PUT_CHAR(OS_COMPORT, Ch);
    if (Ch == '\n')
    {
		do
		{
		    Status = GET_STATUS(OS_COMPORT);
		}
		while (!TX_READY(Status));	// wait until ready

		PUT_CHAR(OS_COMPORT, '\r');
	}
}
Пример #14
0
void
cyg_hal_plf_serial_putc(void *__ch_data, char c)
{
    channel_data_t* chan = (channel_data_t*)__ch_data;
    cyg_uint8* base = chan->base;
    cyg_uint32 status;
    CYGARC_HAL_SAVE_GP();

    do {
      status = GET_STATUS(base);
    } while (!TX_READY(status));	// wait until ready

    PUT_CHAR(base, c);

    if (c == '\n') {
      do {
	status = GET_STATUS(base);
      } while (!TX_READY(status));	// wait until ready
      
      PUT_CHAR(base, '\r');
    }

    CYGARC_HAL_RESTORE_GP();
}
Пример #15
0
static cyg_bool
cyg_hal_plf_serial_getc_nonblock(void* __ch_data, cyg_uint8* ch)
{
    cyg_uint8* base = ((channel_data_t*)__ch_data)->base;
    cyg_uint32 status ;
    long timeout = 100;  // A long time...

    do {
      status = GET_STATUS(base);
      if (--timeout == 0) return false ; 
    } while (!RX_DATA(status));	// wait until ready

    *ch = GET_CHAR(base);

    return true;
}
Пример #16
0
// Executes a <simple> redirection. If background == true, the command is
// executed in the background. Returns the <simple>'s status, or 0 if background
// is true and we don't wait for it to die.
int processSimple(CMD* cmd, bool background)
{
    if(IS_BUILTIN(cmd->argv[0]))
    {
        int status = execBuiltin(cmd);
        updateStatusVar(status);
        return status;
    }
    
    int pid;
    if((pid = fork()) < 0)
    {
        // error in forking
        perror(EXEC_NAME);
        return errno;
    }
    else if(pid == 0)
    {
        // child
        if(redirect(cmd) < 0)
        {
            exit(errno);
        }
        execvp(cmd->argv[0], cmd->argv);
        perror(EXEC_NAME);
        exit(EXIT_FAILURE);
    }
    else
    {
        // parent        
        if(background)
        {
            return 0;
        }
        else
        {
            int status;
            signal(SIGINT, SIG_IGN);
            waitpid(pid, &status, 0);
            signal(SIGINT, SIG_DFL);
            
            int exitStatus = GET_STATUS(status);
            updateStatusVar(exitStatus);
            return exitStatus;
        }
    }
}
Пример #17
0
/*
 * Check if transaction must block.
 */
static inline int stm_check_quiesce(stm_tx_t *tx)
{
  stm_word_t s;

  /* Must be called upon start (while already active but before acquiring any lock) */
  assert(IS_ACTIVE(tx->status));

  ATOMIC_MB_FULL;
  if (ATOMIC_LOAD_ACQ(&quiesce) == 2) {
    s = ATOMIC_LOAD(&tx->status);
    SET_STATUS(tx->status, TX_IDLE);
    while (ATOMIC_LOAD_ACQ(&quiesce) == 2) {
      sched_yield();
    }
    SET_STATUS(tx->status, GET_STATUS(s));
    return 1;
  }
  return 0;
}
Пример #18
0
/**
 * Function: module_imgbase_stop_session
 *
 * Description: This function is called when the camera
 *              session is stopped
 *
 * Arguments:
 *   @module: mct module pointer
 *   @sessionid: session id
 *
 * Return values:
 *     error/success
 *
 * Notes: none
 **/
static boolean module_imgbase_stop_session(mct_module_t *module,
  unsigned int sessionid)
{
  int rc = IMG_SUCCESS;
  module_imgbase_t *p_mod;

  if (!module) {
    IDBG_ERROR("%s:%d failed", __func__, __LINE__);
    return FALSE;
  }

  p_mod = (module_imgbase_t *)module->module_private;
  if (!p_mod) {
    IDBG_ERROR("%s:%d failed", __func__, __LINE__);
    return FALSE;
  }

  /* destroy message thread */
  rc = module_imglib_destroy_msg_thread(&p_mod->msg_thread);
  return GET_STATUS(rc);
}
Пример #19
0
int serial_kbhit(void)
{
    unsigned int Status;

#if defined(SEMIHOSTED)

    // If the ports are the same, have to use the debugger and we
    // can't tell if there is a character available
    if (HOST_COMPORT == OS_COMPORT)
    {
	return (1);
    }

#endif
    //lib_flush_buffer();
    Status = GET_STATUS(0xFFF80000);
    if (!RX_DATA(Status))
	return (0);
    else
	return (1);
}
Пример #20
0
// Creates a subshell and executes cmd in it. Returns the status of the
// subcommand. If backgrond == true, the subcommand is executed in the
// background. The redirection info in subcmdNode is applied to the subshell if
// it is non-NULL.
int processSubcommand(CMD* cmd, CMD* subcmdNode, bool background)
{
    int pid;
    if((pid = fork()) < 0)
    {
        // error in forking
        perror(EXEC_NAME);
        return errno;
    }
    else if(pid == 0)
    {
        // child
        if(subcmdNode && redirect(subcmdNode) < 0)
        {
            exit(errno);
        }
        exit(process(cmd));
    }
    else
    {
        // parent
        if(background)
        {
            return 0;
        }
        else
        {
            int status;
            signal(SIGINT, SIG_IGN);
            waitpid(pid, &status, 0);
            signal(SIGINT, SIG_DFL);
            
            int exitStatus = GET_STATUS(status);
            updateStatusVar(exitStatus);
            return exitStatus;   
        }
    }
}
Пример #21
0
/*
 * Catch signal (to emulate non-faulting load).
 */
static void
signal_catcher(int sig)
{
  sigset_t block_signal;
  stm_tx_t *tx = tls_get_tx();

  /* A fault might only occur upon a load concurrent with a free (read-after-free) */
  PRINT_DEBUG("Caught signal: %d\n", sig);

  /* TODO: TX_KILLED should be also allowed */
  if (tx == NULL || tx->attr.no_retry || GET_STATUS(tx->status) != TX_ACTIVE) {
    /* There is not much we can do: execution will restart at faulty load */
    fprintf(stderr, "Error: invalid memory accessed and no longjmp destination\n");
    exit(1);
  }

  /* Unblock the signal since there is no return to signal handler */
  sigemptyset(&block_signal);
  sigaddset(&block_signal, sig);
  pthread_sigmask(SIG_UNBLOCK, &block_signal, NULL);

  /* Will cause a longjmp */
  stm_rollback(tx, STM_ABORT_SIGNAL);
}
/**
 * Function: module_cac_port_event_func
 *
 * Description: Event handler function for the dummy port
 *
 * Arguments:
 *   @port: mct port pointer
 *   @event: mct event
 *
 * Return values:
 *     error/success
 *
 * Notes: none
 **/
boolean module_cac_port_event_func(mct_port_t *port,
  mct_event_t *event)
{
  int rc = IMG_SUCCESS;
  mct_module_t *p_mct_mod = NULL;
  module_cac_t *p_mod = NULL;
  cac_client_t *p_client;
  boolean fwd_event = TRUE;

  if (!port || !event) {
    IDBG_ERROR("%s:%d invalid input", __func__, __LINE__);
    return FALSE;
  }
  IDBG_LOW("%s:%d] port %p E", __func__, __LINE__, port);
  p_mct_mod = MCT_MODULE_CAST((MCT_PORT_PARENT(port))->data);
  if (!p_mct_mod) {
    IDBG_ERROR("%s:%d invalid module", __func__, __LINE__);
    return FALSE;
  }

  p_mod = (module_cac_t *)p_mct_mod->module_private;
  if (NULL == p_mod) {
    IDBG_ERROR("%s:%d] CAC module NULL", __func__, __LINE__);
    return FALSE;
  }

  p_client = (cac_client_t *)port->port_private;
  if (NULL == p_client) {
    IDBG_ERROR("%s:%d] CAC client NULL", __func__, __LINE__);
    return FALSE;
  }

  IDBG_LOW("%s:%d] type %d", __func__, __LINE__, event->type);
  switch (event->type) {
  case MCT_EVENT_CONTROL_CMD: {
    mct_event_control_t *p_ctrl_event = &event->u.ctrl_event;
    IDBG_MED("%s:%d] Ctrl type %d", __func__, __LINE__, p_ctrl_event->type);
    switch (p_ctrl_event->type) {
    case MCT_EVENT_CONTROL_STREAMON: {
      IDBG_HIGH("%s:%d] CAC STREAMON", __func__, __LINE__);
      pthread_mutex_lock(&p_client->mutex);
      p_client->stream_off = FALSE;
      pthread_mutex_unlock(&p_client->mutex);
      break;
    }
    case MCT_EVENT_CONTROL_STREAMOFF: {
      module_cac_t *p_mod = (module_cac_t *)p_client->p_mod;
      IDBG_MED("%s:%d] CAC STREAMOFF", __func__, __LINE__);
      pthread_mutex_lock(&p_client->mutex);
      p_client->stream_off = TRUE;
      pthread_mutex_unlock(&p_client->mutex);
      img_q_flush(&p_mod->msg_thread.msg_q);
    }
    default:
      break;
    }
    break;
  }
  case MCT_EVENT_MODULE_EVENT: {
    mct_event_module_t *p_mod_event = &event->u.module_event;
    img_component_ops_t *p_comp = &p_client->comp;
    IDBG_MED("%s:%d] Mod type %d", __func__, __LINE__, p_mod_event->type);
    switch (p_mod_event->type) {
    case MCT_EVENT_MODULE_BUF_DIVERT: {
      mod_img_msg_t msg;
      isp_buf_divert_t *p_buf_divert =
        (isp_buf_divert_t *)p_mod_event->module_event_data;

      IDBG_ERROR("%s:%d] identity %x", __func__, __LINE__,
        event->identity);

      memset(&msg, 0x0, sizeof(mod_img_msg_t));
      msg.port = port;
      msg.type = MOD_IMG_MSG_DIVERT_BUF;
      msg.data.buf_divert.buf_divert = *p_buf_divert;
      msg.data.buf_divert.identity = p_client->identity;
      msg.data.buf_divert.p_exec = module_cac_client_divert_exec;
      msg.data.buf_divert.userdata = (void *)p_client;
      module_imglib_send_msg(&p_mod->msg_thread, &msg);

      /* indicate that the buffer is consumed */
      p_buf_divert->is_locked = FALSE;
      p_buf_divert->ack_flag = FALSE;
      fwd_event = FALSE;

      break;
    }
    case MCT_EVENT_MODULE_STATS_AWB_UPDATE: {
      stats_update_t *stats_update = (stats_update_t *)
        p_mod_event->module_event_data;
      p_client->cac_cfg_info.cac_3a_data.awb_gr_gain =
        FLOAT_TO_Q(7, stats_update->awb_update.gain.g_gain);
      p_client->cac_cfg_info.cac_3a_data.awb_gb_gain =
        FLOAT_TO_Q(7, stats_update->awb_update.gain.g_gain);
      IDBG_HIGH("%s: abw gr = %f, awb gb = %f", __func__,
        p_client->cac_cfg_info.cac_3a_data.awb_gr_gain,
        p_client->cac_cfg_info.cac_3a_data.awb_gb_gain);
    }
    break;
    case MCT_EVENT_MODULE_SET_CHROMATIX_PTR:
      //Todo: Update chromatix params with Chromatix version 303
    default:
      break;
    }
    break;
  }
  default:
   break;
  }

  if (fwd_event) {
    boolean brc = module_cac_forward_port_event(p_client, port, event);
    rc = (brc) ? IMG_SUCCESS : IMG_ERR_GENERAL;
  }

  return GET_STATUS(rc);
}
Пример #23
0
// Executes a pipeline and returns the exit status of the pipe. The arg
// pipeRoot is the PIPE or PIPE_ERR command at the root of the pipeline.
// This function draws upon code from Professor Stan Eisenstat at Yale
// University
int execPipe(CMD* pipeRoot)
{
    // count the number of stages in the pipeline
    int numStages = 1;
    for(CMD* cmd = pipeRoot; ISPIPE(cmd->type); cmd = cmd->right, numStages++);
    
    // create table to hold pid and exit status of all stages in the pipe
    struct {
        int pid, status;
    } processTable[numStages];
    
    int fd[2];             // holds file descriptors for the pipe
    int pid, status;       //   the pid and status of a single stage
    int fdIn = STDIN_FD;   //   the read end of the last pipe, or the original
                           //   stdin
    
    CMD* cmd = pipeRoot;
    for(int i = 0; ISPIPE(cmd->type); cmd = cmd->right, i++)
    {
        if(pipe(fd) < 0 || (pid = fork()) < 0)
        {
            perror(EXEC_NAME);
            return errno;
        }
        else if(pid == 0)
        {
            // child
            close(fd[0]);
            
            // redirect stdin to the last pipe read (if there was a last pipe)
            if(fdIn != STDIN_FD)
            {
                dup2(fdIn, STDIN_FD);
                close(fdIn);
            }
            
            bool shouldCloseFD1 = false;
            // redirect stdout to the new pipe write (if it's not stdout)
            if(fd[1] != STDOUT_FD)
            {
                dup2(fd[1], STDOUT_FD);
                shouldCloseFD1 = true;
            }
            
            // if this is a PIPE_ERR, redirect stderr to the new pipe write
            // (if it's not stderr)
            if(cmd->type == PIPE_ERR && fd[1] != STDERR_FD)
            {
                dup2(fd[1], STDERR_FD);
                shouldCloseFD1 = true;
            }
            
            if(shouldCloseFD1) close(fd[1]);
            
            exit(processStage(cmd->left));
        }
        else
        {
            // parent
            processTable[i].pid = pid;
            
            // close the read end of the last pipe if it's not the orig stdin
            if(i > 0)
            {
                close(fdIn);
            }
            
            fdIn = fd[0]; // remember the read end of the new pipe
            close(fd[1]);
        }
    }
    // cmd is now the right child of last PIPE or PIPE_ERR, the last stage of
    // the pipeline
    
    // if the last stage is a built-in command, it should affect the parent
    // shell, so execute it here instead of forking off a process
    if(cmd->type == SIMPLE && IS_BUILTIN(cmd->argv[0]))
    {
        processTable[numStages - 1].pid = -1; // unused pid
        processTable[numStages - 1].status = processSimple(cmd, false);
        close(fdIn);
    }
    else if((pid = fork()) < 0)
    {
        perror(EXEC_NAME);
        return errno;
    }
    else if(pid == 0)
    {
        // child
        if(fdIn != STDIN_FD)
        {
            dup2(fdIn, STDIN_FD);
            close(fdIn);
        }
        exit(processStage(cmd));
    }
    else
    {
        // parent
        processTable[numStages - 1].pid = pid;
        close(fdIn);
    }
    
    // wait for children to die
    signal(SIGINT, SIG_IGN);
    for(int i = 0; i < numStages; )
    {
        pid = wait(&status);
        int j;
        for(j = 0; j < numStages && processTable[j].pid != pid; j++);
        
        // only add to the processTable if the child's pid is in the table;
        // that is, ignore zombies
        if(j < numStages)
        {
            processTable[j].status = status;
            i++;
        }
    }
    signal(SIGINT, SIG_DFL);
    
    for(int i = 0; i < numStages; i++)
    {
        if(GET_STATUS(processTable[i].status) != 0)
        {
            return GET_STATUS(processTable[i].status);
        }
    }
    return 0;
}
Пример #24
0
/*
 * Called by the CURRENT thread to inquire about the status of a transaction.
 */
int stm_aborted(TXPARAM)
{
  TX_GET;

  return (GET_STATUS(tx->status) == TX_ABORTED);
}
Пример #25
0
/**
 * Function: module_imgbase_port_event_func
 *
 * Description: Event handler function for the imgbase port
 *
 * Arguments:
 *   @port: mct port pointer
 *   @event: mct event
 *
 * Return values:
 *     true/false
 *
 * Notes: none
 **/
boolean module_imgbase_port_event_func(mct_port_t *port,
  mct_event_t *event)
{
  int rc = IMG_SUCCESS;
  mct_module_t *p_mct_mod = NULL;
  module_imgbase_t *p_mod = NULL;
  imgbase_client_t *p_client;
  boolean fwd_event = TRUE;

  if (!port || !event) {
    IDBG_ERROR("%s:%d invalid input", __func__, __LINE__);
    return FALSE;
  }
  IDBG_LOW("%s:%d] port %p E", __func__, __LINE__, port);
  p_mct_mod = MCT_MODULE_CAST((MCT_PORT_PARENT(port))->data);
  if (!p_mct_mod) {
    IDBG_ERROR("%s:%d invalid module", __func__, __LINE__);
    return FALSE;
  }

  p_mod = (module_imgbase_t *)p_mct_mod->module_private;
  if (NULL == p_mod) {
    IDBG_ERROR("%s:%d] imgbase module NULL", __func__, __LINE__);
    return FALSE;
  }

  p_client = (imgbase_client_t *)port->port_private;
  if (NULL == p_client) {
    IDBG_ERROR("%s:%d] imgbase client NULL", __func__, __LINE__);
    return FALSE;
  }

  IDBG_LOW("%s:%d] type %d", __func__, __LINE__, event->type);
  switch (event->type) {
  case MCT_EVENT_CONTROL_CMD: {
    mct_event_control_t *p_ctrl_event = &event->u.ctrl_event;
    IDBG_MED("%s:%d] Ctrl type %d", __func__, __LINE__, p_ctrl_event->type);
    switch (p_ctrl_event->type) {
    case MCT_EVENT_CONTROL_STREAMON: {
      IDBG_HIGH("%s:%d] IMGLIB_BASE STREAMON", __func__, __LINE__);
      module_imgbase_client_start(p_client);
      break;
    }
    case MCT_EVENT_CONTROL_STREAMOFF: {
      module_imgbase_t *p_mod = (module_imgbase_t *)p_client->p_mod;
      IDBG_MED("%s:%d] imgbase STREAMOFF", __func__, __LINE__);
      module_imgbase_client_stop(p_client);
      img_q_flush_and_destroy(&p_mod->msg_thread.msg_q);
      img_q_flush_and_destroy(&p_client->stream_parm_q);
      break;
    }
    case MCT_EVENT_CONTROL_PARM_STREAM_BUF: {
      cam_stream_parm_buffer_t *parm_buf =
        event->u.ctrl_event.control_event_data;
      IDBG_HIGH("%s:%d] MCT_EVENT_CONTROL_PARM_STREAM_BUF %d",
        __func__, __LINE__, parm_buf ? parm_buf->type : 0xffff);
      if (parm_buf &&
        (parm_buf->type == CAM_STREAM_PARAM_TYPE_GET_IMG_PROP)) {
        cam_stream_parm_buffer_t *out_buf;
        out_buf = img_q_dequeue(&p_client->stream_parm_q);
        if (out_buf) {
          *parm_buf = *out_buf;
          free(out_buf);
        }
      }
      break;
    }
    default:
      break;
    }
    break;
  }
  case MCT_EVENT_MODULE_EVENT: {
    mct_event_module_t *p_mod_event = &event->u.module_event;
    img_component_ops_t *p_comp = &p_client->comp;
    IDBG_MED("%s:%d] Mod type %d", __func__, __LINE__, p_mod_event->type);
    switch (p_mod_event->type) {
    case MCT_EVENT_MODULE_BUF_DIVERT: {
      mod_img_msg_t msg;
      isp_buf_divert_t *p_buf_divert =
        (isp_buf_divert_t *)p_mod_event->module_event_data;

      IDBG_ERROR("%s:%d] identity %x", __func__, __LINE__,
        event->identity);

      module_imgbase_client_handle_buffer(p_client, p_buf_divert);

      /* indicate that the buffer is consumed */
      p_buf_divert->is_locked = FALSE;
      p_buf_divert->ack_flag = FALSE;
      fwd_event = FALSE;

      break;
    }
    case MCT_EVENT_MODULE_STATS_AWB_UPDATE: {
      stats_update_t *stats_update = (stats_update_t *)
        p_mod_event->module_event_data;
      break;
    }
    case MCT_EVENT_MODULE_QUERY_DIVERT_TYPE: {
      uint32_t *divert_mask = (uint32_t *)p_mod_event->module_event_data;
      *divert_mask |= PPROC_DIVERT_PROCESSED;
      break;
    }
    case MCT_EVENT_MODULE_SET_CHROMATIX_PTR:
      break;
    default:
      break;
    }
    break;
  }
  default:
   break;
  }

  if (fwd_event) {
    boolean brc = module_imgbase_forward_port_event(p_client, port, event);
    rc = (brc) ? IMG_SUCCESS : IMG_ERR_GENERAL;
  }

  return GET_STATUS(rc);
}
Пример #26
0
static int receive_pcb(elp_device * adapter, pcb_struct * pcb)

{
    int i;
    int total_length;
    int stat;
    int timeout;

    CHECK_NULL(pcb);
    CHECK_NULL(adapter);

    /* get the command code */
    timeout = jiffies + TIMEOUT;
    while (((stat = GET_STATUS())&STATUS_ACRF) == 0 && jiffies < timeout)
        ;
    if (jiffies >= timeout)
        TIMEOUT_MSG();

    SET_HSF(0);
    pcb->command = INB(adapter->io_addr+PORT_COMMAND);
    if ((stat & ASF_PCB_MASK) != ASF_PCB_END) {

        /* read the data length */
        timeout = jiffies + TIMEOUT;
        while (((stat = GET_STATUS())&STATUS_ACRF) == 0 && jiffies < timeout)
            ;
        if (jiffies >= timeout)
            TIMEOUT_MSG();
        pcb->length = INB(adapter->io_addr+PORT_COMMAND);

        if (pcb->length > MAX_PCB_DATA)
            printk(invalid_pcb_msg, pcb->length, filename,__LINE__);

        if ((stat & ASF_PCB_MASK) != ASF_PCB_END) {

            /* read the data */
            i = 0;
            timeout = jiffies + TIMEOUT;
            do {
                while (((stat = GET_STATUS())&STATUS_ACRF) == 0 && jiffies < timeout)
                    ;
                pcb->data.raw[i++] = INB(adapter->io_addr+PORT_COMMAND);
                if (i > MAX_PCB_DATA)
                    printk(invalid_pcb_msg, i, filename, __LINE__);
            } while ((stat & ASF_PCB_MASK) != ASF_PCB_END && jiffies < timeout);

            if (jiffies >= timeout)
                TIMEOUT_MSG();

            /* woops, the last "data" byte was really the length! */
            total_length = pcb->data.raw[--i];

            /* safety check total length vs data length */
            if (total_length != (pcb->length + 2)) {
                if (elp_debug >= 2)
                    printk("%s: mangled PCB received\n", adapter->name);
                SET_HSF(HSF_PCB_NAK);
                return FALSE;
            }

            SET_HSF(HSF_PCB_ACK);
            return TRUE;
        }
    }

    SET_HSF(HSF_PCB_NAK);
    return FALSE;
}
Пример #27
0
/**
 * Function: module_imgbase_port_set_caps
 *
 * Description: This method is used to set the capabilities
 *
 * Arguments:
 *   @port: mct port pointer
 *   @caps: mct port capabilities
 *
 * Return values:
 *     error/success
 *
 * Notes: none
 **/
boolean module_imgbase_port_set_caps(mct_port_t *port,
  mct_port_caps_t *caps)
{
  int rc = IMG_SUCCESS;
  return GET_STATUS(rc);
}
Пример #28
0
/*
 * Set the CURRENT transaction as irrevocable.
 */
static INLINE int
int_stm_set_irrevocable(stm_tx_t *tx, int serial)
{
#ifdef IRREVOCABLE_ENABLED
# if CM == CM_MODULAR
    stm_word_t t;
# endif /* CM == CM_MODULAR */

    if (!IS_ACTIVE(tx->status) && serial != -1) {
        /* Request irrevocability outside of a transaction or in abort handler (for next execution) */
        tx->irrevocable = 1 + (serial ? 0x08 : 0);
        return 0;
    }

    /* Are we already in irrevocable mode? */
    if ((tx->irrevocable & 0x07) == 3) {
        return 1;
    }

    if (tx->irrevocable == 0) {
        /* Acquire irrevocability for the first time */
        tx->irrevocable = 1 + (serial ? 0x08 : 0);
#ifdef HYBRID_ASF
        /* TODO: we shouldn't use pthread_mutex/cond since it could use syscall. */
        if (tx->software == 0) {
            asf_abort(ASF_RETRY_IRREVOCABLE);
            return 0;
        }
#endif /* HYBRID_ASF */
        /* Try acquiring global lock */
        if (_tinystm.irrevocable == 1 || ATOMIC_CAS_FULL(&_tinystm.irrevocable, 0, 1) == 0) {
            /* Transaction will acquire irrevocability after rollback */
            stm_rollback(tx, STM_ABORT_IRREVOCABLE);
            return 0;
        }
        /* Success: remember we have the lock */
        tx->irrevocable++;
        /* Try validating transaction */
#if DESIGN == WRITE_BACK_ETL
        if (!stm_wbetl_validate(tx)) {
            stm_rollback(tx, STM_ABORT_VALIDATE);
            return 0;
        }
#elif DESIGN == WRITE_BACK_CTL
        if (!stm_wbctl_validate(tx)) {
            stm_rollback(tx, STM_ABORT_VALIDATE);
            return 0;
        }
#elif DESIGN == WRITE_THROUGH
        if (!stm_wt_validate(tx)) {
            stm_rollback(tx, STM_ABORT_VALIDATE);
            return 0;
        }
#elif DESIGN == MODULAR
        if ((tx->attr.id == WRITE_BACK_CTL && stm_wbctl_validate(tx))
                || (tx->attr.id == WRITE_THROUGH && stm_wt_validate(tx))
                || (tx->attr.id != WRITE_BACK_CTL && tx->attr.id != WRITE_THROUGH && stm_wbetl_validate(tx))) {
            stm_rollback(tx, STM_ABORT_VALIDATE);
            return 0;
        }
#endif /* DESIGN == MODULAR */

# if CM == CM_MODULAR
        /* We might still abort if we cannot set status (e.g., we are being killed) */
        t = tx->status;
        if (GET_STATUS(t) != TX_ACTIVE || ATOMIC_CAS_FULL(&tx->status, t, t + (TX_IRREVOCABLE - TX_ACTIVE)) == 0) {
            stm_rollback(tx, STM_ABORT_KILLED);
            return 0;
        }
# endif /* CM == CM_MODULAR */
        if (serial && tx->w_set.nb_entries != 0) {
            /* TODO: or commit the transaction when we have the irrevocability. */
            /* Don't mix transactional and direct accesses => restart with direct accesses */
            stm_rollback(tx, STM_ABORT_IRREVOCABLE);
            return 0;
        }
    } else if ((tx->irrevocable & 0x07) == 1) {
        /* Acquire irrevocability after restart (no need to validate) */
        while (_tinystm.irrevocable == 1 || ATOMIC_CAS_FULL(&_tinystm.irrevocable, 0, 1) == 0)
            ;
        /* Success: remember we have the lock */
        tx->irrevocable++;
    }
    assert((tx->irrevocable & 0x07) == 2);

    /* Are we in serial irrevocable mode? */
    if ((tx->irrevocable & 0x08) != 0) {
        /* Stop all other threads */
        if (stm_quiesce(tx, 1) != 0) {
            /* Another thread is quiescing and we are active (trying to acquire irrevocability) */
            assert(serial != -1);
            stm_rollback(tx, STM_ABORT_IRREVOCABLE);
            return 0;
        }
    }

    /* We are in irrevocable mode */
    tx->irrevocable++;

#else /* ! IRREVOCABLE_ENABLED */
    fprintf(stderr, "Irrevocability is not supported in this configuration\n");
    exit(-1);
#endif /* ! IRREVOCABLE_ENABLED */
    return 1;
}