@@ -62,7 +62,7 @@ static const char* strip_path(const char* const filename)
62
62
return filename ;
63
63
}
64
64
65
- static size_t sleep_tracker_find_index (const char * const filename )
65
+ static sleep_statistic_t * sleep_tracker_find (const char * const filename )
66
66
{
67
67
char temp [IDENTIFIER_WIDTH ];
68
68
strncpy (temp , filename , IDENTIFIER_WIDTH );
@@ -71,14 +71,14 @@ static size_t sleep_tracker_find_index(const char *const filename)
71
71
// Search for the a driver matching the current name and return it's index
72
72
for (int i = 0 ; i < STATISTIC_COUNT ; ++ i ) {
73
73
if (strcmp (sleep_stats [i ].identifier , temp ) == 0 ) {
74
- return i ;
74
+ return & sleep_stats [ i ] ;
75
75
}
76
76
}
77
77
78
- return -1 ;
78
+ return NULL ;
79
79
}
80
80
81
- static size_t sleep_tracker_add (const char * const filename )
81
+ static sleep_statistic_t * sleep_tracker_add (const char * const filename )
82
82
{
83
83
char temp [IDENTIFIER_WIDTH ];
84
84
strncpy (temp , filename , IDENTIFIER_WIDTH );
@@ -90,14 +90,14 @@ static size_t sleep_tracker_add(const char* const filename)
90
90
strncpy (sleep_stats [i ].identifier , temp , sizeof (temp ));
91
91
core_util_critical_section_exit ();
92
92
93
- return i ;
93
+ return & sleep_stats [ i ] ;
94
94
}
95
95
}
96
96
97
97
// Panic if there are no free indexes left to track with
98
98
error ("No free indexes left to use in mbed stats tracker" );
99
99
100
- return -1 ;
100
+ return NULL ;
101
101
}
102
102
103
103
static void sleep_tracker_print_stats (void )
@@ -120,29 +120,29 @@ void sleep_tracker_lock(const char* const filename, int line)
120
120
{
121
121
const char * const stripped_path = strip_path (filename );
122
122
123
- size_t index = sleep_tracker_find_index (stripped_path );
123
+ sleep_statistic_t * stat = sleep_tracker_find (stripped_path );
124
124
125
125
// Entry for this driver does not exist, create one.
126
- if (index == -1 ) {
127
- index = sleep_tracker_add (filename );
126
+ if (stat == NULL ) {
127
+ stat = sleep_tracker_add (filename );
128
128
}
129
129
130
- core_util_atomic_incr_u8 (& sleep_stats [ index ]. count , 1 );
130
+ core_util_atomic_incr_u8 (& stat -> count , 1 );
131
131
132
132
printf ("LOCK: %s, ln: %i, lock count: %u\r\n" , stripped_path , line , deep_sleep_lock );
133
133
}
134
134
135
135
void sleep_tracker_unlock (const char * const filename , int line )
136
136
{
137
137
const char * const stripped_path = strip_path (filename );
138
- size_t index = sleep_tracker_find_index (stripped_path );
138
+ sleep_statistic_t * stat = sleep_tracker_find (stripped_path );
139
139
140
140
// Entry for this driver does not exist, something went wrong.
141
- if (index == -1 ) {
141
+ if (stat == NULL ) {
142
142
error ("Unlocking sleep for driver that was not previously locked." );
143
143
}
144
144
145
- core_util_atomic_decr_u8 (& sleep_stats [ index ]. count , 1 );
145
+ core_util_atomic_decr_u8 (& stat -> count , 1 );
146
146
147
147
printf ("UNLOCK: %s, ln: %i, lock count: %u\r\n" , stripped_path , line , deep_sleep_lock );
148
148
sleep_tracker_print_stats ();
0 commit comments