void
graph_print (Graph g)
{
  list adjs;
  list vertices = g->vertices;

  assert (!element_null (g));
  fprintf (stderr, "Data of Graph %p\n", (void *) g);
  fprintf (stderr, "----\n");
  fprintf (stderr, "Number of initial Vertices %d\n", g->totalVertices);
  fprintf (stderr, "Number of active Vertices %d\n", list_length (vertices));
  fprintf (stderr, "----\n");

  while (!list_null (vertices))
    {
      vertex_print (list_head (vertices));
      fprintf (stderr, "\tadjacencies: ");
      adjs = g->adjacencies[list_head (vertices)->id];
      while (!list_null (adjs))
	{
	  fprintf (stderr, "%d ", list_head (adjs)->id);
	  adjs = list_next (adjs);
	}
      fprintf (stderr, "\n");
      vertices = list_next (vertices);
    }
}
示例#2
0
void list_copy_object(list_element_t *element, list_data_t data)
{
    list_null(element);
    list_null(data);

    element->data = (void *)malloc(sizeof(list_object_t));
    ((list_object_t*)element->data)->jvm = ((list_object_t*)data)->jvm;
    ((list_object_t*)element->data)->idObject = ((list_object_t*)data)->idObject;
    //element->data = memcpy(element->data, data, sizeof(list_object_t));
}
示例#3
0
void list_copy_string_class(list_element_t *element, list_data_t data)
{
    list_null(element);
    list_null(data);

    element->data = (void *)malloc(sizeof(list_class_t));

    ((list_class_t*)element->data)->className = (void *)malloc((sizeof(char) * strlen((char *)((list_class_t*)data)->className)) + 1);

    ((list_class_t*)element->data)->jvm = ((list_class_t*)data)->jvm;

    ((list_class_t*)element->data)->className = strcpy(((list_class_t*)element->data)->className, ((list_class_t*)data)->className);

}
示例#4
0
bool list_cmp_string_class(list_data_t data, list_data_t data2)
{
    list_null(data);
    list_null(data2);

    list_class_t *obj = (list_class_t*) data;
    list_class_t *obj2 = (list_class_t*) data2;


    if(obj->jvm == obj2->jvm && strcmp(obj->className, obj2->className) == 0) {
        return true;
    }
    return false;

}
示例#5
0
bool list_cmp_object(list_data_t data, list_data_t data2)
{
    list_null(data);
    list_null(data2);

    list_object_t *obj = (list_object_t*) data;
    list_object_t *obj2 = (list_object_t*) data2;


    if(obj->jvm == obj2->jvm && obj->idObject == obj2->idObject) {
        return true;
    }
    return false;

}
示例#6
0
文件: nfsfs.c 项目: dafyddcrosby/L4OS
/* Run request at head of queue */
static
int
run_head_request(void) {
	if (list_null(NfsRequests)) {
		return 0;
	}
	return run_request((NFS_BaseRequest *) list_peek(NfsRequests));
}
示例#7
0
文件: nfsfs.c 项目: dafyddcrosby/L4OS
/* Return a NFS request struct with the token specified */
static
NFS_BaseRequest*
get_request(uintptr_t token) {
	if (list_null(NfsRequests)) {
		dprintf(0, "!!! get_request: List is NULL\n");
		return NULL;
	}
	return (NFS_BaseRequest *) list_find(NfsRequests, search_requests, &token);
}
/* Destroy from u to v, i.e. remove all v entries in adj lists.
 * From all active vertices, iterate through their adjacency lists
 * and remove all occurrences of v.
 */
static void
graph_rEMOVEfROMaDJACENCYlISTS (Graph g, Vertex v)
{
  list vertices = g->vertices;
  list *adjacencies = g->adjacencies;
  list adjs;

  assert (!element_null (g) && !element_null (v));
  while (!list_null (vertices))
    {
      adjs = adjacencies[list_head (vertices)->id];
      while (!list_null (adjs))
	{
	  if (list_head (adjs)->id == v->id)
	    list_remove (&(g->adjacencies[list_head (vertices)->id]), adjs);
	  adjs = list_next (adjs);
	}
      vertices = list_next (vertices);
    }
}
/* Remove v from the vertex list. */
static void
graph_rEMOVEfROMvERTEXlIST (Graph g, Vertex v)
{
  list vertices = g->vertices;

  assert (!element_null (g) && !element_null (v));
  while (!list_null (vertices))
    {
      if (list_head (vertices)->id == v->id)
	list_remove (&(g->vertices), vertices);
      vertices = list_next (vertices);
    }
}
示例#10
0
void list_destroy_string_class(position_t pos)
{
    list_null(pos);

    list_class_t *obj = (list_class_t*) pos->data;

    free(obj->className);

    free(pos->data);
    pos->data=NULL;
    pos->next=NULL;
    pos->prev=NULL;
}
static void
graph_dESTROYvERTEXlIST (Graph g)
{
  list vertices = g->vertices;
  Vertex v = list_head (vertices);

  assert (!element_null (g));
  while (!list_null (vertices))
    {
      v = list_head (vertices);
      graph_dESTROYvERTEXrEFERENCES (g, v);
      vertex_destroy (v);
      vertices = list_next (vertices);
    }
}
示例#12
0
文件: nfsfs.c 项目: dafyddcrosby/L4OS
/* check if the specified request is at the start of the list and should run */
static
int
check_request(NFS_BaseRequest *rq) {
	if (list_null(NfsRequests)) {
		dprintf(0, "!!! nfsfs: check_request NfsRequest list is null !!!\n");
		return run_request(rq);
	}

	/* Check at head of queue */
	NFS_BaseRequest *brq = (NFS_BaseRequest *) list_peek(NfsRequests);
	if (brq != rq) {
		return 0;
	}

	return run_request((NFS_BaseRequest *) list_peek(NfsRequests));
}
示例#13
0
/* Grab a free timer structure from the global free list.  The global
   lock must be held by the caller.  */
struct timer_node *
__timer_alloc (void)
{
  struct list_links *node = list_first (&timer_free_list);

  if (node != list_null (&timer_free_list))
    {
      struct timer_node *timer = timer_links2ptr (node);
      list_unlink_ip (node);
      timer->inuse = TIMER_INUSE;
      timer->refcount = 1;
      return timer;
    }

  return NULL;
}
示例#14
0
/* Allocate a thread structure from the global free list.  Global
   mutex lock must be held by caller.  The thread is moved to
   the active list. */
struct thread_node *
__timer_thread_alloc (const pthread_attr_t *desired_attr, clockid_t clock_id)
{
  struct list_links *node = list_first (&thread_free_list);

  if (node != list_null (&thread_free_list))
    {
      struct thread_node *thread = thread_links2ptr (node);
      list_unlink (node);
      thread_init (thread, desired_attr, clock_id);
      list_append (&thread_active_list, node);
      return thread;
    }

  return 0;
}
示例#15
0
int main (void)
{
    int n = 5;
    int i;
    ex *arr = malloc (sizeof (struct example) * n);
    list l;
    stack s;
    queue q;
    char h[6] = {'h', 'a', 'l', 'l', 'o', '\0'};

    list_init (&l);
    stack_init (&s);
    queue_init (&q);

    fprintf (stderr, "l, s, q\n");

    for (i = 0; i < n; i++)
    {
        arr[i].aChar = malloc (sizeof (char) * n);
        sprintf (arr[i].aChar, "%s:%d", h, i);

        /* You can test both append and prepend functions here. */
        list_append (arr + i, &l);
        stack_push (arr + i, &s);
        queue_enqueue (arr + i, &q);
        fprintf (stderr, "Lengths = %d, %d, %d\n", list_length (l), 
list_length (s), list_length (q));
    }

    while (!list_null (l) || !stack_null (s) || !queue_null (q))
    {
        fprintf (stderr, "%s ", (*(list_head (l))).aChar);
        list_remove (&l, l);
        fprintf (stderr, "%s ", (*(stack_pop (&s))).aChar);
        fprintf (stderr, "%s ", (*(queue_dequeue (&q))).aChar);
        fprintf (stderr, "\n");
    }

    fprintf (stderr, "\n");

    for (i = 0; i < n; i++)
        free (arr[i].aChar);
    free (arr);

    return 0;
}
示例#16
0
/* Search the list of active threads and find one which has matching
   attributes.  Global mutex lock must be held by caller.  */
struct thread_node *
__timer_thread_find_matching (const pthread_attr_t *desired_attr,
			      clockid_t desired_clock_id)
{
  struct list_head *iter = list_first (&thread_active_list);

  while (iter != list_null (&thread_active_list))
    {
      struct thread_node *candidate = thread_links2ptr (iter);

      if (thread_attr_compare (desired_attr, &candidate->attr)
	  && desired_clock_id == candidate->clock_id)
	return candidate;

      iter = list_next (iter);
    }

  return NULL;
}
示例#17
0
int
__timer_thread_queue_timer (struct thread_node *thread,
			    struct timer_node *insert)
{
  struct list_links *iter;
  int athead = 1;

  for (iter = list_first (&thread->timer_queue);
       iter != list_null (&thread->timer_queue);
        iter = list_next (iter))
    {
      struct timer_node *timer = timer_links2ptr (iter);

      if (timespec_compare (&insert->expirytime, &timer->expirytime) < 0)
	  break;
      athead = 0;
    }

  list_insbefore (iter, &insert->links);
  return athead;
}
示例#18
0
文件: timer.c 项目: dafyddcrosby/L4OS
static void
utimer(void)
{
	L4_KDB_SetThreadName(sos_my_tid(), "utimer");
	L4_Accept(L4_UntypedWordsAcceptor);

	List *entryq;
	entryq = list_empty();

	for (;;) {
		L4_Yield();

		// Walk the timer list
		L4_Word_t now = L4_KDB_GetTick();
		list_delete(entryq, processExpired, &now);

		// Wait for a new packet either blocking or non-blocking
		L4_MsgTag_t tag = L4_Niltag;
		if (list_null(entryq))
			L4_Set_ReceiveBlock(&tag);
		else
			L4_Clear_ReceiveBlock(&tag);

		L4_ThreadId_t wait_tid = L4_nilthread;
		tag = L4_Ipc(L4_nilthread, L4_anythread, tag, &wait_tid);

		if (!L4_IpcFailed(tag)) {
			// Received a time out request queue it
			L4_Msg_t msg; L4_MsgStore(tag, &msg);	// Get the message
			utimer_entry_t *entry = (utimer_entry_t *) L4_MsgWord(&msg, 0);
			entry->fTid  = wait_tid;
			list_shift(entryq, entry);
		}
		else if (3 == L4_ErrorCode()) // Receive error # 1
			continue;	// no-partner - non-blocking
		else
			assert(!"Unhandled IPC error");
	}
}
示例#19
0
thread_func (void *arg)
{
  struct thread_node *self = arg;

  /* Register cleanup handler, in case rogue application terminates
     this thread.  (This cannot happen to __timer_signal_thread, which
     doesn't invoke application callbacks). */

  pthread_cleanup_push (thread_cleanup, self);

  pthread_mutex_lock (&__timer_mutex);

  while (1)
    {
      struct list_links *first;
      struct timer_node *timer = NULL;

      /* While the timer queue is not empty, inspect the first node.  */
      first = list_first (&self->timer_queue);
      if (first != list_null (&self->timer_queue))
	{
	  struct timespec now;

	  timer = timer_links2ptr (first);

	  /* This assumes that the elements of the list of one thread
	     are all for the same clock.  */
	  clock_gettime (timer->clock, &now);

	  while (1)
	    {
	      /* If the timer is due or overdue, remove it from the queue.
		 If it's a periodic timer, re-compute its new time and
		 requeue it.  Either way, perform the timer expiry. */
	      if (timespec_compare (&now, &timer->expirytime) < 0)
		break;

	      list_unlink_ip (first);

	      if (__builtin_expect (timer->value.it_interval.tv_sec, 0) != 0
		  || timer->value.it_interval.tv_nsec != 0)
		{
		  timespec_add (&timer->expirytime, &now,
				&timer->value.it_interval);
		  __timer_thread_queue_timer (self, timer);
		}

	      thread_expire_timer (self, timer);

	      first = list_first (&self->timer_queue);
	      if (first == list_null (&self->timer_queue))
		break;

	      timer = timer_links2ptr (first);
	    }
	}

      /* If the queue is not empty, wait until the expiry time of the
	 first node.  Otherwise wait indefinitely.  Insertions at the
	 head of the queue must wake up the thread by broadcasting
	 this condition variable.  */
      if (timer != NULL)
	pthread_cond_timedwait (&self->cond, &__timer_mutex,
				&timer->expirytime);
      else
	pthread_cond_wait (&self->cond, &__timer_mutex);
    }
  /* This macro will never be executed since the while loop loops
     forever - but we have to add it for proper nesting.  */
  pthread_cleanup_pop (1);

}