예제 #1
0
    /*!
     * \retval true queue not empty and next demand can be processed.
     * \retval false queue empty or
     * demands_processed >= m_max_demands_at_once
     */
    bool
    pop(
        //! Count of consequently processed demands from that queue.
        std::size_t demands_processed )
    {
        // Actual deletion of old head must be performed
        // when m_lock will be released.
        std::unique_ptr< demand_t > old_head;
        {
            std::lock_guard< spinlock_t > lock( m_lock );

            old_head = remove_head();

            if( m_head.m_next )
            {
                if( demands_processed < m_max_demands_at_once )
                    return true;
                else
                    m_disp_queue.schedule( this );
            }
            else
                m_tail = &m_head;
        }

        return false;
    }
inline HeapRegion* FreeRegionList::remove_head_or_null() {
  check_mt_safety();
  if (!is_empty()) {
    return remove_head();
  } else {
    return NULL;
  }
}
예제 #3
0
inline HeapRegion* HeapRegionLinkedList::remove_head_or_null() {
  hrl_assert_mt_safety_ok(this);

  if (!is_empty()) {
    return remove_head();
  } else {
    return NULL;
  }
}
예제 #4
0
파일: stailq.hpp 프로젝트: glk/ecl
	void remove(ObjectType *listobj) {
		if (stqh_first == listobj) {
			remove_head();
		} else {
			ObjectType *curobj = stqh_first;
			while (entry(curobj)->stqe_next != listobj)
				curobj = entry(curobj)->stqe_next;
			remove_after(curobj);
		}
	}
예제 #5
0
/* 
 * Description: 
 * 	Moves instruction(s) from the dispatch stage to the issue stage
 * Inputs:
 * 	current_cycle: the cycle we are at
 * Returns:
 * 	None
 */
void dispatch_To_issue(int current_cycle) {


	/* ECE552 Assignment 4 - BEGIN CODE */

   instruction_t* head  = instr_queue[0];

   if (head != NULL && head->tom_dispatch_cycle < current_cycle && head->tom_issue_cycle == 0) {
      if (IS_COND_CTRL(head->op) || IS_UNCOND_CTRL(head->op)) {
			 head = NULL;
			 remove_head();
			 /* decrement the instr_queue_size as first instruction is dispatched*/
			 instr_queue_size = instr_queue_size - 1;
      } else if (USES_INT_FU(head->op) || USES_FP_FU(head->op)) {
				 /* check if there is a reservation station available */
				 if (!is_rs_available(head->op)) {	
						return;
				 }

				 insn_struct* temp = set_rs_available(head->op, head);
				 temp->insn->tom_issue_cycle = current_cycle;
				 set_dependent_insn(temp);

				 /* Set the r_out mapping in the maptable */
				 int i;
	
				 for (i =0; i < 2; i++) {
						if (head->r_out[i] != DNA) {
							 map_table[head->r_out[i]] = head;
						}
				 }
						  
				 temp = NULL;
				 head = NULL;
				 remove_head();
				 instr_queue_size = instr_queue_size - 1;
			}
		}

		/* ECE552 Assignment 4 - END CODE */
}
예제 #6
0
int main(int argc, char *argv[]) {
	printf("\n");
	/*
	 * testing the creation of lists and appending
	 */
	printf("%s\n\n", "Commands Test 1");
	LTICKET ref = create_list("Adewale");
	append_to_list(ref, "Olufemi");
	append_to_list(ref, "Nneka");
	append_to_list(ref, "Jacob");
	append_to_list(ref, "Adetola");
	append_to_list(ref, "Kemi");
	visit_nodes(ref);
	delete_list(ref);

	/*
	 * testing the head and tail removal as well as head insertion
	 */
	printf("%s\n\n", "Commands Test 2");
	LTICKET ref2 = create_list("Adewale");
	append_to_list(ref2, "Olufemi");
	append_to_list(ref2, "Nneka");
	append_to_list(ref2, "Jacob");
	append_to_list(ref2, "Adetola");
	append_to_list(ref2, "Kemi");
	visit_nodes(ref2);
	remove_head(ref2);
	visit_nodes(ref2);
	insert_head(ref2, "Chiamaka");
	visit_nodes(ref2);
	remove_tail(ref2);
	visit_nodes(ref2);
	delete_list(ref2);

	// int check = visit_nodes(ref);
	// if(LE_ISERROR(check))
	// 	printf("%s\n", le_errbuf);
	return 0;
}
예제 #7
0
int main()
{
	list l;
	init(&l);

	printf("Inserting 3, 4, 1, 5, 6 and 2 at the back of the list.\n");
	insert_back(&l, 3);
	insert_back(&l, 4);
	insert_back(&l, 1);
	insert_back(&l, 5);
	insert_back(&l, 6);
	insert_back(&l, 2);
	for_each_forward(&l, print_node, NULL);

	printf("Print list backwards.\n");
	for_each_backward(&l, print_node, NULL);

	printf("Inserting 5 in front of the list.\n");
	insert_front(&l, 5);
	for_each_forward(&l, print_node, NULL);

	printf("Removing tail.\n");
	remove_tail(&l);
	for_each_forward(&l, print_node, NULL);

	printf("Removing head.\n");
	remove_head(&l);
	for_each_forward(&l, print_node, NULL);

	printf("Add 5 to each element in the list.\n");
	int add=5;
	for_each_forward(&l, add_node, &add);
	for_each_forward(&l, print_node, NULL);

	printf("Freeing list.\n");
	for_each_forward(&l, free_node, NULL);
	return 0;
}
예제 #8
0
int		remove_node(t_ctrl **ctrl, const int nbr)
{
  t_list	*list;
  int		i;

  i = 0;
  list = (*ctrl)->head;
  if ((*ctrl)->size == 1)
    return (FAILURE);
  while (i < (*ctrl)->size && list->nbr != nbr)
    {
      list = list->next;
      i++;
    }
  if (list == NULL)
    return (FAILURE);
  else if (list == (*ctrl)->head)
    remove_head(ctrl, list);
  else if (list == (*ctrl)->tail)
    remove_tail(ctrl, list);
  else
    remove_else(ctrl, list);
  return (SUCCESS);
}
/* Important observations:
   1) When an image is added, if it is not the first missing image, it is not removed
      immediately from the missing list (in order not to store another pointer to
      the missing list inside the window ,or otherwise, to go over the missing list
      and look for the image).
   2) images that weren't removed from the missing list in their addition time, will be removed when
      preliminary images will be added.
   3) The first item in the missing list is always really missing.
   4) The missing list is always ordered by image id (see add_pre_decoded_image)
*/
void GlzDecoderWindow::narrow_window(GlzDecodedImage *last_added)
{
    uint64_t new_head_image_id;

    GLZ_ASSERT(_debug_calls, !_missing_list.empty());

    if (_missing_list.front() != last_added->get_id()) {
        return;
    }

    _missing_list.pop_front();  // removing the last added image from the missing list

    /* maintaining the missing list: removing front images that already arrived */
    while (!_missing_list.empty()) {
        int front_win_idx = calc_image_win_idx(_missing_list.front());
        if (_images[front_win_idx] == NULL) { // still missing
            break;
        } else {
            _missing_list.pop_front();
        }
    }

    /* removing unnecessary image from the window's head*/
    if (_missing_list.empty()) {
        new_head_image_id = _images[
                calc_image_win_idx(_tail_image_id)]->get_window_head_id();
    } else {
        // there must be at least one image in the window since narrow_window is called
        // from post decode
        GLZ_ASSERT(_debug_calls, _images[calc_image_win_idx(_missing_list.front() - 1)]);
        new_head_image_id = _images[
                calc_image_win_idx(_missing_list.front() - 1)]->get_window_head_id();
    }

    remove_head(new_head_image_id);
}
예제 #10
0
/* Method for sellers to run */
void *ProcessSellers(void *threadarg) {
    struct seller_data *my_data;
    my_data = (struct seller_data *) threadarg;
    while (time_elapsed() <= SECS_TO_RUN) { // Only run if time isn't up
        if (is_empty(my_data->next)) {
            sleep(1); // Sleep for 1 second if no one in line
        } else {
            pthread_mutex_lock(&mutex_seating);
            int assigned = assign_seat(my_data); // Assign seating
            pthread_mutex_unlock(&mutex_seating);
            char *str = time_elapsed_string();
            if (assigned) {
                int completion_time = 0;
                if (my_data->type == H) {
                    completion_time = rand() % 2 + 1; // Sleep for 1 - 2
                } else if (my_data->type == M) {
                    completion_time = rand() % 3 + 2; // Sleep for 2 - 4
                } else {
                    completion_time = rand() % 4 + 4; // Sleep for 4 - 7
                }
                pthread_mutex_lock(&my_data->mutex);
                remove_head(my_data); // Remove first person from the line
                // Increment wait timer on all people in line and get amount of buyers who left
                int cust_left = increment_wait_timer(my_data, completion_time, str);
                printf("%s: A customer was assigned a seat at %s\n", str, my_data->name);
                pthread_mutex_unlock(&my_data->mutex);
                // Increments ticket sold
                if (my_data->type == H) {
                    h_sold++;
                    h_left += cust_left;
                } else if (my_data->type == M) {
                    m_sold++;
                    m_left += cust_left;
                } else {
                    l_sold++;
                    l_left += cust_left;
                }
                // Sleep for random time to generate minutes to complete sale
                sleep(completion_time);
                free(str);
                char *str2 = time_elapsed_string();
                printf("%s: A customer has completed their ticket purchase at %s\n", str2, my_data->name);
                free(str2);
            } else {
                pthread_mutex_lock(&my_data->mutex);
                printf("%s: Remaining %d customer(s) at %s are being told to leave since tickets are sold out\n", str, my_data->cust_count, my_data->name);
                free(str);
                // Remove and count everyone from the line
                while (my_data->next != NULL) {
                    remove_head(my_data);
                    if (my_data->type == H)
                        h_leave++;
                    else if (my_data->type == M)
                        m_leave++;
                    else
                        l_leave++;
                }
                my_data->closed = 1; // Set seller to closed
                pthread_mutex_unlock(&my_data->mutex);
                pthread_exit(NULL); // Exit seller thread
            }
        }
    }
    pthread_mutex_lock(&my_data->mutex);
    my_data->closed = 1; // Set seller to closed
    int rem = my_data->cust_count;
    if (rem != 0) {
        char *str = time_elapsed_string();
        printf("%s: Remaining %d customer(s) at %s are being told to leave since the selling time is up\n", str, my_data->cust_count, my_data->name);
        free(str);
        // Remove and count everyone from the line
        while (my_data->next != NULL) {
            remove_head(my_data);
            if (my_data->type == H)
                h_closing++;
            else if (my_data->type == M)
                m_closing++;
            else
                l_closing++;
        }
    }
    pthread_mutex_unlock(&my_data->mutex);
}
예제 #11
0
// frees all node memory and empties list
void SList::free()
{
  while (head) {
    remove_head();
  }
}
예제 #12
0
 ~agent_queue_t()
 {
     while( m_head.m_next )
         remove_head();
 }
예제 #13
0
파일: link.hpp 프로젝트: qmc/dsqss
 C& pop() { return remove_head(); };