Changeset 1789 in webkit for trunk/JavaScriptCore/kjs
- Timestamp:
- Aug 9, 2002, 4:24:41 PM (23 years ago)
- Location:
- trunk/JavaScriptCore/kjs
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/collector.cpp
r1371 r1789 67 67 } 68 68 69 #ifdef APPLE_CHANGES70 static pthread_mutex_t collectorLock = PTHREAD_MUTEX_INITIALIZER;71 static pthread_cond_t collectorCondition = PTHREAD_COND_INITIALIZER;72 static unsigned collectorLockCount = 0;73 static pthread_t collectorLockThread;74 #endif75 69 CollectorBlock* Collector::root = 0L; 76 70 CollectorBlock* Collector::currentBlock = 0L; … … 91 85 if (s == 0) 92 86 return 0L; 93 94 #ifdef APPLE_CHANGES95 lock();96 #endif97 87 98 88 // Try and deal with memory requirements in a scalable way. Simple scripts … … 162 152 } 163 153 164 #ifdef APPLE_CHANGES165 unlock();166 #endif167 168 154 return m; 169 155 } … … 174 160 bool Collector::collect() 175 161 { 176 #ifdef APPLE_CHANGES177 lock();178 #endif179 162 #ifdef KJS_DEBUG_MEM 180 163 fprintf(stderr,"Collector::collect()\n"); … … 287 270 finalCheck(); 288 271 #endif 289 #ifdef APPLE_CHANGES290 unlock();291 #endif292 272 return deleted; 293 273 } … … 296 276 void Collector::finalCheck() 297 277 { 298 #ifdef APPLE_CHANGES299 lock();300 #endif301 278 CollectorBlock *block = root; 302 279 while (block) { … … 314 291 block = block->next; 315 292 } 316 #ifdef APPLE_CHANGES317 unlock();318 #endif319 293 } 320 294 #endif … … 323 297 int Collector::numInterpreters() 324 298 { 325 lock();326 299 int count = 0; 327 300 if (InterpreterImp::s_hook) { … … 332 305 } while (scr != InterpreterImp::s_hook); 333 306 } 334 unlock();335 307 return count; 336 308 } … … 338 310 int Collector::numGCNotAllowedObjects() 339 311 { 340 lock();341 312 int count = 0; 342 313 CollectorBlock *block = root; … … 353 324 block = block->next; 354 325 } 355 unlock();356 326 return count; 357 327 } … … 359 329 int Collector::numReferencedObjects() 360 330 { 361 lock();362 331 int count = 0; 363 332 CollectorBlock *block = root; … … 374 343 block = block->next; 375 344 } 376 unlock();377 345 return count; 378 346 } 379 347 380 void Collector::lock() 381 { 382 pthread_mutex_lock(&collectorLock); 383 while (collectorLockCount > 0 && 384 !pthread_equal(pthread_self(), collectorLockThread)) { 385 pthread_cond_wait(&collectorCondition, &collectorLock); 386 } 387 collectorLockThread = pthread_self(); 388 collectorLockCount++; 389 pthread_mutex_unlock(&collectorLock); 390 } 391 392 void Collector::unlock() 393 { 394 pthread_mutex_lock(&collectorLock); 395 collectorLockCount--; 396 if (collectorLockCount == 0) { 397 pthread_cond_signal(&collectorCondition); 398 } 399 pthread_mutex_unlock(&collectorLock); 400 } 401 402 #endif 348 #endif -
trunk/JavaScriptCore/kjs/collector.h
r1126 r1789 93 93 static int numGCNotAllowedObjects(); 94 94 static int numReferencedObjects(); 95 static void lock();96 static void unlock();97 95 #endif 98 96 private: -
trunk/JavaScriptCore/kjs/internal.cpp
r1623 r1789 68 68 const double Inf = *(const double*) Inf_Bytes; 69 69 }; 70 71 #ifdef APPLE_CHANGES 72 static pthread_once_t interpreterLockOnce = PTHREAD_ONCE_INIT; 73 static pthread_mutex_t interpreterLock; 74 75 static void initializeInterpreterLock() 76 { 77 pthread_mutexattr_t attr; 78 79 pthread_mutexattr_init(&attr); 80 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); 81 82 pthread_mutex_init(&interpreterLock, &attr); 83 } 84 85 static inline void lockInterpreter() 86 { 87 pthread_once(&interpreterLockOnce, initializeInterpreterLock); 88 pthread_mutex_lock(&interpreterLock); 89 } 90 91 static inline void unlockInterpreter() 92 { 93 pthread_mutex_unlock(&interpreterLock); 94 } 95 96 #endif 97 70 98 71 99 // ------------------------------ UndefinedImp --------------------------------- … … 689 717 ProgramNode *Parser::progNode = 0; 690 718 int Parser::sid = 0; 691 #ifdef APPLE_CHANGES692 static pthread_mutex_t parserLock = PTHREAD_MUTEX_INITIALIZER;693 #endif694 719 695 720 ProgramNode *Parser::parse(const UChar *code, unsigned int length, int *sourceId, 696 721 int *errLine, UString *errMsg) 697 722 { 698 #ifdef APPLE_CHANGES699 pthread_mutex_lock(&parserLock);700 #endif701 723 if (errLine) 702 724 *errLine = -1; … … 727 749 #endif 728 750 delete prog; 729 #ifdef APPLE_CHANGES730 pthread_mutex_unlock(&parserLock);731 #endif732 751 return 0; 733 752 } 734 753 735 #ifdef APPLE_CHANGES736 pthread_mutex_unlock(&parserLock);737 #endif738 754 return prog; 739 755 } … … 778 794 // as a root set for garbage collection 779 795 #ifdef APPLE_CHANGES 780 Collector::lock();796 pthread_mutex_lock(&interpreterLock); 781 797 m_interpreter = interp; 782 798 #endif … … 792 808 } 793 809 #ifdef APPLE_CHANGES 794 Collector::unlock();810 pthread_mutex_unlock(&interpreterLock); 795 811 #endif 796 812 … … 939 955 // remove from global chain (see init()) 940 956 #ifdef APPLE_CHANGES 941 Collector::lock();957 pthread_mutex_lock(&interpreterLock); 942 958 #endif 943 959 next->prev = prev; … … 951 967 } 952 968 #ifdef APPLE_CHANGES 953 Collector::unlock();969 pthread_mutex_unlock(&interpreterLock); 954 970 #endif 955 971 } … … 989 1005 Completion InterpreterImp::evaluate(const UString &code, const Value &thisV) 990 1006 { 1007 #ifdef APPLE_CHANGES 1008 pthread_mutex_lock(&interpreterLock); 1009 #endif 991 1010 // prevent against infinite recursion 992 1011 if (recursion >= 20) { 1012 #ifdef APPLE_CHANGES 1013 Completion result = Completion(Throw,Error::create(globExec,GeneralError,"Recursion too deep")); 1014 pthread_mutex_unlock(&interpreterLock); 1015 return result; 1016 #else 993 1017 return Completion(Throw,Error::create(globExec,GeneralError,"Recursion too deep")); 1018 #endif 994 1019 } 995 1020 … … 1004 1029 bool cont = dbg->sourceParsed(globExec,sid,code,errLine); 1005 1030 if (!cont) 1031 #ifdef APPLE_CHANGES 1032 { 1033 pthread_mutex_unlock(&interpreterLock); 1034 return Completion(Break); 1035 } 1036 #else 1006 1037 return Completion(Break); 1038 #endif 1007 1039 } 1008 1040 … … 1011 1043 Object err = Error::create(globExec,SyntaxError,errMsg.ascii(),errLine); 1012 1044 err.put(globExec,"sid",Number(sid)); 1045 #ifdef APPLE_CHANGES 1046 pthread_mutex_unlock(&interpreterLock); 1047 #endif 1013 1048 return Completion(Throw,err); 1014 1049 } … … 1053 1088 recursion--; 1054 1089 1090 #ifdef APPLE_CHANGES 1091 pthread_mutex_unlock(&interpreterLock); 1092 #endif 1055 1093 return res; 1056 1094 } -
trunk/JavaScriptCore/kjs/value.cpp
r1623 r1789 42 42 // ----------------------------- ValueImp ------------------------------------- 43 43 44 #if APPLE_CHANGES45 ValueImp::ValueImp() :46 refcount(0)47 {48 // Tell the garbage collector that this memory block corresponds to a real object now49 Collector::lock();50 _flags = VI_CREATED;51 //fprintf(stderr,"ValueImp::ValueImp %p\n",(void*)this);52 Collector::unlock();53 }54 #else55 44 ValueImp::ValueImp() : 56 45 refcount(0), … … 60 49 //fprintf(stderr,"ValueImp::ValueImp %p\n",(void*)this); 61 50 } 62 #endif63 51 64 52 ValueImp::~ValueImp() … … 81 69 void ValueImp::setGcAllowed() 82 70 { 83 #ifdef APPLE_CHANGES84 Collector::lock();85 #endif86 71 //fprintf(stderr,"ValueImp::setGcAllowed %p\n",(void*)this); 87 72 _flags |= VI_GCALLOWED; 88 #ifdef APPLE_CHANGES89 Collector::unlock();90 #endif91 73 } 92 74
Note:
See TracChangeset
for help on using the changeset viewer.