Changeset 19bd84c786fecb77531073b697aad4d3c221d15d
- Timestamp:
- 05/07/08 21:41:01
(3 months ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1210189261 +0300
- git-parent:
[7b4e7dc93dd9bf941bcfe2e2911bbf1de86d7bc6]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1210189248 +0300
- Message:
Remove useless i_refcount == 0 case and fix a tiny race condition.
When i_refcount drops to zero (under the structure lock), the object is
removed from the objects table before the structure lock is released.
Hence, no objects with a nul refcount can ever be left in the table.
There is an unlikely race condition if another object is removed from
the table right between we unlock the structure lock but before we
return from vlc_object_get() (so that the i_middle offset gets wrong).
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rb8909e1 |
r19bd84c |
|
| 687 | 687 | vlc_object_t **pp_objects; |
|---|
| 688 | 688 | libvlc_global_data_t *p_libvlc_global = vlc_global(); |
|---|
| | 689 | vlc_object_t *obj = NULL; |
|---|
| 689 | 690 | |
|---|
| 690 | 691 | vlc_mutex_lock( &structure_lock ); |
|---|
| … | … | |
| 711 | 712 | { |
|---|
| 712 | 713 | /* This happens when there are only two remaining objects */ |
|---|
| 713 | | if( pp_objects[i_middle+1]->i_object_id == i_id |
|---|
| 714 | | && vlc_internals( pp_objects[i_middle+1] )->i_refcount > 0 ) |
|---|
| | 714 | if( pp_objects[i_middle+1]->i_object_id == i_id ) |
|---|
| 715 | 715 | { |
|---|
| 716 | 716 | vlc_object_yield_locked( pp_objects[i_middle+1] ); |
|---|
| 717 | | vlc_mutex_unlock( &structure_lock ); |
|---|
| 718 | | return pp_objects[i_middle+1]; |
|---|
| | 717 | obj = pp_objects[i_middle+1]; |
|---|
| 719 | 718 | } |
|---|
| 720 | 719 | break; |
|---|
| 721 | 720 | } |
|---|
| 722 | 721 | } |
|---|
| 723 | | else if( vlc_internals( pp_objects[i_middle] )->i_refcount > 0 ) |
|---|
| | 722 | else |
|---|
| 724 | 723 | { |
|---|
| 725 | 724 | vlc_object_yield_locked( pp_objects[i_middle] ); |
|---|
| … | … | |
| 727 | 726 | return pp_objects[i_middle]; |
|---|
| 728 | 727 | } |
|---|
| 729 | | |
|---|
| 730 | | if( i_max == 0 ) |
|---|
| 731 | | { |
|---|
| 732 | | /* this means that i_max == i_middle, and since we have already |
|---|
| 733 | | * tested pp_objects[i_middle]), p_found is properly set. */ |
|---|
| 734 | | break; |
|---|
| 735 | | } |
|---|
| 736 | 728 | } |
|---|
| 737 | 729 | |
|---|
| 738 | 730 | vlc_mutex_unlock( &structure_lock ); |
|---|
| 739 | | return NULL; |
|---|
| | 731 | return obj; |
|---|
| 740 | 732 | } |
|---|
| 741 | 733 | |
|---|