Added barriers
This commit is contained in:
@@ -435,5 +435,48 @@ void _vx_e_mat_mult(unsigned tid, unsigned wid)
|
||||
|
||||
}
|
||||
|
||||
void sleep(int num)
|
||||
{
|
||||
for (int i = 0; i < num; i++);
|
||||
}
|
||||
|
||||
|
||||
bool barrier_bool = false;
|
||||
bool barriers[32];
|
||||
|
||||
void barrier(unsigned wid, int num)
|
||||
{
|
||||
barriers[wid] = true;
|
||||
|
||||
if (wid == 0)
|
||||
{
|
||||
bool cont = false;
|
||||
int count = 0;
|
||||
while(cont)
|
||||
{
|
||||
count = 0;
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
if (barriers[i]) count++;
|
||||
}
|
||||
|
||||
if (count == num)
|
||||
{
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
barriers[i] = false;
|
||||
barrier_bool = true;
|
||||
sleep(70);
|
||||
barrier_bool = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while(!barrier_bool);
|
||||
sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
40
kernel/vx_include/vx_mem.c
Normal file
40
kernel/vx_include/vx_mem.c
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
#include "vx_mem.h"
|
||||
|
||||
|
||||
void * vx_malloc_shared(unsigned size)
|
||||
{
|
||||
void * to_return;
|
||||
|
||||
bool done = false;
|
||||
unsigned curr_size;
|
||||
|
||||
unsigned curr_index = 0;
|
||||
while ((curr_index < free_index) && !done)
|
||||
{
|
||||
curr_size = (unsigned) *(free_array[curr_index].ptr - 4);
|
||||
if (curr_size <= size)
|
||||
{
|
||||
to_return = free_array[curr_index].ptr;
|
||||
done = true;
|
||||
}
|
||||
|
||||
curr_index++;
|
||||
}
|
||||
|
||||
unsigned * u_heap_ptr = (unsigned *) heap_ptr;
|
||||
|
||||
if (!done)
|
||||
{
|
||||
u_heap_ptr[0] = size;
|
||||
to_return = heap_ptr + 4;
|
||||
heap_ptr = to_return + size;
|
||||
}
|
||||
|
||||
return to_return;
|
||||
}
|
||||
|
||||
void vx_free(void * to_free)
|
||||
{
|
||||
|
||||
}
|
||||
15
kernel/vx_include/vx_mem.h
Normal file
15
kernel/vx_include/vx_mem.h
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
void * vx_malloc_shared(unsigned);
|
||||
void vx_free(void *);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void * ptr;
|
||||
|
||||
} free_t;
|
||||
|
||||
void * heap_ptr = (void *) 0xFF000000;
|
||||
|
||||
free_t free_array[100];
|
||||
unsigned free_index = 0;
|
||||
|
||||
Reference in New Issue
Block a user