Changeset 3fc79afe9fcd780a3b10af5e714905c5e530d317
- Timestamp:
- 27/03/08 21:10:57
(6 months ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1206648657 +0200
- git-parent:
[54aad20bb04de5de5a70237163981d0cf50d7bdb]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1206648657 +0200
- Message:
hotkeys: cleanup locking
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rf016819 |
r3fc79af |
|
| 52 | 52 | struct intf_sys_t |
|---|
| 53 | 53 | { |
|---|
| 54 | | vlc_mutex_t change_lock; /* mutex to keep the callback |
|---|
| 55 | | * and the main loop from |
|---|
| 56 | | * stepping on each others |
|---|
| 57 | | * toes */ |
|---|
| 58 | 54 | int p_keys[ BUFFER_SIZE ]; /* buffer that contains |
|---|
| 59 | 55 | * keyevents */ |
|---|
| … | … | |
| 112 | 108 | MALLOC_ERR( p_intf->p_sys, intf_sys_t ); |
|---|
| 113 | 109 | |
|---|
| 114 | | vlc_mutex_init( p_intf, &p_intf->p_sys->change_lock ); |
|---|
| 115 | 110 | p_intf->p_sys->i_size = 0; |
|---|
| 116 | 111 | p_intf->pf_run = Run; |
|---|
| … | … | |
| 129 | 124 | var_DelCallback( p_intf->p_libvlc, "key-pressed", KeyEvent, p_intf ); |
|---|
| 130 | 125 | |
|---|
| 131 | | vlc_mutex_destroy( &p_intf->p_sys->change_lock ); |
|---|
| 132 | 126 | /* Destroy structure */ |
|---|
| 133 | 127 | free( p_intf->p_sys ); |
|---|
| … | … | |
| 139 | 133 | static void Run( intf_thread_t *p_intf ) |
|---|
| 140 | 134 | { |
|---|
| 141 | | input_thread_t *p_input = NULL; |
|---|
| 142 | 135 | vout_thread_t *p_vout = NULL; |
|---|
| 143 | | vout_thread_t *p_last_vout = NULL; |
|---|
| 144 | 136 | struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys; |
|---|
| 145 | 137 | vlc_value_t val; |
|---|
| … | … | |
| 159 | 151 | } |
|---|
| 160 | 152 | |
|---|
| 161 | | for( vlc_bool_t b_quit = VLC_FALSE ; !b_quit; ) |
|---|
| | 153 | for( ;; ) |
|---|
| 162 | 154 | { |
|---|
| 163 | | int i_key, i_action; |
|---|
| | 155 | input_thread_t *p_input; |
|---|
| | 156 | vout_thread_t *p_last_vout; |
|---|
| 164 | 157 | int i_times = 0; |
|---|
| 165 | | |
|---|
| 166 | | /* Sleep a bit */ |
|---|
| 167 | | /* msleep( INTF_IDLE_SLEEP ); */ |
|---|
| 168 | | |
|---|
| 169 | | i_action = 0; |
|---|
| 170 | | i_key = GetKey( p_intf ); |
|---|
| | 158 | int i_action = 0; |
|---|
| | 159 | int i_key = GetKey( p_intf ); |
|---|
| | 160 | |
|---|
| | 161 | if( i_key == -1 ) |
|---|
| | 162 | break; /* die */ |
|---|
| 171 | 163 | |
|---|
| 172 | 164 | /* Special action for mouse event */ |
|---|
| … | … | |
| 205 | 197 | } |
|---|
| 206 | 198 | } |
|---|
| 207 | | } |
|---|
| 208 | | |
|---|
| 209 | | if( !i_action ) |
|---|
| 210 | | { |
|---|
| 211 | | b_quit = vlc_object_lock_and_wait( p_intf ); |
|---|
| 212 | | /* No key pressed, sleep a bit more */ |
|---|
| 213 | | continue; |
|---|
| 214 | 199 | } |
|---|
| 215 | 200 | |
|---|
| … | … | |
| 873 | 858 | } |
|---|
| 874 | 859 | |
|---|
| 875 | | static int GetKey( intf_thread_t *p_intf) |
|---|
| 876 | | { |
|---|
| 877 | | vlc_mutex_lock( &p_intf->p_sys->change_lock ); |
|---|
| 878 | | if ( p_intf->p_sys->i_size == 0 ) |
|---|
| | 860 | static int GetKey( intf_thread_t *p_intf ) |
|---|
| | 861 | { |
|---|
| | 862 | intf_sys_t *p_sys = p_intf->p_sys; |
|---|
| | 863 | int i_ret = -1; |
|---|
| | 864 | |
|---|
| | 865 | vlc_object_lock( p_intf ); |
|---|
| | 866 | while( p_sys->i_size == 0 ) |
|---|
| 879 | 867 | { |
|---|
| 880 | | vlc_mutex_unlock( &p_intf->p_sys->change_lock ); |
|---|
| 881 | | return -1; |
|---|
| 882 | | } |
|---|
| | 868 | if( !vlc_object_alive( p_intf ) ) |
|---|
| | 869 | goto out; |
|---|
| | 870 | vlc_object_wait( p_intf ); |
|---|
| | 871 | } |
|---|
| | 872 | |
|---|
| | 873 | i_ret = p_intf->p_sys->p_keys[ 0 ]; |
|---|
| | 874 | p_sys->i_size--; |
|---|
| | 875 | for( int i = 0; i < p_sys->i_size; i++ ) |
|---|
| | 876 | p_sys->p_keys[i] = p_sys->p_keys[i + 1]; |
|---|
| | 877 | |
|---|
| | 878 | out: |
|---|
| | 879 | vlc_object_unlock( p_intf ); |
|---|
| | 880 | return i_ret; |
|---|
| | 881 | } |
|---|
| | 882 | |
|---|
| | 883 | static int PutKey( intf_thread_t *p_intf, int i_key ) |
|---|
| | 884 | { |
|---|
| | 885 | intf_sys_t *p_sys = p_intf->p_sys; |
|---|
| | 886 | int i_ret = VLC_EGENERIC; |
|---|
| | 887 | |
|---|
| | 888 | vlc_object_lock( p_intf ); |
|---|
| | 889 | if ( p_sys->i_size >= BUFFER_SIZE ) |
|---|
| | 890 | msg_Warn( p_intf, "event buffer full, dropping keypress" ); |
|---|
| 883 | 891 | else |
|---|
| 884 | | { |
|---|
| 885 | | int i_return = p_intf->p_sys->p_keys[ 0 ]; |
|---|
| 886 | | int i; |
|---|
| 887 | | p_intf->p_sys->i_size--; |
|---|
| 888 | | for ( i = 0; i < BUFFER_SIZE - 1; i++) |
|---|
| 889 | | { |
|---|
| 890 | | p_intf->p_sys->p_keys[ i ] = p_intf->p_sys->p_keys[ i + 1 ]; |
|---|
| 891 | | } |
|---|
| 892 | | vlc_mutex_unlock( &p_intf->p_sys->change_lock ); |
|---|
| 893 | | return i_return; |
|---|
| 894 | | } |
|---|
| | 892 | p_sys->p_keys[p_sys->i_size++] = i_key; |
|---|
| | 893 | |
|---|
| | 894 | vlc_object_signal_unlocked( p_intf ); |
|---|
| | 895 | vlc_object_unlock( p_intf ); |
|---|
| | 896 | return i_ret; |
|---|
| 895 | 897 | } |
|---|
| 896 | 898 | |
|---|
| … | … | |
| 903 | 905 | VLC_UNUSED(psz_var); VLC_UNUSED(oldval); |
|---|
| 904 | 906 | intf_thread_t *p_intf = (intf_thread_t *)p_data; |
|---|
| 905 | | if ( !newval.i_int ) |
|---|
| 906 | | { |
|---|
| 907 | | msg_Warn( p_this, "Received invalid key event %d", newval.i_int ); |
|---|
| 908 | | return VLC_EGENERIC; |
|---|
| 909 | | } |
|---|
| 910 | | vlc_mutex_lock( &p_intf->p_sys->change_lock ); |
|---|
| 911 | | if ( p_intf->p_sys->i_size == BUFFER_SIZE ) |
|---|
| 912 | | { |
|---|
| 913 | | msg_Warn( p_intf, "event buffer full, dropping keypress" ); |
|---|
| 914 | | vlc_mutex_unlock( &p_intf->p_sys->change_lock ); |
|---|
| 915 | | return VLC_EGENERIC; |
|---|
| 916 | | } |
|---|
| 917 | | else |
|---|
| 918 | | { |
|---|
| 919 | | p_intf->p_sys->p_keys[ p_intf->p_sys->i_size ] = newval.i_int; |
|---|
| 920 | | p_intf->p_sys->i_size++; |
|---|
| 921 | | } |
|---|
| 922 | | vlc_mutex_lock( &p_intf->object_lock ); |
|---|
| 923 | | vlc_cond_signal( &p_intf->object_wait ); |
|---|
| 924 | | vlc_mutex_unlock( &p_intf->object_lock ); |
|---|
| 925 | | vlc_mutex_unlock( &p_intf->p_sys->change_lock ); |
|---|
| 926 | | |
|---|
| 927 | | return VLC_SUCCESS; |
|---|
| | 907 | |
|---|
| | 908 | return PutKey( p_intf, newval.i_int ); |
|---|
| 928 | 909 | } |
|---|
| 929 | 910 | |
|---|