diff options
author | Joseph Lo <jlo@marvell.com> | 2010-10-28 16:38:27 +0800 |
---|---|---|
committer | Joseph Lo <jlo@marvell.com> | 2010-10-28 16:38:27 +0800 |
commit | 994f72319cf33dba0986b0e88469058dea245fbf (patch) | |
tree | 9a9e3de3ab9e10132058133fcb731834093d83f7 | |
parent | 828f4288fc25b202efc51db1f047240afa61dfb5 (diff) |
fix abnormal exit logic
Currently, we only check the lock status. In fact, we should check the
register or used status, too. So changed the logic in code. This can
help to clear the unwanted lock or instance entry when abnormal exit happens.
-rwxr-xr-x | vmeta_lib.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/vmeta_lib.c b/vmeta_lib.c index a1a69bf..60c438c 100755 --- a/vmeta_lib.c +++ b/vmeta_lib.c @@ -815,17 +815,28 @@ int vmeta_thread_monitor(struct monitor_data * p_md) pthread_join(p_md->pt,NULL); dbg_printf(VDEC_DEBUG_LOCK,"pt=0x%x is killed user_id(%d)\n",p_md->pt,p_md->user_id); - if( (p_ks->lock_flag==VMETA_LOCK_ON) && (p_md->user_id==p_ks->active_user_id)) - { - vdec_os_api_unlock(p_md->user_id); - + if(p_md->user_id==p_ks->active_user_id) { + + dbg_printf(VDEC_DEBUG_LOCK,"vmeta thread exit abnormally, instance id=%d lock flag=%d\n",p_md->user_id,p_ks->lock_flag); + if( p_ks->lock_flag==VMETA_LOCK_ON ) { + vdec_os_api_unlock(p_md->user_id); + vmeta_private_lock(); + p_ks->lock_flag = VMETA_LOCK_FORCE_INIT; + vmeta_private_unlock(); + } vmeta_private_lock(); - p_ks->lock_flag = VMETA_LOCK_FORCE_INIT; - p_ks->ref_count--; - memset(&(p_ks->user_id_list[p_ks->active_user_id]),0x0,sizeof(id_instance)); + p_ks->active_user_id = MAX_VMETA_INSTANCE; vmeta_private_unlock(); } + vmeta_private_lock(); + if(p_ks->user_id_list[p_md->user_id].status != 0) { + dbg_printf(VDEC_DEBUG_LOCK,"vmeta thread exit abnormally, clear instance(%d)\n",p_md->user_id); + memset(&(p_ks->user_id_list[p_md->user_id]),0x0,sizeof(id_instance)); + p_ks->ref_count--; + } + vmeta_private_unlock(); + free(p_md);//This is malloced in register function pthread_attr_destroy(&pat); return 0; @@ -875,7 +886,7 @@ tag_monitor_fail: p_md->user_id = user_id; pthread_create(&tmp,NULL,vmeta_thread_monitor,p_md); - dbg_printf(VDEC_DEBUG_LOCK,"pid=0x%x,pt=0x%x are monitored user_id(%d)\n",p_ks->user_id_list[user_id].pid,p_ks->user_id_list[user_id].pt,user_id); + dbg_printf(VDEC_DEBUG_LOCK,"pid=%x,pt=0x%x are monitored user_id(%d)\n",p_ks->user_id_list[user_id].pid,p_ks->user_id_list[user_id].pt,user_id); return VDEC_OS_DRIVER_OK; @@ -955,7 +966,8 @@ tag_monitor_fail: p_ks = (kernel_share*)p_cb->kernel_share_va; if(p_ks->active_user_id == user_id) { - dbg_printf(VDEC_DEBUG_LOCK,"lock same user\n"); + dbg_printf(VDEC_DEBUG_LOCK,"lock same user=%d, lock_flag=%d,ref_count=%d\n",\ + user_id,p_ks->lock_flag,p_ks->ref_count); return LOCK_RET_ME;//just return since they are the same caller } |