vlc_gcrypt.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_gcrypt.h: VLC thread support for gcrypt
00003  *****************************************************************************
00004  * Copyright (C) 2004-2008 Rémi Denis-Courmont
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00019  *****************************************************************************/
00020 
00021 #ifdef LIBVLC_USE_PTHREAD
00022 /**
00023  * If possible, use gcrypt-provided thread implementation. This is so that
00024  * other non-VLC components (inside the process) can also use gcrypt safely.
00025  */
00026 GCRY_THREAD_OPTION_PTHREAD_IMPL;
00027 # define gcry_threads_vlc gcry_threads_pthread
00028 #else
00029 /**
00030  * gcrypt thread option VLC implementation
00031  */
00032 
00033 static int gcry_vlc_mutex_init( void **p_sys )
00034 {
00035     int i_val;
00036     vlc_mutex_t *p_lock = (vlc_mutex_t *)malloc( sizeof( vlc_mutex_t ) );
00037 
00038     if( p_lock == NULL)
00039         return ENOMEM;
00040 
00041     i_val = vlc_mutex_init( p_lock );
00042     if( i_val )
00043         free( p_lock );
00044     else
00045         *p_sys = p_lock;
00046     return i_val;
00047 }
00048 
00049 static int gcry_vlc_mutex_destroy( void **p_sys )
00050 {
00051     vlc_mutex_t *p_lock = (vlc_mutex_t *)*p_sys;
00052     vlc_mutex_destroy( p_lock );
00053     free( p_lock );
00054     return VLC_SUCCESS;
00055 }
00056 
00057 static int gcry_vlc_mutex_lock( void **p_sys )
00058 {
00059     vlc_mutex_lock( (vlc_mutex_t *)*p_sys );
00060     return VLC_SUCCESS;
00061 }
00062 
00063 static int gcry_vlc_mutex_unlock( void **lock )
00064 {
00065     vlc_mutex_unlock( (vlc_mutex_t *)*lock );
00066     return VLC_SUCCESS;
00067 }
00068 
00069 static const struct gcry_thread_cbs gcry_threads_vlc =
00070 {
00071     GCRY_THREAD_OPTION_USER,
00072     NULL,
00073     gcry_vlc_mutex_init,
00074     gcry_vlc_mutex_destroy,
00075     gcry_vlc_mutex_lock,
00076     gcry_vlc_mutex_unlock
00077 };
00078 #endif
00079 
00080 /**
00081  * Initializes gcrypt with proper locking.
00082  */
00083 static inline void vlc_gcrypt_init (void)
00084 {
00085     vlc_mutex_t *lock = var_AcquireMutex ("gcrypt_mutex");
00086     gcry_control (GCRYCTL_SET_THREAD_CBS, &gcry_threads_vlc);
00087     vlc_mutex_unlock (lock);
00088 }

Generated on Wed Aug 13 08:02:37 2008 for VLC by  doxygen 1.5.1