示例#1
0
文件: socket_stub.c 项目: wuwx/simba
static ssize_t read(void *self_p,
                    void *buf_p,
                    size_t size)
{
    void *ref_buf_p;
    size_t ref_size;

    queue_read(&qinput, &ref_buf_p, sizeof(ref_buf_p));
    queue_read(&qinput, &ref_size, sizeof(ref_size));
    memcpy(buf_p, ref_buf_p, size);

    return (ref_size);
}
示例#2
0
/*JSON{
 "type"     : "method",
 "class"    : "Queue",
 "name"     : "read",
 "generate" : "jswrap_Queue_read"
}
reads one character from queue, if available
*/
void jswrap_Queue_read(JsVar *parent) {
  char data;
  JsVar *idx = jsvObjectGetChild(parent,"index",1);
  queue_read(jsvGetInteger(idx));
  jsvUnLock(idx);
  return;
}
示例#3
0
ret_code_t nrf_queue_read(nrf_queue_t const * p_queue,
                          void              * p_data,
                          size_t              element_count)
{
    ret_code_t status = NRF_SUCCESS;

    ASSERT(p_queue != NULL);
    ASSERT(p_data != NULL);

    if (element_count == 0)
    {
        return NRF_SUCCESS;
    }

    CRITICAL_REGION_ENTER();

    if (element_count <= queue_utilization_get(p_queue))
    {
        queue_read(p_queue, p_data, element_count);
    }
    else
    {
        status = NRF_ERROR_NOT_FOUND;
    }

    CRITICAL_REGION_EXIT();

    return status;
}
示例#4
0
      void handle_read(PacketFrom *udpfrom, const boost::system::error_code& error, const size_t bytes_recvd)
      {
	OPENVPN_LOG_UDPLINK_VERBOSE("UDPLink::handle_read: " << error.message());
	PacketFrom::SPtr pfp(udpfrom);
	if (!halt)
	  {
	    if (bytes_recvd)
	      {
		if (!error)
		  {
		    OPENVPN_LOG_UDPLINK_VERBOSE("UDP from " << pfp->sender_endpoint);
		    pfp->buf.set_size(bytes_recvd);
		    stats->inc_stat(SessionStats::BYTES_IN, bytes_recvd);
		    stats->inc_stat(SessionStats::PACKETS_IN, 1);
		    read_handler->udp_read_handler(pfp);
		  }
		else
		  {
		    OPENVPN_LOG_UDPLINK_ERROR("UDP recv error: " << error.message());
		    stats->error(Error::NETWORK_RECV_ERROR);
		  }
	      }
	    queue_read(pfp.release()); // reuse PacketFrom object if still available
	  }
      }
示例#5
0
文件: serial.c 项目: mikesma/fit-cvut
_U1TXInterrupt ()
{
	if (!queue_is_empty (&g_tx_queue))
		U1TXREG = (char) queue_read (&g_tx_queue);

	IFS0bits.U1TXIF = 0;
}
示例#6
0
bool_e VisionCamFrameManager::Set(VisionCamFrame *fr)
{
    bool_e ret = false_e;
    FrameQueueNode_t *fNode = NULL;
    if( fr && qFrames )
    {
        return true_e;
        Lock(frm, ReadLock_e );
        while( queue_length(qFrames ) )
        {
            queue_read( qFrames, false_e, fNode);

            if( !fNode )
                continue;

            if( fNode && fNode->frame && fNode->frame->mFrameBuff == fr->mFrameBuff )
            {
                memcpy(fNode->frame, fr, sizeof(VisionCamFrame));/// @todo check other possibilities
            }
        }
        Unlock(frm, ReadLock_e );
    }

    return ret;
}
示例#7
0
文件: can.c 项目: wuwx/simba
static ssize_t base_chan_read(void *base_p, void *buf_p, size_t size)
{
    struct can_driver_t *self_p;

    self_p = base_p;

    return (queue_read(&self_p->chin, buf_p, size));
}
示例#8
0
    void start(const int n_parallel)
    {
      if (!halt)
	{
	  for (int i = 0; i < n_parallel; i++)
	    queue_read(NULL);
	}
    }
示例#9
0
文件: gfx_display.c 项目: aosp/dvp
bool_e gfx_display_dequeue(gfx_display_t *gfxd, void **phandle)
{
    if (gfxd)
    {
        // wait for buffer from queue
        return queue_read(gfxd->returnq, true_e, phandle);
    }
    return false_e;
}
示例#10
0
文件: can.c 项目: wuwx/simba
ssize_t can_read(struct can_driver_t *self_p,
                 struct can_frame_t *frame_p,
                 size_t size)
{
    ASSERTN(self_p != NULL, EINVAL);
    ASSERTN(frame_p != NULL, EINVAL);
    ASSERTN(size > 0, EINVAL);

    return (queue_read(&self_p->chin, frame_p, size));
}
示例#11
0
FlatBuffer *FlatBufferMgr::nextReady()
{
    uint32_t idx;
    bool ret = queue_read(mReadyQueue, true_e, &idx);
    if (ret) {
        const sp<FlatBuffer>& b = mBuffers[idx];
        ARX_PRINT(ARX_ZONE_BUFFER, "mgr: %d, a buffer is ready: %p, idx:%d", mBuffId, b.get(), idx);
        return b.get();
    }
    return NULL;
}
示例#12
0
SPAN_DECLARE(int) queue_read_msg(queue_state_t *s, uint8_t *buf, int len)
{
    uint16_t lenx;

    /* If we assume the write message was atomic, this read message should be
      safe when conducted in multiple chunks */
    if (queue_read(s, (uint8_t *) &lenx, sizeof(uint16_t)) != sizeof(uint16_t))
        return -1;
    /*endif*/
    /* If we got this far, the actual message chunk should be guaranteed to be
       available */
    if (lenx == 0)
        return 0;
    /*endif*/
    if ((int) lenx > len)
    {
        len = queue_read(s, buf, len);
        /* Discard the rest of the message */
        queue_read(s, NULL, lenx - len);
        return len;
    }
    /*endif*/
    return queue_read(s, buf, lenx);
}
示例#13
0
bool_e VisionCamFrameManager::Get(VisionCamFrame* frm, FrameProperty_t p, void* dest)
{
    bool_e ret = false_e;
    FrameQueueNode_t *fr = NULL;

    if( frm && qFrames )
    {
        Lock(frm, WriteLock_e );
        while( queue_length(qFrames ) )
        {
            queue_read( qFrames, false_e, fr);

            if( !fr )
                continue;

            switch(p)
            {
                case FrameBuffer_e:
                    if( fr->frame == frm->mFrameBuff )
                    {
                        dest = fr->frame;//->mFrameBuff;
                        ret = true_e;
                    }
                    break;

                case FrameTimeStamp_e:
                    if( fr->frame->mTimestamp == frm->mTimestamp )
                    {
                        dest = fr->frame;
                        ret = true_e;
                    }
                    break;

                case FrameNode_e:
                    if(fr->frame == frm->mFrameBuff)
                    {
                        dest = fr;
                        ret = true_e;
                    }
                    break;
            }
        }
        Unlock(frm, WriteLock_e );
    }

    return ret;
}
示例#14
0
文件: serial.c 项目: mikesma/fit-cvut
// Read a single character from the input queue
static int
serial_getchar ()
{
	while (1)
	{
		DISABLE_INTERRUPTS
		if (!queue_is_empty (&g_rx_queue))
			break;

		ENABLE_INTERRUPTS
		delay_loop_ms (1);
	}

	int val = queue_read (&g_rx_queue);
	ENABLE_INTERRUPTS
	return val;
}
示例#15
0
static ssize_t kmsgdump_read(struct file *filp, char *buf, size_t count, loff_t *ppos)
{
	int read_size = 0;
	int buf_size = queue_data_size(&g_dumpqueue);
	
	if(buf_size > 0)
	{
		unsigned char *text = kmalloc(buf_size, GFP_KERNEL);
		read_size = queue_read(&g_dumpqueue, (void*)text, (int)buf_size);
		if(copy_to_user(buf, text, read_size)) {
			kfree(text);
			return -EFAULT;
		}
		kfree(text);
		return read_size;
	}
	// return -EAGAIN;
	return 0;
}
示例#16
0
bool_e VisionCamFrameManager::Unlock(VisionCamFrame*, OperationLock_t lock)
{
    bool_e ret = false_e;
    FrameQueueNode_t *fNode = NULL;
    if( fr && qFrames )
    {
        while( queue_length(qFrames) )
        {
            queue_read(qFrames, false_e, fNode);

            if( fNode && fNode->frame == fr )
            {
                fNode->lock ^= lock;
                ret = true_e;
            }
        }
    }
    return ret;
}
示例#17
0
/**
 * def read(self, mask)
 */
static mp_obj_t class_queue_read(mp_obj_t self_in, mp_obj_t size_in)
{
    struct class_queue_t *self_p;
    vstr_t vstr;
    size_t size;

    self_p = MP_OBJ_TO_PTR(self_in);
    size = mp_obj_get_int(size_in);
    vstr_init_len(&vstr, size);

    size = queue_read(&self_p->queue, vstr.buf, size);

    if (size <= 0) {
        nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
                                           "failed to read from queue"));
    }

    return (mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr));
}
示例#18
0
文件: thread.c 项目: aosp/dvp
static thread_ret_t thread_test_msgs(void *arg)
{
    msg_thread_t *msgt = (msg_thread_t *)arg;
    msg_t msg;
    event_set(&msgt->signal);
    while (msgt->running)
    {
        //SOSAL_PRINT(SOSAL_ZONE_THREAD, "Waiting for queue read!\n");
        if (queue_read(msgt->msgs, true_e, &msg))
        {
            //SOSAL_PRINT(SOSAL_ZONE_THREAD, "Msg: %u\n", msg.code);
            if (msg.code == (value_t)TEST_RET_VALUE)
                msgt->running = false_e;
        }
        else
        {
            SOSAL_PRINT(SOSAL_ZONE_THREAD, "ERROR! Failed to read from queue!\n");
            msgt->running = false_e;
        }
    }
    return (thread_ret_t)msg.code;
}
示例#19
0
文件: USB.cpp 项目: BitMax/openitg
bool WindowsFileIO::Open(CString path, int blocksize_)
{
	LOG->Trace( "WindowsFileIO::open(%s)", path.c_str() );
	blocksize = blocksize_;

	if(buf)
		delete[] buf;
	buf = new char[blocksize];

	if(h != INVALID_HANDLE_VALUE)
		CloseHandle (h);

	h = CreateFile (path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
		NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);

	if(h == INVALID_HANDLE_VALUE)
		return false;

	queue_read();

	return true;
}
示例#20
0
文件: USB.cpp 项目: BitMax/openitg
int WindowsFileIO::finish_read(void *p)
{
	LOG->Trace("this %p, %p", this, p);
	/* We do; get the result.  It'll go into the original buf
	 * we supplied on the original call; that's why buf is a
	 * member instead of a local. */
    unsigned long cnt;
    int ret = GetOverlappedResult(h, &ov, &cnt, FALSE);

    if(ret == 0 && (GetLastError() == ERROR_IO_PENDING || GetLastError() == ERROR_IO_INCOMPLETE))
		return -1;

	queue_read();

	if(ret == 0)
	{
		LOG->Warn(werr_ssprintf(GetLastError(), "Error reading Pump pad"));
	    return -1;
    }

	memcpy( p, buf, cnt );
	return cnt;
}
示例#21
0
size_t nrf_queue_out(nrf_queue_t const * p_queue,
                     void              * p_data,
                     size_t              element_count)
{
    ASSERT(p_queue != NULL);
    ASSERT(p_data != NULL);

    if (element_count == 0)
    {
        return 0;
    }

    CRITICAL_REGION_ENTER();

    size_t utilization = queue_utilization_get(p_queue);
    element_count      = MIN(element_count, utilization);

    queue_read(p_queue, p_data, element_count);

    CRITICAL_REGION_EXIT();

    return element_count;
}
示例#22
0
文件: io.c 项目: darcyg/chaosircd
/* ------------------------------------------------------------------------ *
 * Read either from the fd directly or from its queue.                      *
 * ------------------------------------------------------------------------ */
int io_read(int fd, void *buf, size_t n)
{
  /* Catch invalid arguments */
  if(fd < 0) return -1;
  if(n == 0) return 0;

  /* fd is queued, read from the receive queue */
  if(io_list[fd].control.recvq)
  {
    /* Receive queue is empty */
    if(io_list[fd].recvq.size == 0)
    {
      syscall_errno = EAGAIN;
      return -1;
    }

    return queue_read(&io_list[fd].recvq, buf, n);
  }

  /* Read directly from fd */
  switch(io_list[fd].type)
  {
    case FD_SOCKET:
#ifdef HAVE_SSL
      if(io_list[fd].ssl)
        return ssl_read(fd, buf, IO_READ_SIZE);
      else
#endif
      return syscall_recv(fd, buf, n, 0);
    default:
    case FD_FILE:
    case FD_PIPE:
      return syscall_read(fd, buf, n);
  }

  return -1;
}
示例#23
0
// Put a file from the disk into the cache.  Synchronization required.
int put_cache(char* filename, char* data, int size) {

	cache_entry_t* entry = (cache_entry_t*)malloc(sizeof(cache_entry_t));
	
	// copy the filename to make sure that we own it.
	entry->filename = (char*)malloc( MAX_REQUEST * sizeof(char) );
	strncpy( entry->filename, filename, MAX_REQUEST );
	
	// do not copy data. the user of cache is responsible for it.
	entry->filedata = data;
	entry->file_size = size;
	
	
	while(queue_write(&cache_queue, entry) == -1) {
		fprintf(stderr, "Cache is full\n" );
		// remove an item from the queue (oldest/LRU)
		cache_entry_t* cached = queue_read(&cache_queue);
		// clean up cache entry.
		free( cached->filedata );
		free( cached->filename );
		free( cached );
	}
	return 0;
}
示例#24
0
    void handle_read(PacketFrom *tunfrom, const boost::system::error_code& error, const size_t bytes_recvd)
    {
      OPENVPN_LOG_TUN_VERBOSE("TunIO::handle_read: " << error.message());
      typename PacketFrom::SPtr pfp(tunfrom);
      if (!halt)
	{
	  if (!error)
	    {
	      pfp->buf.set_size(bytes_recvd);
	      stats->inc_stat(SessionStats::TUN_BYTES_IN, bytes_recvd);
	      stats->inc_stat(SessionStats::TUN_PACKETS_IN, 1);
	      if (!tun_prefix)
		{
		  read_handler->tun_read_handler(pfp);
		}
	      else if (pfp->buf.size() >= 4)
		{
		  // handle tun packet prefix, if enabled
		  pfp->buf.advance(4);
		  read_handler->tun_read_handler(pfp);
		}
	      else
		{
		  OPENVPN_LOG_TUN_ERROR("TUN Read Error: cannot read prefix");
		  tun_error(Error::TUN_READ_ERROR, NULL);
		}
	    }
	  else
	    {
	      OPENVPN_LOG_TUN_ERROR("TUN Read Error: " << error.message());
	      tun_error(Error::TUN_READ_ERROR, &error);
	    }
	  if (!halt)
	    queue_read(pfp.release()); // reuse buffer if still available
	}
    }
示例#25
0
文件: main.c 项目: TheJoris/Gillespie
/**
  Load data from files and initialize program.
*/
int start()
{
  int  i,Ncomp,Nqueue;
  double tau_equi, tau_prod;
  long steps_equi, steps_prod;
  char *dummy;
  dummy = (char*) malloc(40);
  FILE *fp;

  // load general information from Gillespie.inp
  if( (fp = fopen("Gillespie.inp","r")) == NULL ) 
  {
    printf("Cannot open Gillespie.inp.\n");
    abort();
  }
  
  // read the information
  sys.name = calloc( MAXNAMELENGTH, sizeof(char) );
  fscanf( fp, "%s%*s", sys.name ); 
  fscanf( fp, "%d%*s", &sys.Ncomp );
  fscanf( fp, "%d%*s", &sys.Nreact );
  fscanf( fp, "%ld\t%ld\t%ld%*s", &steps_equi, &steps_prod, &sys.stats_steps );
  fscanf( fp, "%lg%*s", &sys.dt );
  fscanf( fp, "%lg\t%lg%*s", &tau_equi, &tau_prod );
  fscanf( fp, "%lg\t%lg%*s", &sys.doubling_time, &sys.doubling_time_std );
  
  // convert the number of blocks, which the calculation should run, into steps
  // or set it to the maximum number, when it should be neglected
  if( steps_equi < 0 )
    steps_equi = LONG_MAX;
  else
    steps_equi *= sys.stats_steps;

  if( steps_prod < 0 )
    steps_prod = LONG_MAX;
  else
    steps_prod *= sys.stats_steps;
  
  // ignore negative times
  if( tau_equi < 0 )
    tau_equi = INF_POS;
  if( tau_prod < 0 )
    tau_prod = INF_POS;
  
  // close file
  fclose(fp);

  printf("===============================================================================\n");
  printf("This program propagates the chemical master equation according\n");
  printf("to the Gillespie-algorithm.\n");
/*  printf("Log book information.\n\n");
  if (!(log_init(sys.name,TRUE)==0))
    printf("No log book information could be obtained.\n");*/
  printf("-------------------------------------------------------------------------------\n");
  printf("System parameters.\n\n");
  printf("Name of the run                   %8s\n",sys.name);
  printf("Number of components              %8d\n",sys.Ncomp);
  printf("Number of reaction channels       %8d\n",sys.Nreact);
/*  printf("Number of equilibrium blocks      %8d\n",*n_blk_eq);
  printf("Number of production  blocks      %8d\n",*n_blk_run);
  printf("Number of steps per block         %8d\n",*n_steps);*/
  printf("Timesteps of writeout             %8f\n",sys.dt);
  printf("Total time(steps) of equilibrium run     %8f (%ld)\n",tau_equi,steps_equi);
  printf("Total time(steps) of production run      %8f (%ld)\n",tau_prod,steps_prod);
  if( HAS_GROWTH )
  {
    printf( "Doubling time                     %8f +- %8f\n", sys.doubling_time, sys.doubling_time_std );
  }

  // use this information to allocate memory and read in components and reactions

  allocate_memory();
  read_components();
  read_reactions();
  get_reaction_network();
  
  // check, if the state of the system has to be loaded from a file
  if( sys.input != NULL )
  {
    printf( "Load initial state of the system from '%s'...\n", sys.input );
    
    if( (fp = fopen(sys.input, "r")) == NULL) 
    {
      printf("The file '%s' could not be opened\n", sys.input);
      return EXIT_FAILURE;
    }
    
    fscanf( fp, "%lg\t%d\t%d\t%lg\t%*s", 
            &sys.tau_init, &Ncomp, &Nqueue, &sys.last_division 
          );
    if( Ncomp != sys.Ncomp )
    {
      printf("The number of components do not match (%d in the definition and %d in the state)\n",sys.Ncomp,Ncomp);
      return EXIT_FAILURE;
    }
    
    for( i=0; i<Ncomp; i++ )
    {
      fscanf( fp, "%d\t%s", &X[i], dummy );
    }
    
    queue_read( fp, Nqueue, sys.tau_init );
    
    fclose( fp );
  }
  else
  {
    sys.tau_init = 0; // initialize values, which are loaded from file otherwise
  }
  
  // print the chemical system that will be investigated
  if( sys.output_stats )
    print_reactions( FALSE );
  print_initial_conditions();
  
  if( HAS_GROWTH )
  {
	printf("the system has GROWTH \n");
    if( sys.growth_type == GROWTH_LINEAR )
    {
      fprintf( stderr, "Growth is linear\n" );
      if( isnan( sys.last_division ) )
      {
        // set last_division such that volume(0)=1.
        sys.last_division = sys.tau_init - 0.5*sys.doubling_time;
      }
    }
    else if ( sys.growth_type == GROWTH_EXPONENTIAL )
    {
      fprintf( stderr, "Growth is exponential\n" );
      if( isnan( sys.last_division ) )
      {
        // set last_division such that volume(0)=1.
        sys.last_division = sys.tau_init - 0.528766*sys.doubling_time;
        // 0.528766 == -log(log(2))/log(2)
      }
    }
    else
    {
      printf( "Unknown growth type `%d`", sys.growth_type );
      abort();
    }
  }
  
  if( sys.output_conc == OUTPUT_AUTOMATIC )
  {
    if( HAS_GROWTH )
      sys.output_conc = OUTPUT_CONCENTRATION;
    else 
      sys.output_conc = OUTPUT_COPYNUMBER;
  }
  
  if( sys.output_conc == OUTPUT_CONCENTRATION )
  {
    fprintf( stderr, "Output data are concentrations (mean volume = 1).\n" );
  }
  else
  {
    fprintf( stderr, "Output data is copynumbers.\n" );
  }
  
  printf( "===============================================================================\n" );
  
  // run some steps to reach equilibrium 
  if( tau_equi > 0 )
  {
    printf( "Start equilibrium run...\n" );
    run( EQUIL, tau_equi, steps_equi );
  }
  
  // do actual run
  if( tau_prod > 0 )
  {
    printf( "Start production run...\n" );
    run( RUN, tau_prod, steps_prod );
  }
  
  return EXIT_SUCCESS;
}
示例#26
0
文件: libero.c 项目: dosuser/libero2
gpointer safe_dequeue(gqueue *queue){
	gpointer *node;
	queue_read(queue,(gpointer *)&node);
	if(node!=NULL) dlog(0,"dequeue\n");
	return node;
}