1 mike 1.2 //%2006////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 mike 1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #ifndef Pegasus_TSDKey_h
35 #define Pegasus_TSDKey_h
36
37 #include <Pegasus/Common/Config.h>
38 #include <Pegasus/Common/Linkage.h>
39 #include <Pegasus/Common/Threads.h>
40
41 PEGASUS_NAMESPACE_BEGIN
42
43 mike 1.2 //==============================================================================
44 //
45 // TSDKeyType
46 //
47 //==============================================================================
48
49 #if defined(PEGASUS_HAVE_PTHREADS)
50 typedef pthread_key_t TSDKeyType;
51 #endif
52
53 #if defined(PEGASUS_HAVE_WINDOWS_THREADS)
54 typedef DWORD TSDKeyType;
55 #endif
56
57 //==============================================================================
58 //
59 // TSDKey
60 //
61 //==============================================================================
62
63 class PEGASUS_COMMON_LINKAGE TSDKey
64 mike 1.2 {
65 public:
66
67 static Uint32 create(TSDKeyType * key);
68
69 static Uint32 destroy(TSDKeyType key);
70
71 static void* get_thread_specific(TSDKeyType key);
72
73 static Uint32 set_thread_specific(TSDKeyType key, void* value);
74 };
75
76 //==============================================================================
77 //
78 // PEGASUS_HAVE_PTHREADS
79 //
80 //==============================================================================
81
82 #if defined(PEGASUS_HAVE_PTHREADS)
83
84 inline Uint32 TSDKey::create(TSDKeyType* key)
85 mike 1.2 {
86 return pthread_key_create(key, NULL);
87 }
88
89 inline Uint32 TSDKey::destroy(TSDKeyType key)
90 {
91 return pthread_key_delete(key);
92 }
93
94 inline void * TSDKey::get_thread_specific(TSDKeyType key)
95 {
96 return pthread_getspecific(key);
97 }
98
99 inline Uint32 TSDKey::set_thread_specific(TSDKeyType key, void* value)
100 {
101 return pthread_setspecific(key, value);
102 }
103
104 #endif /* defined(PEGASUS_HAVE_PTHREADS) */
105
106 mike 1.2 //==============================================================================
107 //
108 // PEGASUS_HAVE_WINDOWS_THREADS
109 //
110 //==============================================================================
111
112 #if defined(PEGASUS_HAVE_WINDOWS_THREADS)
113
114 inline Uint32 TSDKey::create(TSDKeyType* key)
115 {
116 *key = TlsAlloc();
117
118 if (*key == -1)
119 return 1;
120 else
121 return 0;
122 }
123
124 inline Uint32 TSDKey::destroy(TSDKeyType key)
125 {
126 if (TlsFree(key))
127 mike 1.2 return 0;
128 else
129 return 1;
130 }
131
132 inline void * TSDKey::get_thread_specific(TSDKeyType key)
133 {
134 return TlsGetValue(key);
135 }
136
137 inline Uint32 TSDKey::set_thread_specific(TSDKeyType key, void * value)
138 {
139 if (TlsSetValue(key, value))
140 return 0;
141 else
142 return 1;
143 }
144
145 #endif /* defined(PEGASUS_HAVE_WINDOWS_THREADS) */
146
147 PEGASUS_NAMESPACE_END
148 mike 1.2
149 #endif /* Pegasus_TSDKey_h */
|