Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** $Id: qt/qthreadstorage.h 3.3.8 edited Jan 11 14:46 $ 00003 ** 00004 ** ... 00005 ** 00006 ** Copyright (C) 2005-2007 Trolltech ASA. All rights reserved. 00007 ** 00008 ** This file is part of the tools module of the Qt GUI Toolkit. 00009 ** 00010 ** This file may be distributed under the terms of the Q Public License 00011 ** as defined by Trolltech ASA of Norway and appearing in the file 00012 ** LICENSE.QPL included in the packaging of this file. 00013 ** 00014 ** This file may be distributed and/or modified under the terms of the 00015 ** GNU General Public License version 2 as published by the Free Software 00016 ** Foundation and appearing in the file LICENSE.GPL included in the 00017 ** packaging of this file. 00018 ** 00019 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 00020 ** licenses may use this file in accordance with the Qt Commercial License 00021 ** Agreement provided with the Software. 00022 ** 00023 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00024 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00025 ** 00026 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00027 ** information about Qt Commercial License Agreements. 00028 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 00029 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00030 ** 00031 ** Contact info@trolltech.com if any conditions of this licensing are 00032 ** not clear to you. 00033 ** 00034 **********************************************************************/ 00035 00036 #ifndef QTHREADSTORAGE_H 00037 #define QTHREADSTORAGE_H 00038 00039 #ifdef QT_THREAD_SUPPORT 00040 00041 #ifndef QT_H 00042 #include "qglobal.h" 00043 #endif // QT_H 00044 00045 class Q_EXPORT QThreadStorageData 00046 { 00047 public: 00048 QThreadStorageData( void (*func)(void *) ); 00049 ~QThreadStorageData(); 00050 00051 void** get() const; 00052 void** set( void* p ); 00053 00054 static void finish( void** ); 00055 int id; 00056 }; 00057 00058 00059 template <class T> 00060 class QThreadStorage 00061 { 00062 private: 00063 QThreadStorageData d; 00064 00065 #if defined(Q_DISABLE_COPY) 00066 // disable copy constructor and operator= 00067 QThreadStorage( const QThreadStorage & ); 00068 QThreadStorage &operator=( const QThreadStorage & ); 00069 #endif // Q_DISABLE_COPY 00070 00071 static void deleteData( void *x ) { delete (T)x; } 00072 00073 public: 00074 inline QThreadStorage() : d( deleteData ) { } 00075 inline ~QThreadStorage() { } 00076 00077 inline bool hasLocalData() const 00078 { return d.get() != 0; } 00079 00080 inline T& localData() 00081 { void **v = d.get(); if ( !v ) v = d.set( 0 ); return *(T*)v; } 00082 00083 inline T localData() const 00084 { void **v = d.get(); return ( v ? *(T*)v : 0 ); } 00085 00086 inline void setLocalData( T t ) 00087 { (void) d.set( t ); } 00088 }; 00089 00090 #endif // QT_THREAD_SUPPORT 00091 00092 #endif // QTHREADSTORAGE_H