File tree Expand file tree Collapse file tree 4 files changed +15
-42
lines changed
Expand file tree Collapse file tree 4 files changed +15
-42
lines changed Original file line number Diff line number Diff line change 6767
6868#ifdef CONFIG_PM
6969
70- /* Function-like macros *****************************************************/
71- /****************************************************************************
72- * Name: pm_lock
73- *
74- * Descripton:
75- * Lock the power management registry. NOTE: This function may return
76- * an error if a signal is received while what (errno == EINTR).
77- *
78- ****************************************************************************/
79-
80- #define pm_lock () sem_wait(&g_pmglobals.regsem);
81-
82- /****************************************************************************
83- * Name: pm_unlock
84- *
85- * Descripton:
86- * Unlock the power management registry.
87- *
88- ****************************************************************************/
89-
90- #define pm_unlock () sem_post(&g_pmglobals.regsem);
91-
9270/****************************************************************************
9371 * Public Types
9472 ****************************************************************************/
Original file line number Diff line number Diff line change @@ -295,23 +295,22 @@ int pm_metrics(int milliseconds)
295295 pmdbg ("Please Start PM to enable PM Metrics\n" );
296296 return OK ;
297297 }
298- /* Lock PM so that no two thread can run PM Metrics simultaneously */
299- pm_lock ();
300298
301299 /* Allocate memory for initializing PM Metrics measurements */
302300 g_pm_metrics = (pm_metric_t * )kmm_calloc (1 , sizeof (pm_metric_t ));
303301 if (g_pm_metrics == NULL ) {
304302 set_errno (ENOMEM );
305303 pmdbg ("Unable to initialize pm_metrics, error = %d\n" , get_errno ());
306- pm_unlock ();
307304 return ERROR ;
308305 }
306+
307+ flags = enter_critical_section ();
308+
309309 /* PM Metrics Initialization */
310310 for (index = 0 ; index < PM_COUNT ; index ++ ) {
311311 g_pm_metrics -> state_metrics .state_accum_ticks [index ] = 0 ;
312312 }
313313
314- flags = enter_critical_section ();
315314 start_time = clock_systimer ();
316315 g_pm_metrics -> state_metrics .stime = start_time ;
317316
@@ -348,7 +347,5 @@ int pm_metrics(int milliseconds)
348347 kmm_free (g_pm_metrics );
349348 g_pm_metrics = NULL ;
350349
351- /* Unlock PM Metrics for other threads */
352- pm_unlock ();
353350 return OK ;
354351}
Original file line number Diff line number Diff line change 8585
8686int pm_register (FAR struct pm_callback_s * callbacks )
8787{
88- int ret ;
88+ irqstate_t flags ;
8989
9090 DEBUGASSERT (callbacks );
9191
92+ flags = enter_critical_section ();
93+
9294 /* Add the new entry to the end of the list of registered callbacks */
95+ dq_addlast (& callbacks -> entry , & g_pmglobals .registry );
9396
94- ret = pm_lock ();
95- if (ret == OK ) {
96- dq_addlast (& callbacks -> entry , & g_pmglobals .registry );
97- pm_unlock ();
98- }
97+ leave_critical_section (flags );
9998
100- return ret ;
99+ return OK ;
101100}
102101
103102#endif /* CONFIG_PM */
Original file line number Diff line number Diff line change 8585
8686int pm_unregister (FAR struct pm_callback_s * callbacks )
8787{
88- int ret ;
88+ irqstate_t flags ;
8989
9090 DEBUGASSERT (callbacks );
9191
92+ flags = enter_critical_section ();
93+
9294 /* Remove entry from the list of registered callbacks. */
95+ dq_rem (& callbacks -> entry , & g_pmglobals .registry );
9396
94- ret = pm_lock ();
95- if (ret == OK ) {
96- dq_rem (& callbacks -> entry , & g_pmglobals .registry );
97- pm_unlock ();
98- }
97+ leave_critical_section (flags );
9998
100- return ret ;
99+ return OK ;
101100}
102101
103102#endif /* CONFIG_PM */
You can’t perform that action at this time.
0 commit comments