Changeset 1126 in webkit for trunk/JavaScriptCore/kjs/collector.cpp
- Timestamp:
- May 10, 2002, 9:41:01 AM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/collector.cpp
r1112 r1126 30 30 #include <typeinfo> 31 31 #endif 32 #ifdef APPLE_CHANGES 33 #include <pthread.h> 34 #endif 32 35 33 36 namespace KJS { … … 47 50 using namespace KJS; 48 51 52 49 53 CollectorBlock::CollectorBlock(int s) 50 54 : size(s), … … 63 67 } 64 68 69 #ifdef APPLE_CHANGES 70 // FIXME: fix these once static initializers for pthread_cond_t and 71 // pthread_mutex_t are fixed not to warn. 72 static pthread_mutex_t collectorLock = {_PTHREAD_MUTEX_SIG_init, {}}; 73 static pthread_cond_t collectorCondition = {_PTHREAD_COND_SIG_init, {}}; 74 static unsigned collectorLockCount = 0; 75 static pthread_t collectorLockThread; 76 #endif 65 77 CollectorBlock* Collector::root = 0L; 66 78 CollectorBlock* Collector::currentBlock = 0L; … … 81 93 if (s == 0) 82 94 return 0L; 95 96 #ifdef APPLE_CHANGES 97 lock(); 98 #endif 83 99 84 100 // Try and deal with memory requirements in a scalable way. Simple scripts … … 148 164 } 149 165 166 #ifdef APPLE_CHANGES 167 unlock(); 168 #endif 169 150 170 return m; 151 171 } … … 156 176 bool Collector::collect() 157 177 { 178 #ifdef APPLE_CHANGES 179 lock(); 180 #endif 158 181 #ifdef KJS_DEBUG_MEM 159 182 fprintf(stderr,"Collector::collect()\n"); … … 253 276 finalCheck(); 254 277 #endif 278 #ifdef APPLE_CHANGES 279 unlock(); 280 #endif 255 281 return deleted; 256 282 } … … 259 285 void Collector::finalCheck() 260 286 { 287 #ifdef APPLE_CHANGES 288 lock(); 289 #endif 261 290 CollectorBlock *block = root; 262 291 while (block) { … … 274 303 block = block->next; 275 304 } 305 #ifdef APPLE_CHANGES 306 unlock(); 307 #endif 276 308 } 277 309 #endif … … 280 312 int Collector::numInterpreters() 281 313 { 314 lock(); 282 315 int count = 0; 283 316 if (InterpreterImp::s_hook) { … … 288 321 } while (scr != InterpreterImp::s_hook); 289 322 } 323 unlock(); 290 324 return count; 291 325 } … … 293 327 int Collector::numGCNotAllowedObjects() 294 328 { 329 lock(); 295 330 int count = 0; 296 331 CollectorBlock *block = root; … … 307 342 block = block->next; 308 343 } 344 unlock(); 309 345 return count; 310 346 } … … 312 348 int Collector::numReferencedObjects() 313 349 { 350 lock(); 314 351 int count = 0; 315 352 CollectorBlock *block = root; … … 326 363 block = block->next; 327 364 } 365 unlock(); 328 366 return count; 329 367 } 330 #endif 368 369 void Collector::lock() 370 { 371 pthread_mutex_lock(&collectorLock); 372 while (collectorLockCount > 0 && 373 !pthread_equal(pthread_self(), collectorLockThread)) { 374 pthread_cond_wait(&collectorCondition, &collectorLock); 375 } 376 collectorLockThread = pthread_self(); 377 collectorLockCount++; 378 pthread_mutex_unlock(&collectorLock); 379 } 380 381 void Collector::unlock() 382 { 383 pthread_mutex_lock(&collectorLock); 384 collectorLockCount--; 385 if (collectorLockCount == 0) { 386 pthread_cond_signal(&collectorCondition); 387 } 388 pthread_mutex_unlock(&collectorLock); 389 } 390 391 #endif
Note:
See TracChangeset
for help on using the changeset viewer.