Changeset 431 for branches/thune/thread_safe/context.c
- Timestamp:
- 07/16/07 03:30:29 (17 months ago)
- Files:
-
- 1 modified
-
branches/thune/thread_safe/context.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/thune/thread_safe/context.c
r427 r431 25 25 26 26 #define LOWERCASE(c) if(c >= 'A' && c <= 'Z') c -= 'A' - 'a' 27 28 29 /* 30 UrlanEnv::atoms & UrlanEnv::atomNames can be made thread safe through one 31 of the following: 32 33 1. Use LOCK_ATOMS in or around these functions: 34 ur_internT() 35 ur_atomStrT() 36 ur_atomCStrT() (and all use of returned pointer) 37 ur_atomHash() 38 dumpAtoms() 39 40 2. Fix size of atom arrays and throw error/assert when full. 41 Must still lock these functions to access head/chain AtomRec members: 42 ur_internT() 43 dumpAtoms() 44 45 Option #2 is currently being used. 46 */ 27 47 28 48 … … 120 140 void dumpAtoms( UThread* ut ) 121 141 { 122 LOCK_ GLOBAL142 LOCK_ATOMS 123 143 { 124 144 const char* names = ut->env->atomNames.ptr.c; … … 143 163 } 144 164 } 145 UNLOCK_ GLOBAL165 UNLOCK_ATOMS 146 166 } 147 167 #endif … … 151 171 Add atom to environment. 152 172 153 If the environment has multiple threads, the caller must have called154 LOCK_GLOBAL.155 156 173 \param str Name of atom. 157 174 \param len Number of characters. 158 175 159 \return sAtom176 \return Atom 160 177 */ 161 178 UAtom ur_internT( UThread* ut, const char* str, int len ) … … 171 188 AtomRec* node; 172 189 173 174 190 assert( len > 0 ); 175 191 176 192 177 193 // Check if atom already exists. 194 195 hash = ur_hash( str, str + len ); 196 197 LOCK_ATOMS 178 198 179 199 atoms = &ut->env->atoms; 180 200 table = (AtomRec*) atoms->ptr.v; 181 201 names = &ut->env->atomNames; 182 183 hash = ur_hash( str, str + len );184 202 185 203 node = table + (hash % atoms->avail); … … 228 246 // Nope, add new atom. 229 247 230 /* TODO: Make atoms & atomNames thread safe through one of the following:231 232 1. Halt all other threads.233 2. Fix size of atom arrays and throw error/assert when full.234 3. Use LOCK_GLOBAL in or around these functions in addition to ur_intern:235 ur_atomStrT()236 ur_atomCStrT()237 dumpAtoms()238 */239 240 248 if( atoms->used == atoms->avail ) 241 249 { 250 #if 1 251 // Atom table size is fixed so read only access does not need to be 252 // locked. When the table is full, we are finished. 253 assert( 0 && "Atom table is full" ); 254 return 0; // TODO: Report fatal error 255 #else 242 256 ur_arrayReserve( atoms, sizeof(AtomRec), atoms->used + 1 ); 243 257 ur_rebuildAtomHash( atoms ); … … 245 259 246 260 HASH_INSERT( atoms, table, node, hash, atoms->used ) 261 #endif 247 262 } 248 263 node = table + atoms->used; … … 253 268 node->nameLen = len; 254 269 270 #if 1 271 if( (names->used + len + 1) > names->avail ) 272 { 273 assert( 0 && "Atom name buffer is full" ); 274 return 0; // TODO: Report fatal error 275 } 276 #else 255 277 ur_arrayReserve( names, sizeof(char), names->used + len + 1 ); 278 #endif 279 256 280 cp = names->ptr.c + names->used; 257 281 ep = cp + len; … … 267 291 done: 268 292 269 return node - table; 293 c = node - table; 294 295 UNLOCK_ATOMS 296 297 return c; 270 298 } 271 299 … … 278 306 If added, the word is initialied as unset. 279 307 280 \return sIndex of word in context.308 \return Index of word in context. 281 309 */ 282 310 int ur_internWordT( UThread* ut, const UContext* ctx, UAtom atom ) … … 424 452 /** 425 453 Find word in context by atom. 426 \return sWord index or -1 if not found.454 \return Word index or -1 if not found. 427 455 */ 428 456 int ur_lookupT( UThread* ut, const UContext* ctx, UAtom atom )
