-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initialize monitors only once in network
- Loading branch information
Showing
5 changed files
with
87 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
dory/Hardware_targets/PULP/GAP9_NE16/Utils_files/monitor.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "monitor.h" | ||
#include "pmsis.h" | ||
|
||
|
||
int monitor_init(Monitor * const monitor, int buffer_size) { | ||
monitor->empty = pi_cl_sem_alloc(); | ||
if (monitor->empty == 0) { | ||
return -1; | ||
} | ||
|
||
monitor->full = pi_cl_sem_alloc(); | ||
if (monitor->full == 0) { | ||
pi_cl_sem_free(monitor->empty); | ||
return -2; | ||
} | ||
|
||
pi_cl_sem_set(monitor->full, 0); | ||
pi_cl_sem_set(monitor->empty, buffer_size); | ||
|
||
return 0; | ||
} | ||
|
||
void monitor_term(Monitor monitor) { | ||
pi_cl_sem_free(monitor.empty); | ||
pi_cl_sem_free(monitor.full); | ||
} | ||
|
||
void monitor_produce_begin(Monitor monitor) { | ||
pi_cl_sem_dec(monitor.empty); | ||
} | ||
|
||
void monitor_produce_end(Monitor monitor) { | ||
pi_cl_sem_inc(monitor.full, 1); | ||
} | ||
|
||
void monitor_consume_begin(Monitor monitor) { | ||
pi_cl_sem_dec(monitor.full); | ||
} | ||
|
||
void monitor_consume_end(Monitor monitor) { | ||
pi_cl_sem_inc(monitor.empty, 1); | ||
} |
51 changes: 12 additions & 39 deletions
51
dory/Hardware_targets/PULP/GAP9_NE16/Utils_files/monitor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,20 @@ | ||
#include "pmsis.h" | ||
#ifndef __MONITOR_H__ | ||
#define __MONITOR_H__ | ||
|
||
#include <stdint.h> | ||
|
||
|
||
typedef struct Monitor { | ||
uint32_t empty; | ||
uint32_t full; | ||
} Monitor; | ||
|
||
|
||
static int monitor_init(Monitor * const monitor, int buffer_size) { | ||
monitor->empty = pi_cl_sem_alloc(); | ||
if (monitor->empty == 0) { | ||
return -1; | ||
} | ||
|
||
monitor->full = pi_cl_sem_alloc(); | ||
if (monitor->full == 0) { | ||
pi_cl_sem_free(monitor->empty); | ||
return -2; | ||
} | ||
|
||
pi_cl_sem_set(monitor->full, 0); | ||
pi_cl_sem_set(monitor->empty, buffer_size); | ||
|
||
return 0; | ||
} | ||
|
||
static void monitor_term(Monitor monitor) { | ||
pi_cl_sem_free(monitor.empty); | ||
pi_cl_sem_free(monitor.full); | ||
} | ||
|
||
static void monitor_produce_begin(Monitor monitor) { | ||
pi_cl_sem_dec(monitor.empty); | ||
} | ||
|
||
static void monitor_produce_end(Monitor monitor) { | ||
pi_cl_sem_inc(monitor.full, 1); | ||
} | ||
|
||
static void monitor_consume_begin(Monitor monitor) { | ||
pi_cl_sem_dec(monitor.full); | ||
} | ||
|
||
static void monitor_consume_end(Monitor monitor) { | ||
pi_cl_sem_inc(monitor.empty, 1); | ||
} | ||
int monitor_init(Monitor * const monitor, int buffer_size); | ||
void monitor_term(Monitor monitor); | ||
void monitor_produce_begin(Monitor monitor); | ||
void monitor_produce_end(Monitor monitor); | ||
void monitor_consume_begin(Monitor monitor); | ||
void monitor_consume_end(Monitor monitor); | ||
|
||
#endif // __MONITOR_H__ |