Browse Source

mic: add task_fifo.h and task_fifo.c in driver/mp_common

Thibaud Lambert 12 years ago
parent
commit
ab022067e9
2 changed files with 92 additions and 0 deletions
  1. 34 0
      src/drivers/mp_common/task_fifo.c
  2. 58 0
      src/drivers/mp_common/task_fifo.h

+ 34 - 0
src/drivers/mp_common/task_fifo.c

@@ -0,0 +1,34 @@
+#include "task_fifo.h"
+
+void task_fifo_init(struct task_fifo* fifo){
+  fifo->first = fifo->last = NULL;
+  pthread_mutex_init(&(fifo->mutex), NULL);
+}
+
+int task_fifo_is_empty(struct task_fifo* fifo){
+  return fifo->first == NULL;
+}
+
+void task_fifo_append(struct task_fifo* fifo, struct task * task){
+  pthread_mutex_lock(&(fifo->mutex));
+  if(task_fifo_is_empty(fifo)){
+    fifo->first = fifo->last = task;
+  }
+  else{
+    fifo->last->next = task;
+    fifo->last = task;
+  }
+  task->next = NULL;
+  pthread_mutex_unlock(&(fifo->mutex));
+}
+
+void task_fifo_pop(struct task_fifo* fifo){
+  pthread_mutex_lock(&(fifo->mutex));
+  if(!task_fifo_is_empty(fifo)){
+    if(fifo->first == fifo->last)
+      fifo->first = fifo->last = NULL;
+    else
+      fifo->first = fifo->first->next; 
+  }
+  pthread_mutex_unlock(&(fifo->mutex));
+}

+ 58 - 0
src/drivers/mp_common/task_fifo.h

@@ -0,0 +1,58 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2012  Inria
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#ifndef __TASK_FIFO_H__
+#define __TASK_FIFO_H__
+
+#include <pthread.h>
+
+#include <starpu.h>
+#include <common/config.h>
+
+
+struct task{
+  struct _starpu_mp_node *node;
+  void (*kernel)(void **, void *);
+  void *interfaces[STARPU_NMAXBUFS]; 
+  void *cl_arg;
+  unsigned coreid;
+
+  /*the next task of the fifo*/
+  struct task * next;
+};
+
+
+struct task_fifo{
+  /*the first task of the fifo*/
+  struct task * first;
+  
+  /*the last task of the fifo*/
+  struct task * last;
+
+  /*mutex to protect concurrent access on the fifo*/
+  pthread_mutex_t mutex;
+};
+
+
+void task_fifo_init(struct task_fifo* fifo);
+
+int task_fifo_is_empty(struct task_fifo* fifo);
+
+void task_fifo_append(struct task_fifo* fifo, struct task * task);
+
+void task_fifo_pop(struct task_fifo* fifo);
+
+#endif /* __TASK_FIFO_H__*/