@@ -75,9 +75,15 @@ static size_t sleep_tracker_find_index(const char *const filename)
75
75
}
76
76
}
77
77
78
- // If no driver was found currently in the structure, find the first array
79
- // index that hasn't been used by a driver and fill it, then return the
80
- // index.
78
+ return -1 ;
79
+ }
80
+
81
+ static size_t sleep_tracker_add (const char * const filename )
82
+ {
83
+ char temp [IDENTIFIER_WIDTH ];
84
+ strncpy (temp , filename , IDENTIFIER_WIDTH );
85
+ temp [IDENTIFIER_WIDTH - 1 ] = '\0' ;
86
+
81
87
for (int i = 0 ; i < STATISTIC_COUNT ; ++ i ) {
82
88
if (sleep_stats [i ].identifier [0 ] == '\0' ) {
83
89
core_util_critical_section_enter ();
@@ -113,8 +119,14 @@ static void sleep_tracker_print_stats(void)
113
119
void sleep_tracker_lock (const char * const filename , int line )
114
120
{
115
121
const char * const stripped_path = strip_path (filename );
122
+
116
123
size_t index = sleep_tracker_find_index (stripped_path );
117
124
125
+ // Entry for this driver does not exist, create one.
126
+ if (index == -1 ) {
127
+ index = sleep_tracker_add (filename );
128
+ }
129
+
118
130
core_util_atomic_incr_u8 (& sleep_stats [index ].count , 1 );
119
131
120
132
printf ("LOCK: %s, ln: %i, lock count: %u\r\n" , stripped_path , line , deep_sleep_lock );
@@ -125,6 +137,11 @@ void sleep_tracker_unlock(const char* const filename, int line)
125
137
const char * const stripped_path = strip_path (filename );
126
138
size_t index = sleep_tracker_find_index (stripped_path );
127
139
140
+ // Entry for this driver does not exist, something went wrong.
141
+ if (index == -1 ) {
142
+ error ("Unlocking sleep for driver that was not previously locked." );
143
+ }
144
+
128
145
core_util_atomic_decr_u8 (& sleep_stats [index ].count , 1 );
129
146
130
147
printf ("UNLOCK: %s, ln: %i, lock count: %u\r\n" , stripped_path , line , deep_sleep_lock );
0 commit comments