Skip to content

Commit 516b6d0

Browse files
ewoodevsunghan-chang
authored andcommitted
pm: Replace pm_lock/pm_unlock with enter_critical_section
- Remove pm_lock/pm_unlock macros from pm.h - Use enter_critical_section in pm_register/pm_unregister - Remove pm_lock/pm_unlock calls from pm_metrics Signed-off-by: Eunwoo Nam <eunwoo.nam@samsung.com>
1 parent 854648d commit 516b6d0

File tree

4 files changed

+15
-42
lines changed

4 files changed

+15
-42
lines changed

os/pm/pm.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,6 @@
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
****************************************************************************/

os/pm/pm_metrics.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff 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
}

os/pm/pm_register.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,18 @@
8585

8686
int 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 */

os/pm/pm_unregister.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,18 @@
8585

8686
int 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 */

0 commit comments

Comments
 (0)