p_thread = &radio->thread[MM_RADIO_THREAD_SEEK];
MMRADIO_CHECK_ARG(p_thread);
+ MMRADIO_THREAD_LOCK(p_thread);
if (p_thread->is_running) {
MMRADIO_LOG_ERROR("[RADIO_ERROR_INVALID_OPERATION]radio is seeking, can't serve another request try again");
+ MMRADIO_THREAD_UNLOCK(p_thread);
return MM_ERROR_RADIO_INTERNAL;
}
+ MMRADIO_THREAD_UNLOCK(p_thread);
radio->seek_unmute = false;
p_thread = &radio->thread[MM_RADIO_THREAD_SCAN];
MMRADIO_CHECK_ARG(p_thread);
+ MMRADIO_THREAD_LOCK(p_thread);
+ if (p_thread->is_running) {
+ MMRADIO_LOG_ERROR("[MM_ERROR_RADIO_INVALID_STATE]radio is scanning, can't serve another request try again");
+ MMRADIO_THREAD_UNLOCK(p_thread);
+ return MM_ERROR_RADIO_INVALID_STATE;
+ }
+ MMRADIO_THREAD_UNLOCK(p_thread);
+
p_thread->stop = false;
ret = __mmradio_prepare_radio_device(radio);
MMRADIO_CHECK_ARG_RETURN_VOID(p_thread);
MMRADIO_THREAD_LOCK(p_thread);
- MMRADIO_THREAD_SIGNAL(p_thread);
- MMRADIO_THREAD_UNLOCK(p_thread);
-
- MMRADIO_THREAD_LOCK(p_thread);
while (!p_thread->thread_exit) {
- MMRADIO_LOG_DEBUG("scan thread started. waiting for signal.");
- MMRADIO_THREAD_WAIT(p_thread);
+ while (!p_thread->is_running) {
+ MMRADIO_LOG_DEBUG("scan thread started. waiting for signal.");
+ MMRADIO_THREAD_WAIT(p_thread);
+ }
if (p_thread->thread_exit) {
MMRADIO_LOG_DEBUG("exiting scan thread");
MMRADIO_CHECK_ARG_RETURN_VOID(p_thread);
MMRADIO_THREAD_LOCK(p_thread);
- MMRADIO_THREAD_SIGNAL(p_thread);
- MMRADIO_THREAD_UNLOCK(p_thread);
-
- MMRADIO_THREAD_LOCK(p_thread);
while (!p_thread->thread_exit) {
- MMRADIO_LOG_DEBUG("seek thread started. waiting for signal.");
- MMRADIO_THREAD_WAIT(p_thread);
+ while (!p_thread->is_running) {
+ MMRADIO_LOG_DEBUG("seek thread started. waiting for signal.");
+ MMRADIO_THREAD_WAIT(p_thread);
+ }
if (p_thread->thread_exit) {
MMRADIO_LOG_DEBUG("exiting seek thread");
MMRADIO_LOG_INFO("Setting %f volume", volume);
- MMRADIO_VOLUME_LOCK(radio);
radio->local_volume = volume;
if (radio->vstream)
sound_manager_set_virtual_stream_volume(radio->vstream,
(double)radio->local_volume);
- MMRADIO_VOLUME_UNLOCK(radio);
-
MMRADIO_LOG_FLEAVE();
return MM_ERROR_NONE;
MMRADIO_RETURN_VAL_IF_FAIL(pVolume, MM_ERROR_INVALID_ARGUMENT);
- MMRADIO_VOLUME_LOCK(radio);
*pVolume = radio->local_volume;
- MMRADIO_VOLUME_UNLOCK(radio);
MMRADIO_LOG_FLEAVE();
}
p_thread = &radio->thread[type];
+ p_thread->is_running = false;
MMRADIO_CHECK_ARG(p_thread);
MMRADIO_INIT_MUTEX(p_thread->mutex);
MMRADIO_INIT_COND(p_thread->cond);
- MMRADIO_THREAD_LOCK(p_thread);
p_thread->thread_id = pthread_create(&p_thread->thread, NULL,
(void *)__mmradio_thread_function[type], (void *)radio);
if (p_thread->thread_id) {
MMRADIO_LOG_DEBUG("failed to create thread : [%d]", type);
- MMRADIO_THREAD_UNLOCK(p_thread);
return MM_ERROR_RADIO_INTERNAL;
}
- MMRADIO_LOG_DEBUG("wait for [%d] thread", type);
- MMRADIO_THREAD_WAIT(p_thread);
- MMRADIO_LOG_DEBUG("[%d] thread started", type);
- MMRADIO_THREAD_UNLOCK(p_thread);
-
return MM_ERROR_NONE;
ERROR:
MMRADIO_CHECK_INSTANCE(radio);
MMRADIO_INIT_MUTEX(radio->cmd_lock);
- MMRADIO_INIT_MUTEX(radio->volume_lock);
MMRADIO_INIT_MUTEX(radio->hal_seek_mutex);
for (type = (int)MM_RADIO_THREAD_MSG; type < (int)MM_RADIO_THREAD_NUM; type++) {
ERROR:
pthread_mutex_destroy(&radio->cmd_lock);
- pthread_mutex_destroy(&radio->volume_lock);
pthread_mutex_destroy(&radio->hal_seek_mutex);
MMRADIO_LOG_FLEAVE();
case MM_RADIO_THREAD_SCAN:
MMRADIO_THREAD_LOCK(p_thread);
p_thread->thread_exit = true;
+ p_thread->is_running = true;
MMRADIO_THREAD_SIGNAL(p_thread);
MMRADIO_THREAD_UNLOCK(p_thread);
pthread_join(p_thread->thread, NULL);
__mmradio_destroy_thread_type(radio, (MMRadioThreadTypes)type);
pthread_mutex_destroy(&radio->cmd_lock);
- pthread_mutex_destroy(&radio->volume_lock);
pthread_mutex_destroy(&radio->hal_seek_mutex);
MMRADIO_LOG_FLEAVE();
p_thread->thread_exit = false;
-
- MMRADIO_THREAD_LOCK(p_thread);
- MMRADIO_THREAD_SIGNAL(p_thread);
- MMRADIO_THREAD_UNLOCK(p_thread);
-
/* we run a while one loop*/
while (!p_thread->thread_exit) {
msg = (mm_radio_msg_t *)g_async_queue_pop(radio->msg_queue);
ret = mm_resource_manager_commit(radio->resource_manager);
if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
MMRADIO_LOG_ERROR("failed to commit resource manager");
- mm_resource_manager_mark_for_release(radio->resource_manager,
- radio->radio_resource);
radio->radio_resource = NULL;
return ret;
}