Skip to content

Commit

Permalink
Statically zero-initialize Epiphany mutex
Browse files Browse the repository at this point in the history
Signed-off-by: Ola Jeppsson <ola@adapteva.com>
  • Loading branch information
olajep committed May 9, 2016
1 parent 55c85cf commit 87e6021
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions code/EpFaceCore_commonlib/src/device_cascade_detector.c
Expand Up @@ -40,12 +40,8 @@
#define BANK3 0x6000
//(EpCoreBank3 *)BANK3

//e_mutex_t mutex;


/**
* @return global pointer to mutex in first core
*/
/* Global mutex */
e_mutex_t global_mutex = 0;

/**
* Get pointer on begin of Shared memory structure.
Expand Down Expand Up @@ -129,13 +125,11 @@ static void dma_transfer (
* @return unmodified (*val) value
*/
static int atomic_increment(int volatile *const val, int const max_val) {
e_mutex_t *mutex_p = (void *)0x00004000;

e_mutex_lock(0, 0, mutex_p);
e_mutex_lock(0, 0, &global_mutex);
int const cur_val = *val;
if(cur_val < max_val)
*val = cur_val + 1;
e_mutex_unlock(0, 0, mutex_p);
e_mutex_unlock(0, 0, &global_mutex);

return cur_val;
}
Expand All @@ -147,13 +141,11 @@ static int atomic_increment(int volatile *const val, int const max_val) {
* @return unmodified (*val) value
*/
static int atomic_decrement(int volatile * const val, int const min_val) {
e_mutex_t *mutex_p = (void *)0x00004000;

e_mutex_lock(0, 0, mutex_p);
e_mutex_lock(0, 0, &global_mutex);
int const cur_val = *val;
if(cur_val > min_val)
*val = cur_val - 1;
e_mutex_unlock(0, 0, mutex_p);
e_mutex_unlock(0, 0, &global_mutex);

return cur_val;
}
Expand All @@ -166,15 +158,9 @@ int mc_core_common_go()
unsigned row = 0;
unsigned col = 0;
e_coreid_t coreid = 0;
e_mutex_t *mutex = NULL;
// Must be initialized ONLY on one core
mutex = (int *)0x00004000;
coreid = e_get_coreid();
e_coords_from_coreid(coreid, &row, &col);
if ( (0==row) && (0==col) )
{
e_mutex_init(0, 0, mutex, NULL);
}
#endif
((EpCoreBank1 *)BANK1)->timer.core_id = e_get_coreid();

Expand Down

0 comments on commit 87e6021

Please sign in to comment.