| OLD | NEW |
| 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 /* This Source Code Form is subject to the terms of the Mozilla Public | 2 /* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 * License, v. 2.0. If a copy of the MPL was not distributed with this | 3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 | 5 |
| 6 /* | 6 /* |
| 7 ** Thread Private Data | 7 ** Thread Private Data |
| 8 ** | 8 ** |
| 9 ** There is an aribitrary limit on the number of keys that will be allocated | 9 ** There is an aribitrary limit on the number of keys that will be allocated |
| 10 ** by the runtime. It's largish, so it is intended to be a sanity check, not | 10 ** by the runtime. It's largish, so it is intended to be a sanity check, not |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 123 |
| 124 /* | 124 /* |
| 125 ** Define some per-thread-private data. | 125 ** Define some per-thread-private data. |
| 126 ** "index" is an index into the per-thread private data table | 126 ** "index" is an index into the per-thread private data table |
| 127 ** "priv" is the per-thread-private data | 127 ** "priv" is the per-thread-private data |
| 128 ** | 128 ** |
| 129 ** If the per-thread private data table has a previously registered | 129 ** If the per-thread private data table has a previously registered |
| 130 ** destructor function and a non-NULL per-thread-private data value, | 130 ** destructor function and a non-NULL per-thread-private data value, |
| 131 ** the destructor function is invoked. | 131 ** the destructor function is invoked. |
| 132 ** | 132 ** |
| 133 ** This can return PR_FAILURE if index is invalid (ie., beyond the current | 133 ** This can return PR_FAILURE if index is invalid (ie., beyond the limit |
| 134 ** high water mark) or memory is insufficient to allocate an exanded vector. | 134 ** on the TPD slots) or memory is insufficient to allocate an expanded |
| 135 ** vector. |
| 135 */ | 136 */ |
| 136 | 137 |
| 137 PR_IMPLEMENT(PRStatus) PR_SetThreadPrivate(PRUintn index, void *priv) | 138 PR_IMPLEMENT(PRStatus) PR_SetThreadPrivate(PRUintn index, void *priv) |
| 138 { | 139 { |
| 139 PRThread *self = PR_GetCurrentThread(); | 140 PRThread *self = PR_GetCurrentThread(); |
| 140 | 141 |
| 141 /* | 142 /* |
| 142 ** The index being set might not have a sufficient vector in this | 143 ** To improve performance, we don't check if the index has been |
| 143 ** thread. But if the index has been allocated, it's okay to go | 144 ** allocated. |
| 144 ** ahead and extend this one now. | |
| 145 */ | 145 */ |
| 146 if ((index >= _PR_TPD_LIMIT) || (index >= _pr_tpd_highwater)) | 146 if (index >= _PR_TPD_LIMIT) |
| 147 { | 147 { |
| 148 PR_SetError(PR_TPD_RANGE_ERROR, 0); | 148 PR_SetError(PR_TPD_RANGE_ERROR, 0); |
| 149 return PR_FAILURE; | 149 return PR_FAILURE; |
| 150 } | 150 } |
| 151 | 151 |
| 152 PR_ASSERT(((NULL == self->privateData) && (0 == self->tpdLength)) | 152 PR_ASSERT(((NULL == self->privateData) && (0 == self->tpdLength)) |
| 153 || ((NULL != self->privateData) && (0 != self->tpdLength))); | 153 || ((NULL != self->privateData) && (0 != self->tpdLength))); |
| 154 | 154 |
| 155 /* |
| 156 ** If this thread does not have a sufficient vector for the index |
| 157 ** being set, go ahead and extend this vector now. |
| 158 */ |
| 155 if ((NULL == self->privateData) || (self->tpdLength <= index)) | 159 if ((NULL == self->privateData) || (self->tpdLength <= index)) |
| 156 { | 160 { |
| 157 void *extension = PR_CALLOC(_pr_tpd_length * sizeof(void*)); | 161 void *extension = PR_CALLOC(_pr_tpd_length * sizeof(void*)); |
| 158 if (NULL == extension) | 162 if (NULL == extension) |
| 159 { | 163 { |
| 160 PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); | 164 PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0); |
| 161 return PR_FAILURE; | 165 return PR_FAILURE; |
| 162 } | 166 } |
| 163 if (self->privateData) { | 167 if (self->privateData) { |
| 164 (void)memcpy( | 168 (void)memcpy( |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 /* | 243 /* |
| 240 ** We give up after a fixed number of passes. Any non-NULL | 244 ** We give up after a fixed number of passes. Any non-NULL |
| 241 ** thread-private data value with a registered destructor | 245 ** thread-private data value with a registered destructor |
| 242 ** function is not destroyed. | 246 ** function is not destroyed. |
| 243 */ | 247 */ |
| 244 memset(self->privateData, 0, self->tpdLength * sizeof(void*)); | 248 memset(self->privateData, 0, self->tpdLength * sizeof(void*)); |
| 245 } | 249 } |
| 246 } /* _PR_DestroyThreadPrivate */ | 250 } /* _PR_DestroyThreadPrivate */ |
| 247 | 251 |
| 248 #endif /* !XP_BEOS */ | 252 #endif /* !XP_BEOS */ |
| OLD | NEW |