示例#1
0
struct cached_block *
lookup_cache (block_sector_t sector)
{
  struct cached_block *cb;
  struct list_elem *e;

  for (e = list_begin(&cache_list); e != list_end(&cache_list);
       e = list_next(e))
    {
      cb = list_entry(e, struct cached_block, elem);
      if (cb->sector == sector)
	{
	  return cb;
	}
    }
  return NULL;
}
示例#2
0
/* Returns the file descriptor associated with the given handle.
   Terminates the process if HANDLE is not associated with an
   open file. */
static struct file_descriptor *
lookup_fd (int handle) 
{
  struct thread *cur = thread_current ();
  struct list_elem *e;
   
  for (e = list_begin (&cur->fds); e != list_end (&cur->fds);
       e = list_next (e))
    {
      struct file_descriptor *fd;
      fd = list_entry (e, struct file_descriptor, elem);
      if (fd->handle == handle)
        return fd;
    }
 
  thread_exit ();
}
示例#3
0
void
frame_free (void *frame)
{
    struct list_elem *e;

    lock_acquire (&frame_table_lock);
    for (e = list_begin (&frame_table); e != list_end (&frame_table); e = list_next (e)) {
        struct frame_entry *frame_entry = list_entry (e, struct frame_entry, elem);
        if (frame_entry->frame == frame) {
            list_remove (e);
            free (frame_entry);
            palloc_free_page (frame);
            break;
        }
    }
    lock_release (&frame_table_lock);
}
示例#4
0
文件: frame.c 项目: IVY-bug/Pintos4
void
falloc_free_frame (void *kaddr)
{
	struct list_elem *e;
	
	for (e = list_begin(&frame_table);
		e != list_end(&frame_table); e = list_next(e))
    {
    	struct frame_entry *f = list_entry(e, struct frame_entry, elem);
    	if(f->frame == kaddr)
       	{
       		list_remove(e);
       		free(f);
       		break;
       	}
    }
}
示例#5
0
/* Reads an inode from SECTOR
   and returns a `struct inode' that contains it.
   Returns a null pointer if memory allocation fails. */
struct inode *
inode_open (disk_sector_t sector) 
{
  struct list_elem *e;
  struct inode *inode;

  //Lock anyone else out of the inode list
  lock_acquire(&inode_list_lock);
  /* Check whether this inode is already open. */
  for (e = list_begin (&open_inodes); e != list_end (&open_inodes);
       e = list_next (e)) 
    {
      inode = list_entry (e, struct inode, elem);
      if (inode->sector == sector) 
        {
          inode_reopen (inode);
          lock_release(&inode_list_lock);
          return inode; 
        }
    }


  /* Allocate memory. */
  inode = malloc (sizeof *inode);
  if (inode == NULL)
  {
    lock_release(&inode_list_lock);
    return NULL;
  }

  /* Initialize. */
  inode->sector = sector;
  inode->open_cnt = 1;
  inode->deny_write_cnt = 0;
  inode->removed = false;
  disk_read (filesys_disk, inode->sector, &inode->data);

  lock_init(&inode->reader_writer_lock);
  lock_init(&inode->internal_lock);

  //Push the node into the list and unlock the list for other modifications
  list_push_front (&open_inodes, &inode->elem);
  lock_release(&inode_list_lock);

  return inode;
}
示例#6
0
LIST * property_set_create( FRAME * frame, int flags )
{
    LIST * properties = lol_get( frame->args, 0 );
    LIST * sorted = list_sort( properties );
    LIST * unique = list_unique( sorted );
    struct ps_map_entry * pos = ps_map_insert( &all_property_sets, unique );
    list_free( sorted );
    if ( pos->value )
    {
        list_free( unique );
        return list_new( object_copy( pos->value ) );
    }
    else
    {
        OBJECT * rulename = object_new( "new" );
        OBJECT * varname = object_new( "self.raw" );
        LIST * val = call_rule( rulename, frame,
            list_new( object_new( "property-set" ) ), 0 );
        LISTITER iter, end;
        object_free( rulename );
        pos->value = object_copy( list_front( val ) );
        var_set( bindmodule( pos->value ), varname, unique, VAR_SET );
        object_free( varname );

        for ( iter = list_begin( unique ), end = list_end( unique ); iter != end; ++iter )
        {
            const char * str = object_str( list_item( iter ) );
            if ( str[ 0 ] != '<' || ! strchr( str, '>' ) )
            {
                string message[ 1 ];
                string_new( message );
                string_append( message, "Invalid property: '" );
                string_append( message, str );
                string_append( message, "'" );
                rulename = object_new( "errors.error" );
                call_rule( rulename, frame,
                    list_new( object_new( message->value ) ), 0 );
                /* unreachable */
                string_free( message );
                object_free( rulename );
            }
        }

        return val;
    }
}
示例#7
0
文件: syscall.c 项目: roooot/pintos
/* Returns the file with the given fid from the current thread's files */
static struct user_file *
file_by_fid (int fid)
{
  struct list_elem *e;
  struct thread *t;

  t = thread_current();
  for (e = list_begin (&t->files); e != list_end (&t->files);
       e = list_next (e))
    {
      struct user_file *f = list_entry (e, struct user_file, thread_elem);
      if (f->fid == fid)
        return f;
    }

  return NULL;
}
示例#8
0
/* Reads an inode from SECTOR
   and returns a `struct inode' that contains it.
   Returns a null pointer if memory allocation fails. */
struct inode *
inode_open (disk_sector_t sector) 
{
  struct list_elem *e;
  struct inode *inode;

  
  /* Check whether this inode is already open. */
  lock_acquire(&inode_list_lock);
  for (e = list_begin (&open_inodes); e != list_end (&open_inodes);
       e = list_next (e)) 
    {
      inode = list_entry (e, struct inode, elem);
      if (inode->sector == sector) 
        {
          inode_reopen (inode);
	  lock_release(&inode_list_lock);
          return inode; 
        }
    }


  /* Allocate memory. */
  inode = malloc (sizeof *inode);
  if (inode == NULL)
  {
    return NULL;
  }
  
  list_push_front (&open_inodes, &inode->elem);

  /* Initialize. */
  inode->sector = sector;
  inode->open_cnt = 1;
  inode->removed = false;
  inode->read_cnt = 0;
  lock_init(&inode->inode_lock); 
  lock_init(&inode->read_lock); 
  sema_init(&inode->semaphore,1);
  disk_read (filesys_disk, inode->sector, &inode->data);

 lock_release(&inode_list_lock);

  return inode;
}
示例#9
0
文件: map.c 项目: knarko/pintos
void map_remove_if(struct map* m, bool(*exec)(key_t, value_t, int), int aux)
{
  for(struct list_elem *e = list_begin(&(m->content)); 
      e != list_end(&(m->content));)
    {
    struct association *f = list_entry(e, struct association, elem);
    if (exec(f->key, f->value, aux))
      {
	e = list_remove(e);
	free(f);
      }
    else 
      {
	e = list_next(e);
      }
  }
  return;
}
示例#10
0
Bool hashtable_contains(HashTable ht, Type key) { //compreuba que exista el key
    if (ht == NULL || key == NULL)
        return FALSE;
    int i;

    i = ht->hashcodeF(key) % ht->capacity;
    if (ht->l_array[i] == NULL)
        return FALSE;
    Iterator ite;
    ite = list_begin(ht->l_array[i]);
    while (list_hasNext(ite)) {
        ite = list_next(ite);
        if (ht->isKeyEqual(retrieveKeyFromIterator(ite), key)) {
            return TRUE;
        }
    }
    return FALSE;
}
示例#11
0
static int test(int id)
{
	clist* list_t = list_begin(&g_listTimerWork);
	int i = 0;
	while(list_end(&g_listTimerWork) != list_t)
	{
		st_timer* timer_t = (st_timer*)list_t;
		LOG_WRITE_POS(LOG_ERR, "%d  ", timer_t->id);
		if (i++ > 20)
		{
			LOG_WRITE_POS(LOG_ERR, "insert id = %d, link_number = %d\r\n", id, i);
			exit(1);
		}
		list_t = list_t->next;
	}
	LOG_WRITE_POS(LOG_ERR, "id=%d,   link_number = %d, %ld,  %ld\r\n", id, i, g_timerArray[id].tv.tv_sec, g_timerArray[id].tv.tv_usec);
	return 1;
}
示例#12
0
Type hashtable_get(HashTable ht, Type key) {  //recupera el value con el key
    if (ht == NULL || key == NULL)
        return NULL;
    int i;

    i = ht->hashcodeF(key) % ht->capacity;
    if (ht->l_array[i] == NULL)
        return NULL;
    Iterator ite;
    ite = list_begin(ht->l_array[i]);
    while (list_hasNext(ite)) {
        ite = list_next(ite);
        if (ht->isKeyEqual(retrieveKeyFromIterator(ite), key)) {
            return retrieveValueFromIterator(ite);
        }
    }
    return NULL;
}
示例#13
0
/* Finds and returns a frame given KPAGE */
struct frame_element *
frame_table_find (uint32_t *kpage)
{
  struct list_elem *e;
  struct frame_element *fe = NULL;
  for (e = list_begin (&frame_table); e != list_end (&frame_table);
       e = list_next (e))
    {
      fe = list_entry (e, struct frame_element, frame_elem);
      if (fe == NULL)
	break;
      else if (fe->kpage == kpage)
	break;
      else 
	fe = NULL;
    }
  return fe;
}
示例#14
0
文件: sched.c 项目: mduft/tachyon3
static thread_t* sched_choose() {
    for(priority_t i = PrioKernel; i < PrioMaxPrio; --i) {
        list_node_t* node = list_begin(_sched_queues[i]);

        // TODO: check priorities!
        while(node) {
            thread_t* thr = (thread_t*)node->data;

            if(thr && thr->state == Runnable) {
                return thr;
            }

            node = node->next;
        }
    }

    return NULL;
}
示例#15
0
文件: make1.c 项目: CarterTsai/clasp
static LIST * make1list( LIST * l, TARGETS * targets, int flags )
{
    for ( ; targets; targets = targets->next )
    {
        TARGET * t = targets->target;

        if ( t->binding == T_BIND_UNBOUND )
            make1bind( t );

        if ( ( flags & RULE_EXISTING ) && ( flags & RULE_NEWSRCS ) )
        {
            if ( ( t->binding != T_BIND_EXISTS ) &&
                ( t->fate <= T_FATE_STABLE ) )
                continue;
        }
        else if ( flags & RULE_EXISTING )
        {
            if ( t->binding != T_BIND_EXISTS )
                continue;
        }
        else if ( flags & RULE_NEWSRCS )
        {
            if ( t->fate <= T_FATE_STABLE )
                continue;
        }

        /* Prohibit duplicates for RULE_TOGETHER. */
        if ( flags & RULE_TOGETHER )
        {
            LISTITER iter = list_begin( l );
            LISTITER const end = list_end( l );
            for ( ; iter != end; iter = list_next( iter ) )
                if ( object_equal( list_item( iter ), t->boundname ) )
                    break;
            if ( iter != end )
                continue;
        }

        /* Build new list. */
        l = list_push_back( l, object_copy( t->boundname ) );
    }

    return l;
}
示例#16
0
文件: frame.c 项目: satyacha/Pintos
void frame_free(struct frame *f) {
	// here we free the frame held by the process
	lock_acquire(&ftable_lock);
	struct list_elem *elem = list_begin(&frame_list);
	while (elem != list_end(&frame_list)) {
		struct frame *fe = list_entry(elem, struct frame, frame_list_elem);
		if (fe != f) {
			elem = list_next(elem);
			continue;
		}
		// if current process frame that is to be freed is in the list, then remove it from list and free memory
		list_remove(elem);
		pagedir_clear_page(fe->page->frame_holder_thread->pagedir, fe->page->addr);
		palloc_free_page(fe->base); // free the page currently held by the frame
		free(fe); // then free the frame
		break;
	}
	lock_release(&ftable_lock);
}
示例#17
0
Type* hashtable_getValues(HashTable ht) { //devuelve un arreglo con los key de la tabla
    Type* array; //contiene los values a devolver
    array = (Type *) malloc(sizeof (Type) * ht->size);
    Iterator ite;
    int i;
    int count;
    count = 0;
    for (i = 0; i < ht->capacity; i++) {
        if (ht->l_array[i] != NULL) {
            ite = list_begin(ht->l_array[i]);
            while (list_hasNext(ite)) {
                ite = list_next(ite);
                array[count] = retrieveValueFromIterator(ite);
                count++;
            }
        }
    }
    return array; 
}
示例#18
0
/* Releases LOCK, which must be owned by the current thread.

   An interrupt handler cannot acquire a lock, so it does not
   make sense to try to release a lock within an interrupt
   handler. */
void
lock_release (struct lock *lock) 
{ 
  ASSERT (lock != NULL);
  ASSERT (lock_held_by_current_thread (lock));

  enum intr_level old_level = intr_disable ();

  bool yield = false;

  lock->holder = NULL;

  struct thread *cur = thread_current ();
  if (cur->priority > cur->old_priority)
   {
     yield = true;
     cur->priority = cur->old_priority;
   }

  if (list_size (&lock->semaphore.waiters) <=1) 
   { 
     struct list_elem *e;
     struct lock_elem *l;
     for (e = list_begin (&lock_list); e != list_end (&lock_list);
          e = list_next (e))
      {
        l = list_entry (e, struct lock_elem, elem);
        if (lock->id == l->id)
         {
           list_remove (e);
           free (l);
           break;
         }
      }
   }  

  sema_up (&lock->semaphore);

  if (yield) thread_yield ();
  
  intr_set_level (old_level);

}
void config_set_string(config_t *config, const char *section, const char *key, const char *value) {
  section_t *sec = section_find(config, section);
  if (!sec) {
    sec = section_new(section);
    list_append(config->sections, sec);
  }

  for (const list_node_t *node = list_begin(sec->entries); node != list_end(sec->entries); node = list_next(node)) {
    entry_t *entry = list_node(node);
    if (!strcmp(entry->key, key)) {
      free(entry->value);
      entry->value = strdup(value);
      return;
    }
  }

  entry_t *entry = entry_new(key, value);
  list_append(sec->entries, entry);
}
示例#20
0
struct f_info* findfile(uint32_t fd) {
    
    struct thread *t = thread_current();
    struct list* f_lst = &(t->f_lst);
    struct list_elem *e;
    
    /* Iterate through the entire f_lst to look for the same fd.
     * Return immediately, once found it. */
    for (e = list_begin(f_lst); e != list_end(f_lst); e = list_next(e)) {
        struct f_info* f = list_entry(e, struct f_info, elem);
        if (f->fd == fd)
            return f;
    }
    
    /* If not found, then exit with error. */
    exit(-1);
    return NULL;
    
}
示例#21
0
文件: inode.c 项目: tdzhang/cs140
/* Reads an inode from SECTOR
   and returns a `struct inode' that contains it.
   Returns a null pointer if memory allocation fails. */
struct inode *
inode_open (block_sector_t sector)
{
  struct list_elem *e;
  struct inode *inode;

  /* Check whether this inode is already open. */
  lock_acquire(&open_inodes_lock);
  for (e = list_begin (&open_inodes); e != list_end (&open_inodes);
       e = list_next (e)) 
    {
      inode = list_entry (e, struct inode, elem);
      if (inode->sector == sector) 
        {
          inode_reopen (inode);
          lock_release(&open_inodes_lock);
          return inode; 
        }
    }
  lock_release(&open_inodes_lock);
  /* Allocate memory. */
  inode = malloc (sizeof *inode);
  if (inode == NULL)
    return NULL;

  /* Initialize. */
  ASSERT(!lock_held_by_current_thread (&open_inodes_lock));
  lock_acquire(&open_inodes_lock);
  list_push_front (&open_inodes, &inode->elem);
  lock_release(&open_inodes_lock);
  inode->sector = sector;
  inode->open_cnt = 1;
  inode->deny_write_cnt = 0;
  inode->removed = false;
  lock_init(&inode->dir_lock);
  lock_init(&inode->inode_lock);
  /* retrieve inode_disk from sector */
  struct inode_disk id;
  cache_read(inode->sector, INVALID_SECTOR_ID, &id, 0, BLOCK_SECTOR_SIZE);
  inode->readable_length = id.length;
  inode->is_dir = id.is_dir;
  return inode;
}
void
sem_yield(sem_t *sp)
{
    sem *sema = (sem*)sp;
    ucontext_t *curr = NULL, *next = NULL;
    tcb *running = NULL, *tcbnext = NULL;
    struct list_elem *e = NULL;
    int queueflag = -1;

    running = list_entry(list_begin(&q_running), thread_p, elem)->p;
    if (is_list_empty(&q_ready_H) && is_list_empty(&q_ready_L)) {
        printf("Q_ready_H and L are both empty!\n");
        return;
    }

    thread_p *tmp_p = (thread_p *)calloc(1, sizeof(thread_p));
    tmp_p->p = running;
    list_insert_tail(&sema->waiters, &tmp_p->elem);
    curr = &running->context;
    e = list_begin(&q_running);
    tmp_p = list_entry(e, thread_p, elem);
    list_remove(e);
    free(tmp_p);

    if (!is_list_empty(&q_ready_H)) {
        tcbnext = list_entry(list_begin(&q_ready_H), thread_p, elem)->p;
        queueflag = 0;
    }
    else if (!is_list_empty(&q_ready_L)) {
        tcbnext = list_entry(list_begin(&q_ready_L), thread_p, elem)->p;
        queueflag = 1;
    }
    tmp_p = (thread_p *)calloc(1, sizeof(thread_p));
    tmp_p->p = tcbnext;
    list_insert_head(&q_running, &tmp_p->elem);
    next = &tcbnext->context;

    if (queueflag == 0) 
        e = list_begin(&q_ready_H);
    else if (queueflag == 1) 
        e = list_begin(&q_ready_L);
    tmp_p = list_entry(e, thread_p, elem);
    list_remove(e);
    free(tmp_p);
    assert(curr);
    assert(next);
    if (swapcontext(curr, next) == -1) {
        printf("Swapcontext error: %s\n", strerror(errno));   
    }
}
示例#23
0
static void file_dirscan_impl( OBJECT * dir, scanback func, void * closure )
{
    file_info_t * const d = file_query( dir );
    if ( !d || !d->is_dir )
        return;

    /* Lazy collect the directory content information. */
    if ( list_empty( d->files ) )
    {
        if ( DEBUG_BINDSCAN )
            out_printf( "scan directory %s\n", object_str( d->name ) );
        if ( file_collect_dir_content_( d ) < 0 )
            return;
    }

    /* OS specific part of the file_dirscan operation. */
    file_dirscan_( d, func, closure );

    /* Report the collected directory content. */
    {
        LISTITER iter = list_begin( d->files );
        LISTITER const end = list_end( d->files );
        for ( ; iter != end; iter = list_next( iter ) )
        {
            OBJECT * const path = list_item( iter );
            file_info_t const * const ffq = file_query( path );
            /* Using a file name read from a file_info_t structure allows OS
             * specific implementations to store some kind of a normalized file
             * name there. Using such a normalized file name then allows us to
             * correctly recognize different file paths actually identifying the
             * same file. For instance, an implementation may:
             *  - convert all file names internally to lower case on a case
             *    insensitive file system
             *  - convert the NTFS paths to their long path variants as that
             *    file system each file system entity may have a long and a
             *    short path variant thus allowing for many different path
             *    strings identifying the same file.
             */
            (*func)( closure, ffq->name, 1 /* stat()'ed */, &ffq->time );
        }
    }
}
示例#24
0
static waiting_command_t *get_waiting_command(command_opcode_t opcode) {
  pthread_mutex_lock(&commands_pending_response_lock);

  for (const list_node_t *node = list_begin(commands_pending_response);
      node != list_end(commands_pending_response);
      node = list_next(node)) {
    waiting_command_t *wait_entry = list_node(node);

    if (!wait_entry || wait_entry->opcode != opcode)
      continue;

    list_remove(commands_pending_response, wait_entry);

    pthread_mutex_unlock(&commands_pending_response_lock);
    return wait_entry;
  }

  pthread_mutex_unlock(&commands_pending_response_lock);
  return NULL;
}
示例#25
0
文件: frame.c 项目: xuruiyang/CS5600
/*
 * select one frame to kick out
 * the page inside it. We implement
 * Clock Algorithm here.
 */
struct frame_table_entry* clock_kick(){
	struct list_elem *elem;
clock:
	elem = list_begin(&frame_table);
	while (elem != list_end(&frame_table)) {
		struct frame_table_entry* fte;
		fte = list_entry(elem, struct frame_table_entry, elem);
		ASSERT(fte!=NULL);
		if(!pagedir_is_accessed(fte->owner->pagedir,fte->pg_vaddr)
				&& fte->pinned == false){
			return fte;
		}else{
			pagedir_set_accessed(fte->owner->pagedir,fte->pg_vaddr,0);
		}
		elem = list_next(elem);
	}
	goto clock;
	NOT_REACHED();
	return NULL;
}
示例#26
0
void cached_read(struct inode* inode, block_sector_t sector, const void *buffer){
	if(INODE_DEBUG) printf("cache_read: inode: %x sector: %d buffer: %x\n", inode, sector, buffer);
	
	traverse_buffcachelist();
	struct list_elem* e = NULL;
	for(e=list_begin(&buffcachelist); e!= list_end(&buffcachelist); e= list_next(e)){
		struct cached_block* cblock = list_entry(e, struct cached_block, elem);
		//printf("JMJMJMJMJMJMJMJMJMJMJMJMJM\n");
		if(cblock->sector == sector){
			memcpy(buffer, cblock->data, BLOCK_SECTOR_SIZE);
			//list_remove(e);
			//list_push_front(&buffcachelist, e);
			return;
		}
	}
	struct cached_block* free_buff = get_free_cache_buff();
	free_buff->inode = inode;
	free_buff->sector = sector;
	block_read(fs_device, sector, free_buff->data);
	memcpy(buffer, free_buff->data, BLOCK_SECTOR_SIZE);
}
示例#27
0
//功  能: 获取一个可连接目标
//参  数: sock是exSocket函数返回的socket id
//返回值: 连接目标的数据地址指针
static s_link* GetLinkAccept(st_sock* sts)
{
	s_link* pslink = NULL;

	sem_wait(&sts->semLink);
	pslink = (s_link*)list_begin(&sts->list);
	while ((s_link*)list_end(&sts->list) != pslink)
	{
		if (pslink->accept == 0)
		{
			pslink->accept = 1;
			pslink->tsWaitTime = sts->tsWaitTime;
			printf_debug2("pslink=%x, pslink->SeqRead=%d\n", pslink, pslink->SeqRead);
			sem_post(&sts->semLink);
			return pslink;
		}
		pslink = (s_link*)pslink->list.next;
	}
	sem_post(&sts->semLink);
	return NULL;
}
示例#28
0
文件: irq.c 项目: tdz/opsys
void
handle_irq(unsigned char irqno)
{
    const struct list* head = g_irq_handling.irqh + irqno;
    struct list* item = list_begin(head);

    while (item != list_end(head)) {

        struct list* next = list_next(item);

        struct irq_handler* irqh = irq_handler_of_list(item);

        enum irq_status status = irqh->func(irqno, irqh);
        if (status == IRQ_HANDLED) {
            break;
        }

        /* don't touch *item after func() returned */
        item = next;
    }
}
示例#29
0
文件: tls.c 项目: bigvaliant/kendylib
void clear_tls()
{
	if(is_init)
	{
		if(COMPARE_AND_SWAP(&is_init,1,0) == 1)
		{
			pthread_key_delete(thread_key);
			mutex_lock(tls_mtx);
			list_iter it = list_begin(tls_list);
			list_iter end = list_end(tls_list);
			for( ; !IT_LIST_EQUAL(it,end); IT_LIST_NEXT(it))
			{
				hash_map_t h = IT_LIST_GET(hash_map_t,it);
				hash_map_destroy(&h);
			}
			mutex_unlock(tls_mtx);
			mutex_destroy(&tls_mtx);
			list_destroy(&tls_list);
		}
	}
}
示例#30
0
static void sys_seek(int fd, unsigned position)
{
  struct thread *curr = thread_current();
  struct opened_file_elem *opened_elem;
  struct list_elem *e;
  int check_valid=0;
  if(fd<2)
    return;
  for( e = list_begin(&curr->openfile_list) ; e != list_end(&curr->openfile_list) ;
      e = list_next(e) )
  {
    opened_elem=list_entry(e,struct opened_file_elem,elem_f);
    if(opened_elem->fd==fd)
    {
      check_valid=1;
      return file_seek(opened_elem->opened_file,position);
    }
  }
  if(check_valid==0)
    return;
}