Exemple #1
0
void* producer(void* ptr)
{
    Buffer* buf = (Buffer*)ptr;
    while (1) {
        int slot = write_start(buf);
        if (slot == -1) {
            printf(ANSI_GREEN"producer: no free space left in queue...waiting"ANSI_NORMAL"\n");
            buffer_print(buf);
            exit(-1);
            usleep(producer_delay);
            continue;
        }
        
        //printf(ANSI_GREEN"producer: slot %d"ANSI_NORMAL"\n", slot);
        buffer_print(buf);
        usleep(produce_duration);
        write_done(buf);
        buffer_print(buf);
    }

    return 0;
}
Exemple #2
0
/* Write the specified number of bytes from the buffer buf to a given NFS file */
void
nfsfs_write(pid_t pid, VNode self, fildes_t file, L4_Word_t offset,
		const char *buf, size_t nbyte, void (*write_done)(pid_t pid, VNode self,
			fildes_t file, L4_Word_t offset, const char *buf, size_t nbyte, int status)) {
	dprintf(1, "*** nfsfs_write: %p, %d, %d, %p, %d\n", self, file, offset, buf, nbyte);

	NFS_File *nf = (NFS_File *) self->extra;	
	if (nf == NULL) {
		dprintf(0, "!!! nfsfs_write: Invalid NFS file (p %d, f %d), no nfs struct!\n",
				pid, file);
		write_done(pid, self, file, offset, buf, 0, SOS_VFS_NOFILE);
		return;
	}

	NFS_WriteRequest *rq = (NFS_WriteRequest *) create_request(RT_WRITE, self, pid);
	rq->file = file;
	rq->buf = (char *) buf;
	rq->offset = offset;
	rq->nbyte = nbyte;
	rq->write_done = write_done;

	check_request((NFS_BaseRequest *) rq);
}
Exemple #3
0
void *aio_completion_handler (void *thread_data)
{
    struct io_event events[AIO_MAXIO];
    struct io_queue *this_io;
    int num, i;
    struct __arc_object *obj;
    while (1)
      {
	  num = io_getevents (ioctx, 1, AIO_MAXIO, events, NULL);
	  if (should_stop)
	      break;
	  //      lfs_printf("\n%d io_request completed\n\n", num);

	  for (i = 0; i < num; i++)
	    {
		this_io = (struct io_queue *) events[i].data;

		if (events[i].res2 != 0)
		  {
		      lfs_printf ("aio write error \n");
		  }
		if (events[i].obj != &this_io->iocb)
		  {
		      lfs_printf ("iocb is lost \n");
		      exit (1);
		  }
		if (events[i].res != this_io->iocb.u.c.nbytes)
		  {
		      lfs_printf
			  ("rw missed bytes expect % ld,got % ld res2=%d \n",
			   this_io->iocb.u.c.nbytes, events[i].res,
			   events[i].res2);
		      // exit (1);
		  }
		if (this_io->item->fops == READ_COMMAND)
		  {
		      obj = this_io->item->obj;
		      arc_read_done (obj);
		      printf ("whats up");
		  }
		else if (this_io->item->fops == WRITE_COMMAND)
		  {

		      write_done (this_io->item, LFS_SUCCESS);
		  }
	    }

	  pthread_mutex_lock (&IOCBQ_MUTEX);

	  for (i = 0; i < num; i++)
	    {
		this_io = (struct io_queue *) events[i].data;
		this_io->ref_cnt = 0;
	    }
	  pthread_mutex_unlock (&IOCBQ_MUTEX);

      }

    should_stop = 1;
    pthread_exit (NULL);
}