コード例 #1
0
ファイル: console.c プロジェクト: ismaellc/SOTR
int
consoleread(struct inode *ip, char *dst, int n)
{
  uint target;
  int c;

  iunlock(ip);
  target = n;
  acquire(&input.lock);
  while(n > 0){
    while(input.r == input.w){
      if(proc->killed){
        release(&input.lock);
        ilock(ip);
        return -1;
      }
      sleep(&input.r, &input.lock);
    }
    c = input.buf[input.r++ % INPUT_BUF];
    if(c == C('D')){  // EOF
      if(n < target){
        // Save ^D for next time, to make sure
        // caller gets a 0-byte result.
        input.r--;
      }
      break;
    }
    *dst++ = c;
    --n;
    if(c == '\n')
      break;
  }
  release(&input.lock);
  ilock(ip);

  return target - n;
}
コード例 #2
0
ファイル: proc.c プロジェクト: jahandideh-iman/XV6_Scheduling
// Exit the current process.  Does not return.
// An exited process remains in the zombie state
// until its parent calls wait() to find out it exited.
void exit(void) {
	struct proc *p;
	int fd;

	if (proc == initproc)
		panic("init exiting");

	// Close all open files.
	for (fd = 0; fd < NOFILE; fd++) {
		if (proc->ofile[fd]) {
			fileclose(proc->ofile[fd]);
			proc->ofile[fd] = 0;
		}
	}

	iput(proc->cwd);
	proc->cwd = 0;

	acquire(&ptable.lock);

	// Parent might be sleeping in wait().
	wakeup1(proc->parent);

	// Pass abandoned children to init.
	for (p = ptable.proc; p < &ptable.proc[NPROC]; p++) {
		if (p->parent == proc) {
			p->parent = initproc;
			if (p->state == ZOMBIE)
				wakeup1(initproc);
		}
	}

	// Jump into the scheduler, never to return.
	proc->state = ZOMBIE;
	sched();
	panic("zombie exit");
}
コード例 #3
0
ファイル: proc.c プロジェクト: Succubuster/cosc301-proj04
// Grow current process's memory by n bytes.
// Return 0 on success, -1 on failure.
int
growproc(int n)
{
  uint sz;
  acquire(&ptable.lock);
  sz = proc->sz;
  if(n > 0){
    if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0){
			release(&ptable.lock);
      return -1;
		}
  } else if(n < 0){
    if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0) {
			release(&ptable.lock);
      return -1;
		}
  }
  proc->sz = sz;


	struct proc *p; //looping thru ptable to change szs -KC
	for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
		//calling process is a thread, change parent and siblings
		if (  (proc->isThread == 1) && (p == proc->parent || 
		p->parent == proc->parent)  ) {
			p->sz = sz;			
		}
		//calling process is a process, change child threads
		else if (proc->isThread == 0 && p->parent == proc) {
			p->sz = sz;
		}
	}

  release(&ptable.lock);
  switchuvm(proc);
  return 0;
}
コード例 #4
0
ファイル: proc.c プロジェクト: yonatana/OS
void 
thread_exit(void * ret_val){
  acquire(&ptable.lock);
  
  if(proc->is_thread){//not the main procces
    if(proc->parent->num_of_thread_child==1){//the main thread already thread_exit and also all other thread
      proc->parent->num_of_thread_child--;
      release(&ptable.lock);
      exit();
    }
    
    
  //this is not the last thread by any mean
    proc->ret_val = ret_val;			// not main thread and not the last one
    proc->parent->num_of_thread_child--;
    proc->state = ZOMBIE;
    if(proc->thread_joined){
      wakeup1(proc);
    }
    sched();
    release(&ptable.lock);
  }
    
  else if (proc->num_of_thread_child == 1){//this is the main thread and it is the last thread
    proc->num_of_thread_child--;
    release(&ptable.lock);
    exit();
  }
  
  
  else{//this is the main thread but other thread are alive
    proc->num_of_thread_child--;
    proc->state = ZOMBIE;
    sched();
    release(&ptable.lock);
  }
}
コード例 #5
0
ファイル: file.c プロジェクト: aryx/fork-xv6
// Close file f.  (Decrement ref count, close when reaches 0.)
void
fileclose(struct file *f)
{
  struct file ff;

  acquire(&file_table_lock);
  if(f->ref < 1 || f->type == FD_CLOSED)
    panic("fileclose");
  if(--f->ref > 0){
    release(&file_table_lock);
    return;
  }
  ff = *f;
  f->ref = 0;
  f->type = FD_CLOSED;
  release(&file_table_lock);
  
  if(ff.type == FD_PIPE)
    pipeclose(ff.pipe, ff.writable);
  else if(ff.type == FD_INODE)
    iput(ff.ip);
  else
    panic("fileclose");
}
コード例 #6
0
ファイル: proc.c プロジェクト: zzddhhtjzz/xv6
// Grow current process's memory by n bytes.
// Return 0 on success, -1 on failure.
int
growproc(int n)
{
  uint sz;
  
  sz = proc->sz;
  if(n > 0){
    if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0)
      return -1;
  } else if(n < 0){
    if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0)
      return -1;
  }
  proc->sz = sz;
  struct proc *p;
  acquire(&ptable.lock);
  for(p=ptable.proc; p<&ptable.proc[NPROC]; p++){
    if(p->parent!=proc || 1==p->thread)
     p->sz = sz;
  }
  release(&ptable.lock);
  switchuvm(proc);
  return 0;
}
コード例 #7
0
ファイル: proc.c プロジェクト: qsheridan/cosc301-proj04
// Grow current process's memory by n bytes.
// Return 0 on success, -1 on failure.
int
growproc(int n)
{
    acquire(&ptable.lock);
    uint sz;

    //struct proc* p;

    sz = proc->sz;

    if(n > 0) {
        if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0) {
            release(&ptable.lock);
            return -1;
        }
    } else if(n < 0) {
        if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0) {
            release(&ptable.lock);
            return -1;
        }
    }
    proc->sz = sz;
    if (proc->is_thread == 1) {
        proc = proc->parent;
        proc->sz = sz;
    }
    /*for(p = ptable.proc; p < &ptable.proc[NPROC]; p++) {
    if(p->parent == parent) {
    	proc->sz = sz;
    }
    }*/

    release(&ptable.lock);
    switchuvm(proc);
    return 0;
}
コード例 #8
0
ファイル: main.c プロジェクト: olivo/BP
int thr1() { //nsThread::Init (mozilla/xpcom/threads/nsThread.cpp 1.31)

  int PR_CreateThread__RES = 1;
  acquire(mStartLock);
  start_main=1;
#ifdef SATABS
  { __CPROVER_atomic_begin();
#else
  { __blockattribute__((atomic))
#endif
      if( __COUNT__ == 0 ) { // atomic check(0);
	mThread = PR_CreateThread__RES; 
	__COUNT__ = __COUNT__ + 1; 
      } else { assert(0); } 
#ifdef SATABS
  __CPROVER_atomic_end(); }
#else
  }
#endif
  release(mStartLock);
  if (mThread == 0) { return -1; }
  else { return 0; }

}
コード例 #9
0
ファイル: proc.c プロジェクト: Aarskin/CS537
// Grow current process's memory by n bytes.
// Return 0 on success, -1 on failure.
int
growproc(int n)
{
  uint sz;
  
  acquire(&ptable.lock);
  sz = proc->sz;
  if(n > 0){
    if((sz = allocuvm(proc->pgdir, sz, sz + n)) == 0)
      return -1;
  } else if(n < 0){
    if((sz = deallocuvm(proc->pgdir, sz, sz + n)) == 0)
      return -1;
  }
  proc->sz = sz;
  
  if(proc->thread) // reflect the changes in the parent as well
    proc->parent->sz = sz;
    
  release(&ptable.lock);
  
  switchuvm(proc);
  return 0;
}
コード例 #10
0
//PAGEBREAK: 40
int
pipewrite(struct pipe *p, char *addr, int n) {
	int i;

	acquire(&p->lock);

	for (i = 0; i < n; i++) {
		while (p->nwrite == p->nread + PIPESIZE) { //DOC: pipewrite-full
			if (p->readopen == 0 || proc->killed) {
				release(&p->lock);
				return -1;
			}

			wakeup(&p->nread);
			sleep(&p->nwrite, &p->lock);  //DOC: pipewrite-sleep
		}

		p->data[p->nwrite++ % PIPESIZE] = addr[i];
	}

	wakeup(&p->nread);  //DOC: pipewrite-wakeup1
	release(&p->lock);
	return n;
}
コード例 #11
0
ファイル: bio.c プロジェクト: caiolima/xv6-public
// Look through buffer cache for block on device dev.
// If not found, allocate a buffer.
// In either case, return B_BUSY buffer.
static struct buf*
bget(uint dev, uint blockno)
{
  struct buf *b;

  acquire(&bcache.lock);

 loop:
  // Is the block already cached?
  for(b = bcache.head.next; b != &bcache.head; b = b->next){
    if(b->dev == dev && b->blockno == blockno){
      if(!(b->flags & B_BUSY)){
        b->flags |= B_BUSY;
        release(&bcache.lock);
        return b;
      }
      sleep(b, &bcache.lock);
      goto loop;
    }
  }

  // Not cached; recycle some non-busy and clean buffer.
  // "clean" because B_DIRTY and !B_BUSY means log.c
  // hasn't yet committed the changes to the buffer.
  for(b = bcache.head.prev; b != &bcache.head; b = b->prev){
    if((b->flags & B_BUSY) == 0 && (b->flags & B_DIRTY) == 0){
      b->dev = dev;
      b->blockno = blockno;
      b->flags = B_BUSY;
      b->bsize = sb[dev].blocksize;
      release(&bcache.lock);
      return b;
    }
  }
  panic("bget: no buffers");
}
コード例 #12
0
ファイル: Preflowpush.cpp プロジェクト: nikunjy/parallelStuff
  void operator()(GNode& src, Galois::UserContext<GNode>& ctx) {
    if (version != nondet) {
      bool used = false;
      if (version == detDisjoint) {
        ctx.getLocalState(used);
      }
      if (!used) {
        acquire(src);
      }
      if (version == detDisjoint) {
        if (!used)
          return;
      } else {
        app.graph.getData(src, Galois::WRITE);
      }
    }

    int increment = 1;
    if (discharge(src, ctx)) {
      increment += BETA;
    }

    counter.accum += increment;
  }
コード例 #13
0
ファイル: atomic.cpp プロジェクト: alarouche/cppao
active::atomic_node * active::atomic_fifo::pop()
{
	atomic_node * t = acquire(output_queue, &busy);
	
	if( t==nullptr )
	{
		// Output queue is empty, so
		// reverse input_queue and assign it to output_queue
		
		atomic_node * old_input = input_queue.exchange(nullptr, std::memory_order_relaxed);
		atomic_node * result = nullptr;
		atomic_node * new_output = nullptr;
		if(old_input!=nullptr)
		{
			result = old_input;
			for(atomic_node * n=old_input; n!=nullptr;)
			{
				if( n->next )
				{
					result = n->next;
					n->next = new_output;
					new_output = n;
					n = result;
				}
				else break;
			}
		}
		release(output_queue, new_output);
		return result;
	}
	else
	{
		release(output_queue, t?t->next:nullptr);
		return t;
	}
}
コード例 #14
0
ファイル: proc.c プロジェクト: yonatana/OS
/*
 * this thread wants the semaphore
 * if its 0 then the thread does to sleep
 * else take it
 */
int 
binary_semaphore_down(int binary_semaphore_ID){
   
   struct binary_semaphore* sem = &sem_table.binary_semaphore[binary_semaphore_ID] ;
   acquire(&sem_table.sem_locks[binary_semaphore_ID]);
  
  
  
  //give the new thread a place in queue
  if(sem->waiting){
    proc->sem_queue_pos = ++(sem->waiting);
  }
  
  for(;;){
    if(sem->initialize){
      if(sem->value && !proc->sem_queue_pos){//the sem is not locked && the thread is the next one
	sem->value = 0;//sem is locked
	proc->wait_for_sem = -1;//done waiting 
	release(&sem_table.sem_locks[binary_semaphore_ID]);
	return 0;
      }
      else{//the sem is locked or this is this the first time for this thread
	  if(proc->sem_queue_pos<=0){
	    proc->sem_queue_pos = ++(sem->waiting);
	  }
	  proc->wait_for_sem = binary_semaphore_ID;
	  sleep(sem,&sem_table.sem_locks[binary_semaphore_ID]);
      }
    }
    else{
      cprintf("we had problem at binary_semaphore_down: the semaphore wasnt initialize\n"); 
      release(&sem_table.sem_locks[binary_semaphore_ID]);
      return -1;
    }
  }
}
コード例 #15
0
ファイル: fs.c プロジェクト: bitc/3
// Lock the given inode.
// Reads the inode from disk if necessary.
void
ilock(struct inode *ip)
{
  struct buf *bp;
  struct dinode *dip;

  if(ip == 0 || ip->ref < 1)
    panic("ilock");

  acquire(&icache.lock);
  while(ip->flags & I_BUSY)
    sleep(ip, &icache.lock);
  ip->flags |= I_BUSY;
  release(&icache.lock);

  if(!(ip->flags & I_VALID)){
    bp = bread(ip->dev, IBLOCK(ip->inum));
    dip = (struct dinode*)bp->data + ip->inum%IPB;
    ip->type = dip->type;
    ip->major = dip->major;
    ip->minor = dip->minor;
    ip->nlink = dip->nlink;
    ip->size = dip->size;
    memmove(ip->addrs, dip->addrs, sizeof(ip->addrs));
/*vvv  TASK 1.1  vvv*/
    ip->indirect2 = dip->indirect2;
/*^^^^^^^^^^^^^^^^^^*/
/*vvv  TASK 2    vvv*/
    memmove(ip->password, dip->password, sizeof(ip->password));
/*^^^^^^^^^^^^^^^^^^*/
    brelse(bp);
    ip->flags |= I_VALID;
    if(ip->type == 0)
      panic("ilock: no type");
  }
}
コード例 #16
0
ファイル: proc.c プロジェクト: RickyV33/XV6-Operating-System
void
scheduler(void){
    //struct proc *p;
    
    int i;
    struct proc *p;

    for(;;){
        // Enable interrupts on this processor.
        sti();
        acquire(&ptable.lock);
        for (i = 0; i < SIZE; ++i) { 
            if (ptable.readyList[i] == 0)
                continue;
            p = ptable.readyList[i];
            removeFromReadyList(p, p->priority);
            // Set it back to priority 0 (increments at the end of loop)
            if (i != 2)
                i = -1;
            //Decrement counter
            --ptable.timeToReset;
            if (ptable.timeToReset == 0) {
                //cprintf("Reseting list\n");
                resetReadyList();
                ptable.timeToReset = COUNT;
            }
            proc = p;
            switchuvm(p);
            p->state = RUNNING;
            swtch(&cpu->scheduler, proc->context);
            switchkvm();
            proc = 0;
        }
        release(&ptable.lock);
    }
}
コード例 #17
0
ファイル: proc.c プロジェクト: zzddhhtjzz/xv6
//The is the join syscall iplementation
int 
join(int threadId, void** stack)
{
  struct proc *p;
  int hasChild;
  int pid;
  acquire(&ptable.lock);
  for(;;){
    hasChild = 0;
    for(p=ptable.proc; p<&ptable.proc[NPROC]; p++){
      if(p->parent != proc || 0==p->thread)
    	continue;
      hasChild = 1;
      
      if(p->state == ZOMBIE && p->pid == threadId){
        pid = p->pid;
    	kfree(p->kstack);
 	p->kstack = 0;
	p->state = UNUSED;
 	p->parent = 0;
	p->pid = 0;
	p->name[0] = 0;
 	p->killed = 0;
	p->thread = 0;
	release(&ptable.lock);
	*stack = p->ustack;
	return pid; 
      } 
    }
    if(hasChild==0 || proc->killed==1){
      release(&ptable.lock);
      return -1;
    }
    sleep(proc, &ptable.lock);
  }
}
コード例 #18
0
ファイル: proc.c プロジェクト: byan23/OprSys
// Kill the process with the given pid.
// Process won't exit until it returns
// to user space (see trap in trap.c).
int
kill(int pid)
{
  //cprintf("kill pid: %d\n", proc->pid);
  struct proc *p;
  int slot_no = -1;
  acquire(&ptable.lock);
  for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){
    ++slot_no;
    if(p->pid == pid){
      p->killed = 1;
      // remove from queue
      //int pri = pstat.pri
      //switch()
      // Wake process from sleep if necessary.
      if(p->state == SLEEPING)
	p->state = RUNNABLE;
      release(&ptable.lock);
      return 0;
    }
  }
  release(&ptable.lock);
  return -1;
}
コード例 #19
0
ファイル: p41.c プロジェクト: dmitrymakhnin/Study
int
main(int argc, char *argv[]){
  int             numb_tries,i = 5;
  unsigned int    sleep_time;
  char            *fname;
  void            set_defaults(int, char *[], int *, unsigned *, char **);
  enum boolean         acquire(char *, int, unsigned);
  enum boolean         release(char *);
  /*
	Assign values
  */
  set_defaults(argc, argv, &numb_tries, &sleep_time, &fname);
  						/* Obtain lock file	*/
  if (acquire(fname, numb_tries, sleep_time)) {
    while (i--) {
      printf("%d  %d \n", getpid(), i);			/* Use resource	*/
      sleep(sleep_time);
    }
    release(fname);				/* Remove lock file	*/
    return 0;
  } else
    printf(" %d Unable to obtain lock file after %d tries. \n", getpid(), numb_tries);
    return 1;
}
コード例 #20
0
ファイル: join.c プロジェクト: AllenDou/linuxthreads
int pthread_detach(pthread_t thread_id)
{
  int terminated;
  struct pthread_request request;
  pthread_handle handle = thread_handle(thread_id);
  pthread_descr th;

  acquire(&handle->h_spinlock);
  if (invalid_handle(handle, thread_id)) {
    release(&handle->h_spinlock);
    return ESRCH;
  }
  th = handle->h_descr;
  /* If already detached, error */
  if (th->p_detached) {
    release(&handle->h_spinlock);
    return EINVAL;
  }
  /* If already joining, don't do anything. */
  if (th->p_joining != NULL) {
    release(&handle->h_spinlock);
    return 0;
  }
  /* Mark as detached */
  th->p_detached = 1;
  terminated = th->p_terminated;
  release(&handle->h_spinlock);
  /* If already terminated, notify thread manager to reclaim resources */
  if (terminated && __pthread_manager_request >= 0) {
    request.req_thread = thread_self();
    request.req_kind = REQ_FREE;
    request.req_args.free.thread = th;
    write(__pthread_manager_request, (char *) &request, sizeof(request));
  }
  return 0;
}
コード例 #21
0
ファイル: fs.c プロジェクト: gaohannk/xv6-system
// Lock the given inode.
// Reads the inode from disk if necessary.
void
ilock(struct inode *ip)
{
  struct buf *bp;
  struct dinode *dip;

  if(ip == 0 || ip->ref < 1)
    panic("ilock");

  acquire(&icache.lock);
  while(ip->flags & I_BUSY)
    sleep(ip, &icache.lock);
  ip->flags |= I_BUSY;
  release(&icache.lock);

  if(!(ip->flags & I_VALID)){
    bp = bread(ip->dev, IBLOCK(ip->inum, sb));
    dip = (struct dinode*)bp->data + ip->inum%IPB;
    ip->type = dip->type;
    ip->major = dip->major;
    ip->minor = dip->minor;
    ip->nlink = dip->nlink;
    ip->size = dip->size;

    // Read ownership permissions into memory
    ip->ownerId = dip->ownerId;
    ip->groupId = dip->groupId;
    ip->mode = dip->mode;

    memmove(ip->addrs, dip->addrs, sizeof(ip->addrs));
    brelse(bp);
    ip->flags |= I_VALID;
    if(ip->type == 0)
      panic("ilock: no type");
  }
}
コード例 #22
0
 scoped_lock( mutex_type& m, bool is_writer ) : my_mutex(NULL) {
     acquire(m,is_writer);
 }
コード例 #23
0
 scoped_lock( mutex_type& m ) : my_mutex(NULL) {
     acquire(m);
 }
コード例 #24
0
ファイル: ineptxyreftancp.c プロジェクト: timburrow/OpenVnmrJ
pulsesequence() {

// Define Variables and Objects and Get Parameter Values

   CP hy = getcp("HY",0.0,0.0,0,1);
   strncpy(hy.fr,"dec",3);
   strncpy(hy.to,"dec2",4);
   putCmd("frHY='dec'\n");
   putCmd("toHY='dec2'\n");

   GP inept = getinept("ineptYX");
   strncpy(inept.ch1,"dec2",4);
   strncpy(inept.ch2,"obs",3);
   putCmd("ch1YXinept='dec2'\n");
   putCmd("ch2YXinept='obs'\n");
   
   DSEQ dec = getdseq("H");
   strncpy(dec.t.ch,"dec",3);
   putCmd("chHtppm='dec'\n"); 
   strncpy(dec.s.ch,"dec",3);
   putCmd("chHspinal='dec'\n");

   DSEQ mix = getdseq("Hmix");
   strncpy(mix.t.ch,"dec",3);
   putCmd("chHmixtppm='dec'\n"); 
   strncpy(mix.s.ch,"dec",3);
   putCmd("chHmixspinal='dec'\n");

// Dutycycle Protection

   double simpw1 = inept.pw1;
   if (inept.pw2 > inept.pw1) simpw1 = inept.pw2;

   double simpw2 = inept.pw3;
   if (inept.pw4 > inept.pw3) simpw2 = inept.pw4;

   DUTY d = init_dutycycle();
   d.dutyon = getval("pwH90") + getval("tHY") + 2.0*simpw1 + 2.0*simpw2;
   d.dutyoff = d1 + 4.0e-6;
   d.c1 = d.c1 + (!strcmp(dec.seq,"tppm"));
   d.c1 = d.c1 + ((!strcmp(dec.seq,"tppm")) && (dec.t.a > 0.0));
   d.t1 = inept.t1 + inept.t2 + inept.t3 + inept.t4 + 
          getval("rd") + getval("ad") + at;
   d.c2 = d.c2 + (!strcmp(dec.seq,"spinal"));
   d.c2 = d.c2 + ((!strcmp(dec.seq,"spinal")) && (dec.s.a > 0.0));
   d.t2 = inept.t1 + inept.t2 + inept.t3 + inept.t4 + 
          getval("rd") + getval("ad") + at;
   d = update_dutycycle(d);
   abort_dutycycle(d,10.0);

// Set Phase Tables

   settable(phH90,16,table1);
   settable(phHhy,4,table2);
   settable(phYhy,4,table3);
   settable(ph1Yyxinept,4,table4);
   settable(ph1Xyxinept,4,table5);
   settable(ph2Yyxinept,4,table6);
   settable(ph2Xyxinept,16,table7);
   settable(ph3Yyxinept,8,table8);
   settable(ph3Xyxinept,4,table9);
   settable(phRec,8,table10);
   setreceiver(phRec);

// Begin Sequence

   txphase(ph1Xyxinept); decphase(phH90); dec2phase(phYhy);
   obspwrf(getval("aXyxinept")); decpwrf(getval("aH90")); dec2pwrf(getval("aYhy"));
   obsunblank(); decunblank(); _unblank34();
   delay(d1);
   sp1on(); delay(2.0e-6); sp1off(); delay(2.0e-6);

// H to Y Cross Polarization

   decrgpulse(getval("pwH90"),phH90,0.0,0.0);
   decphase(phHhy);
   _cp_(hy,phHhy,phYhy);
   decphase(zero);

// INEPT Transfer from Y to X

   _dseqon(mix);
   _ineptref(inept,ph1Yyxinept,ph1Xyxinept,ph2Yyxinept,ph2Xyxinept,ph3Yyxinept,ph3Xyxinept);
   _dseqoff(mix);

// Begin Acquisition

   _dseqon(dec);
   obsblank(); _blank34();
   delay(getval("rd"));
   startacq(getval("ad"));
   acquire(np, 1/sw);
   endacq();
   _dseqoff(dec);
   obsunblank(); decunblank(); _unblank34();
}
コード例 #25
0
ファイル: lockfile.C プロジェクト: Sidnicious/sfslite
lockfile::~lockfile ()
{
  if (fdok () && (islocked || acquire (false)))
    unlink (path.cstr());
  closeit ();
}
コード例 #26
0
ファイル: trap.c プロジェクト: ProkofievDmitriy/ass2
//PAGEBREAK: 41
void
trap(struct trapframe *tf)
{
  if(tf->trapno == T_SYSCALL){
    if(proc->killed)
      exit();
    proc->tf = tf;
    syscall();

    if(proc->killed)
      exit();
    return;
  }

  switch(tf->trapno){
  case T_IRQ0 + IRQ_TIMER:
    if(cpu->id == 0){
      acquire(&tickslock);
      ticks++;
      updateProcTimes(); // UPDATE EACH PROCESS TIME COUNTERS
      wakeup(&ticks);
      release(&tickslock);
    }
    lapiceoi();
    break;
  case T_IRQ0 + IRQ_IDE:
    ideintr();
    lapiceoi();
    break;
  case T_IRQ0 + IRQ_IDE+1:
    // Bochs generates spurious IDE1 interrupts.
    break;
  case T_IRQ0 + IRQ_KBD:
    kbdintr();
    lapiceoi();
    break;
  case T_IRQ0 + IRQ_COM1:
    uartintr();
    lapiceoi();
    break;
  case T_IRQ0 + 7:
  case T_IRQ0 + IRQ_SPURIOUS:
    cprintf("cpu%d: spurious interrupt at %x:%x\n",
            cpu->id, tf->cs, tf->eip);
    lapiceoi();
    break;
   
  //PAGEBREAK: 13
  default:
    if(proc == 0 || (tf->cs&3) == 0){
      // In kernel, it must be our mistake.
      cprintf("unexpected trap %d from cpu %d eip %x (cr2=0x%x)\n",
              tf->trapno, cpu->id, tf->eip, rcr2());
      panic("trap");
    }
    // In user space, assume process misbehaved.
    cprintf("pid %d %s: trap %d err %d on cpu %d "
            "eip 0x%x addr 0x%x--kill proc\n",
            proc->pid, proc->name, tf->trapno, tf->err, cpu->id, tf->eip, 
            rcr2());
    proc->killed = 1;
  }

  // Force process exit if it has been killed and is in user space.
  // (If it is still executing in the kernel, let it keep running 
  // until it gets to the regular system call return.)
  if(proc && proc->killed && (tf->cs&3) == DPL_USER)
    exit();

  // Force process to give up CPU on clock tick. --- IF FCFS POLICY DONT GIVEUP CPU
  // If interrupts were on while locks held, would need to check nlock.
#ifndef FCFS
  if(proc && proc->state == RUNNING && tf->trapno == T_IRQ0+IRQ_TIMER && (ticks % QUANTA)==0)
    yield();
#endif

// Check if the process has been killed since we yielded
  if(proc && proc->killed && (tf->cs&3) == DPL_USER)
    exit();
}
コード例 #27
0
 void acquire_ownership_once(Callable && acquire) {
    if(!m_owned) {
       acquire();
       m_owned = true;
    }
 }
コード例 #28
0
ファイル: Builder.cpp プロジェクト: AndreLouisCaron/cxxpy
 ModuleBuilder::ModuleBuilder ( const Bytes& name )
     : Module(acquire(::Py_InitModule(name.data(), NO_MODULE_METHODS)))
 {
 }
コード例 #29
0
ファイル: Builder.cpp プロジェクト: AndreLouisCaron/cxxpy
 Map ClassBuilder::symbols () const
 {
     return (Map(acquire(::getclasssymbols(handle()))));
 }
コード例 #30
0
ファイル: Builder.cpp プロジェクト: AndreLouisCaron/cxxpy
 ClassBuilder::ClassBuilder ( const Bytes& name, const Map& symbols )
     : Object(acquire(::PyClass_New(0, symbols.handle(), name.handle())))
 {
 }