/* (c) Copyright 2001-2008 The world wide DirectFB Open Source Community (directfb.org) (c) Copyright 2000-2004 Convergence (integrated media) GmbH All rights reserved. Written by Denis Oliver Kropp , Andreas Hundt , Sven Neumann , Ville Syrjälä and Claudio Ciccani . This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __DIRECT__OS__LINUX__GLIBC__MUTEX_H__ #define __DIRECT__OS__LINUX__GLIBC__MUTEX_H__ #include #include #define _ZU "%zu" #define _ZD "%zd" /**********************************************************************************************************************/ typedef struct { pthread_mutex_t lock; } DirectMutex; /**********************************************************************************************************************/ #define DIRECT_MUTEX_INITIALIZER(name) { PTHREAD_MUTEX_INITIALIZER } #define DIRECT_RECURSIVE_MUTEX_INITIALIZER(name) { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP } DirectResult direct_mutex_init ( DirectMutex *mutex ); DirectResult direct_recursive_mutex_init ( DirectMutex *mutex ); DirectResult direct_mutex_lock ( DirectMutex *mutex ); DirectResult direct_mutex_unlock ( DirectMutex *mutex ); DirectResult direct_mutex_trylock ( DirectMutex *mutex ); DirectResult direct_mutex_deinit ( DirectMutex *mutex ); /**********************************************************************************************************************/ /**********************************************************************************************************************/ typedef struct { pthread_key_t key; } DirectTLS; /**********************************************************************************************************************/ #define DIRECT_TLS_DATA( name ) \ static DirectTLS name = { (pthread_key_t) -1 } /**********************************************************************************************************************/ __attribute__((no_instrument_function)) static inline void *direct_tls_get__( DirectTLS *tls ); __attribute__((no_instrument_function)) static inline DirectResult direct_tls_set__( DirectTLS *tls, void *value ); __attribute__((no_instrument_function)) static inline DirectResult direct_tls_register( DirectTLS *tls, void (*destructor)( void* ) ); __attribute__((no_instrument_function)) static inline DirectResult direct_tls_unregister( DirectTLS *tls ); /**********************************************************************************************************************/ #define direct_tls_get( name ) direct_tls_get__( &name ) #define direct_tls_set( name, v ) direct_tls_set__( &name, v ) /**********************************************************************************************************************/ static inline void * direct_tls_get__( DirectTLS *tls ) { void *value; value = pthread_getspecific( tls->key ); return value; } static inline DirectResult direct_tls_set__( DirectTLS *tls, void *value ) { if (pthread_setspecific( tls->key, value )) return errno2result( errno ); return DR_OK; } static inline DirectResult direct_tls_register( DirectTLS *tls, void (*destructor)( void* ) ) { if (pthread_key_create( &tls->key, destructor )) return errno2result( errno ); return DR_OK; } static inline DirectResult direct_tls_unregister( DirectTLS *tls ) { if (pthread_key_delete( tls->key )) return errno2result( errno ); tls->key = (pthread_key_t) -1; return DR_OK; } #endif