Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/threads/threadkey.h

Go to the documentation of this file.
00001 /*
00002  * lib/threads/threadkey.h
00003  * 
00004  * Implementing a unique thread-specific container. 
00005  * 
00006  * Copyright (c) 2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014  * 
00015  */
00016 
00017 #ifndef _ThreadLibrary_ThreadKey_H_
00018 #define _ThreadLibrary_ThreadKey_H_ 1
00019 
00026 #include <lib/sconfig.h>    /* MUST be first */
00027 
00028 /* Can we use our own pthreads-based implementation? This should be faster.*/
00029 #if USE_PRIVATE__PTHREADS
00030 #include <errno.h>   /* for EGAGIN */
00031 #include <pthread.h>
00032 #else
00033 #include <glib/gthread.h>
00034 #endif  /* USE_PRIVATE__PTHREADS */
00035 
00047 class ThreadKey
00048 {
00049     public:
00050 #if USE_PRIVATE__PTHREADS
00051         static const pthread_key_t invalid=((pthread_key_t)(~0));
00052 #endif
00053         
00054     private:
00055 #if USE_PRIVATE__PTHREADS
00056         pthread_key_t k;
00057 #else
00058         GStaticPrivate k;
00059 #endif
00060         
00061     public:
00063         inline ThreadKey()
00064 #if USE_PRIVATE__PTHREADS
00065             {  if(pthread_key_create(&k,NULL)) k=invalid;  }
00066 #else
00067             {  g_static_private_init(&k);  }
00068 #endif
00069         
00071         inline ~ThreadKey()
00072 #if USE_PRIVATE__PTHREADS
00073             {  if(k!=invalid)  pthread_key_delete(k);  }
00074 #else
00075             {  g_static_private_free(&k);  }
00076 #endif
00077         
00079         inline void *get()
00080 #if USE_PRIVATE__PTHREADS
00081             {  return(pthread_getspecific(k));  }
00082 #else
00083             {  return(g_static_private_get(&k));  }
00084 #endif
00085         
00087         inline void set(void *v)
00088 #if USE_PRIVATE__PTHREADS
00089             {  pthread_setspecific(k,v);  }
00090 #else
00091             {  g_static_private_set(&k,v,NULL);  }
00092 #endif
00093         
00094 };
00095 
00096 #endif  /* _ThreadLibrary_ThreadKey_H_ */

Generated on Sat Feb 19 22:33:46 2005 for Ray by doxygen 1.3.5