Example #1
0
/* Inserts ELEM at the end of LIST, so that it becomes the
   back in LIST. */
void
list_push_back (struct list *list, struct list_elem *elem)
{
  list_insert (list_end (list), elem);
}
Example #2
0
void insert_tail(AList_WS* list, double data) {
	insert_at_loc(list, list_end(list), get_next(list, list_end(list)), data);
}
Example #3
0
void delete_tail(AList_WS* list) {
	delete_data_loc(list, list_end(list));
}
Example #4
0
//to sort in the standard of cmp with method of mergeSort
void list_sort(list *plist, cmp_t cmp){
	mergeSort(list_begin(plist), list_end(plist), plist->m_size, cmp);
}
Example #5
0
iter_t list_push(list *plist, void* pdata){
	//always insert to the tail of list
	return list_insert(plist, list_end(plist), pdata);
}
Example #6
0
File: synch.c Project: rwan6/pintos
/* Acquires LOCK, sleeping until it becomes available if
   necessary.  The lock must not already be held by the current
   thread.

   Perform priority donation within lock aquire. We detect whether
   the lock holder is ready to be run and if we need to donate
   priority to it to avoid priority inversion. If nested dependency
   exists, we update the priority up the dependency chain until the
   bottleneck thread has a high-enough priority to complete its
   execution. More details can be found in the design documentation.

   This function may sleep, so it must not be called within an
   interrupt handler.  This function may be called with
   interrupts disabled, but interrupts will be turned back on if
   we need to sleep. */
void
lock_acquire (struct lock *lock)
{
  ASSERT (lock != NULL);
  ASSERT (!intr_context ());
  ASSERT (!lock_held_by_current_thread (lock));

  if (!thread_mlfqs)
    {
      struct thread *t_lock = lock->holder;
      enum intr_level old_level;
      if (t_lock && t_lock->status == THREAD_READY)
        {
          thread_current ()->waiting_on_lock = lock;
          old_level = intr_disable ();
          int cur_priority = thread_current ()->donated_priority;
          if (cur_priority > t_lock->donated_priority)
            {
              /* Add to thread's list of priority donors */
              list_insert_ordered (&t_lock->donated_list,
                &thread_current ()->donatedelem, priority_less, NULL);
              t_lock->donated_priority = cur_priority;
            }
          intr_set_level (old_level);
        }
      else
        {
          thread_current ()->waiting_on_lock = lock;
          struct thread *prev_t = thread_current ();
          while (t_lock)
            {
              if (prev_t->donated_priority > t_lock->donated_priority)
                {
                  /* If I was already in the list, remove myself before
                  being reinserted in-order */
                  struct list_elem *dup_e;
                  for (dup_e = list_begin (&t_lock->donated_list);
                    dup_e != list_end (&t_lock->donated_list);
                    dup_e = list_next (dup_e))
                    {
                      if (dup_e == &prev_t->donatedelem)
                        list_remove(&prev_t->donatedelem);
                    }
                  /* Add to thread's list of priority donors */
                  old_level = intr_disable ();
                  list_insert_ordered (&t_lock->donated_list,
                    &prev_t->donatedelem, priority_less, NULL);
                  intr_set_level (old_level);
                  t_lock->donated_priority = prev_t->donated_priority;
                }
              if (t_lock->waiting_on_lock)
                {
                  prev_t = t_lock;
                  t_lock = t_lock->waiting_on_lock->holder;
                }
              else
                t_lock = NULL;
            }
        }
    }

  sema_down (&lock->semaphore);
  lock->holder = thread_current ();
}
Example #7
0
void list_clear_all(list *plist){
	for(iter_t iter = list_begin(plist)->m_next;
	iter!=list_end(plist); iter = list_begin(plist)->m_next){
		list_erase(plist,iter);
	}
}
Example #8
0
/* Checks whether the given shell list is actually a request to execute raw
 * commands without an external shell.
 */
int is_raw_command_request( LIST * shell )
{
    return !list_empty( shell ) &&
        !strcmp( object_str( list_front( shell ) ), "%" ) &&
        list_next( list_begin( shell ) ) == list_end( shell );
}
Example #9
0
File: hash.c Project: dongyx/hyphen
static inline int enditer(list_iter_t iter) {
	return iter == list_end(list_container(iter));
}
Example #10
0
LIST * hcache( TARGET * t, int rec, regexp * re[], LIST * hdrscan )
{
    HCACHEDATA * c;

    ++queries;

    if ( ( c = (HCACHEDATA *)hash_find( hcachehash, t->boundname ) ) )
    {
        if ( !timestamp_cmp( &c->time, &t->time ) )
        {
            LIST * const l1 = hdrscan;
            LIST * const l2 = c->hdrscan;
            LISTITER iter1 = list_begin( l1 );
            LISTITER const end1 = list_end( l1 );
            LISTITER iter2 = list_begin( l2 );
            LISTITER const end2 = list_end( l2 );
            while ( iter1 != end1 && iter2 != end2 )
            {
                if ( !object_equal( list_item( iter1 ), list_item( iter2 ) ) )
                    iter1 = end1;
                else
                {
                    iter1 = list_next( iter1 );
                    iter2 = list_next( iter2 );
                }
            }
            if ( iter1 != end1 || iter2 != end2 )
            {
                if ( DEBUG_HEADER )
                {
                    printf( "HDRSCAN out of date in cache for %s\n",
                        object_str( t->boundname ) );
                    printf(" real  : ");
                    list_print( hdrscan );
                    printf( "\n cached: " );
                    list_print( c->hdrscan );
                    printf( "\n" );
                }

                list_free( c->includes );
                list_free( c->hdrscan );
                c->includes = L0;
                c->hdrscan = L0;
            }
            else
            {
                if ( DEBUG_HEADER )
                    printf( "using header cache for %s\n", object_str(
                        t->boundname ) );
                c->age = 0;
                ++hits;
                return list_copy( c->includes );
            }
        }
        else
        {
            if ( DEBUG_HEADER )
                printf ("header cache out of date for %s\n", object_str(
                    t->boundname ) );
            list_free( c->includes );
            list_free( c->hdrscan );
            c->includes = L0;
            c->hdrscan = L0;
        }
    }
    else
    {
        int found;
        c = (HCACHEDATA *)hash_insert( hcachehash, t->boundname, &found );
        if ( !found )
        {
            c->boundname = object_copy( t->boundname );
            c->next = hcachelist;
            hcachelist = c;
        }
    }

    /* 'c' points at the cache entry. Its out of date. */
    {
        LIST * const l = headers1( L0, t->boundname, rec, re );

        timestamp_copy( &c->time, &t->time );
        c->age = 0;
        c->includes = list_copy( l );
        c->hdrscan = list_copy( hdrscan );

        return l;
    }
}
Example #11
0
void hcache_done()
{
    FILE       * f;
    HCACHEDATA * c;
    int          header_count = 0;
    const char * hcachename;
    int          maxage;

    if ( !hcachehash )
        return;

    if ( !( hcachename = cache_name() ) )
        goto cleanup;

    if ( !( f = fopen( hcachename, "wb" ) ) )
        goto cleanup;

    maxage = cache_maxage();

    /* Print out the version. */
    write_netstring( f, CACHE_FILE_VERSION );

    c = hcachelist;
    for ( c = hcachelist; c; c = c->next )
    {
        LISTITER iter;
        LISTITER end;
        char time_secs_str[ 30 ];
        char time_nsecs_str[ 30 ];
        char age_str[ 30 ];
        char includes_count_str[ 30 ];
        char hdrscan_count_str[ 30 ];

        if ( maxage == 0 )
            c->age = 0;
        else if ( c->age > maxage )
            continue;

        sprintf( includes_count_str, "%lu", (long unsigned)list_length(
            c->includes ) );
        sprintf( hdrscan_count_str, "%lu", (long unsigned)list_length(
            c->hdrscan ) );
        sprintf( time_secs_str, "%lu", (long unsigned)c->time.secs );
        sprintf( time_nsecs_str, "%lu", (long unsigned)c->time.nsecs );
        sprintf( age_str, "%lu", (long unsigned)c->age );

        write_netstring( f, CACHE_RECORD_HEADER );
        write_netstring( f, object_str( c->boundname ) );
        write_netstring( f, time_secs_str );
        write_netstring( f, time_nsecs_str );
        write_netstring( f, age_str );
        write_netstring( f, includes_count_str );
        for ( iter = list_begin( c->includes ), end = list_end( c->includes );
            iter != end; iter = list_next( iter ) )
            write_netstring( f, object_str( list_item( iter ) ) );
        write_netstring( f, hdrscan_count_str );
        for ( iter = list_begin( c->hdrscan ), end = list_end( c->hdrscan );
            iter != end; iter = list_next( iter ) )
            write_netstring( f, object_str( list_item( iter ) ) );
        fputs( "\n", f );
        ++header_count;
    }
    write_netstring( f, CACHE_RECORD_END );

    if ( DEBUG_HEADER )
        printf( "hcache written to %s.   %d dependencies, %.0f%% hit rate\n",
            hcachename, header_count, queries ? 100.0 * hits / queries : 0 );

    fclose ( f );

cleanup:
    for ( c = hcachelist; c; c = c->next )
    {
        list_free( c->includes );
        list_free( c->hdrscan );
        object_free( c->boundname );
    }

    hcachelist = 0;
    if ( hcachehash )
        hashdone( hcachehash );
    hcachehash = 0;
}
Example #12
0
int main(int argc, char* argv[])
{
    list_t* pt_list = create_list(vector_t<int>);
    vector_t* pt_vec = create_vector(int);
    iterator_t t_it_list;
    iterator_t t_it_vec;
    size_t t_i = 0;
    size_t t_j = 0;
    size_t t_count = 0;
    if(pt_list == NULL || pt_vec == NULL)
    {
        return -1;
    }

    list_init(pt_list);
    vector_init(pt_vec);

    srand((unsigned)time(NULL));
    for(t_i = 0; t_i < 10; ++t_i)
    {
        t_count = rand() % 10;
        vector_clear(pt_vec);
        for(t_j = 0; t_j < t_count; ++t_j)
        {
            vector_push_back(pt_vec, rand() - rand());
        }
        list_push_back(pt_list, pt_vec);
    }

    printf("before sorting:\n");
    for(t_it_list = list_begin(pt_list);
        !iterator_equal(t_it_list, list_end(pt_list));
        t_it_list = iterator_next(t_it_list))
    {
        for(t_it_vec = vector_begin(iterator_get_pointer(t_it_list));
            !iterator_equal(t_it_vec, vector_end(iterator_get_pointer(t_it_list)));
            t_it_vec = iterator_next(t_it_vec))
        {
            printf("%d, ", *(int*)iterator_get_pointer(t_it_vec));
        }
        printf("\n");
    }
    printf("\n");

    list_sort(pt_list);

    printf("before sorting:\n");
    for(t_it_list = list_begin(pt_list);
        !iterator_equal(t_it_list, list_end(pt_list));
        t_it_list = iterator_next(t_it_list))
    {
        for(t_it_vec = vector_begin(iterator_get_pointer(t_it_list));
            !iterator_equal(t_it_vec, vector_end(iterator_get_pointer(t_it_list)));
            t_it_vec = iterator_next(t_it_vec))
        {
            printf("%d, ", *(int*)iterator_get_pointer(t_it_vec));
        }
        printf("\n");
    }
    printf("\n");

    list_destroy(pt_list);
    vector_destroy(pt_vec);

    return 0;
}