Changeset d2a236 in git for Singular/countedref.cc
- Timestamp:
- Aug 21, 2012, 12:52:56 PM (12 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 180efc06f46eb5c71b54411dc6be57f125ad2ca0
- Parents:
- fc70ace7d1e2b805c813bfe25f3dc25f2670531a
- git-author:
- Alexander Dreyer <alexander.dreyer@itwm.fraunhofer.de>2012-08-21 12:52:56+02:00
- git-committer:
- Oleksandr Motsak <motsak@mathematik.uni-kl.de>2012-09-05 15:52:15+02:00
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/countedref.cc
rfc70ac rd2a236 36 36 typedef CountedRefEnv self; 37 37 38 39 40 }; 41 idhdl* getmyroot() { 42 static idhdl myroot = NULL; 43 if (myroot == NULL) { 44 myroot = enterid(" _shared_data_ ", 0, PACKAGE_CMD, &IDROOT, TRUE); 45 } 46 return &myroot; 47 } 38 public: 39 40 static idhdl* locals() { 41 static idhdl myroot = NULL; 42 if (myroot == NULL) { 43 myroot = enterid(" _shared_data_ ", 0, PACKAGE_CMD, &IDROOT, TRUE); 44 } 45 return &myroot; 46 } 47 48 static idhdl newid(int typ, void* data) { 49 char* name = (char*)omAlloc0(512); 50 static unsigned int counter = 0; 51 sprintf(name, " :%u:%p:_shared_: ", ++counter, data); 52 53 idhdl* root = locals(); 54 assume((*root)->get(name, 0) == NULL); 55 short ref = (*root)->ref; 56 *root = (*root)->set(name, 0, typ, FALSE); 57 (*root)->ref = ++ref;; 58 59 IDDATA(*root) = (char*) data; 60 61 return *root; 62 } 63 64 static void erase(idhdl handle) { 65 66 idhdl* root = locals(); 67 short ref = (*root)->ref; 68 killhdl2(handle, root, currRing); 69 (*root)->ref = --ref; 70 if(ref > 0) { return;} 71 72 killhdl2(*root, &IDROOT, currRing); 73 (*root) = NULL; 74 } 75 }; 76 48 77 49 78 class RefCounter { … … 205 234 /// @note Sergio Leone memorial function 206 235 BOOLEAN broken() { 207 if( (m_context == getmyroot()) || (m_context == &currRing->idroot))236 if( (m_context == CountedRefEnv::locals()) || (m_context == &currRing->idroot)) 208 237 return FALSE; // the good, 209 238 … … 347 376 void countedref_Print(blackbox *b, void* ptr) 348 377 { 349 if (ptr == NULL) return;350 (*CountedRef::cast(ptr))->Print();378 if (ptr) (*CountedRef::cast(ptr))->Print(); 379 else PrintS("<unassigned reference or shared memory>"); 351 380 } 352 381 … … 354 383 char* countedref_String(blackbox *b, void* ptr) 355 384 { 356 if (ptr == NULL) return NULL;385 if (ptr == NULL) return omStrDup(sNoName); 357 386 return (*CountedRef::cast(ptr))->String(); 358 387 } … … 388 417 BOOLEAN countedref_Op1(int op, leftv res, leftv head) 389 418 { 419 if (head->Data() == NULL) return FALSE; 390 420 if(op == TYPEOF_CMD) 391 421 return blackboxDefaultOp1(op, res, head); … … 398 428 BOOLEAN countedref_Op2(int op, leftv res, leftv head, leftv arg) 399 429 { 400 430 if (head->Data() == NULL) return FALSE; 401 431 return CountedRef::cast(head).dereference(head) || CountedRef::resolve(arg) || 402 432 iiExprArith2(res, head, op, arg); … … 406 436 BOOLEAN countedref_Op3(int op, leftv res, leftv head, leftv arg1, leftv arg2) 407 437 { 438 if (head->Data() == NULL) return FALSE; 408 439 return CountedRef::cast(head).dereference(head) || 409 440 CountedRef::resolve(arg1) || CountedRef::resolve(arg2) || … … 415 446 BOOLEAN countedref_OpM(int op, leftv res, leftv args) 416 447 { 448 if (args->Data() == NULL) return FALSE; 417 449 return CountedRef::cast(args).dereference(args) || iiExprArithM(res, args, op); 418 450 } … … 431 463 public: 432 464 /// Construct new reference from Singular data 433 CountedRefShared(leftv arg): base(new data_type(wrap(arg), getmyroot())) { }465 CountedRefShared(leftv arg): base(new data_type(wrap(arg), CountedRefEnv::locals())) { } 434 466 435 467 private: … … 451 483 /// Replace data that reference is pointing to 452 484 self& operator=(leftv rhs) { 453 m_data->set(wrap(rhs), getmyroot());485 m_data->set(wrap(rhs), CountedRefEnv::locals()); 454 486 return *this; 455 487 } … … 464 496 465 497 static leftv wrap(leftv arg) { 466 char* name = (char*)omAlloc0(512); 467 static unsigned int counter = 0; 468 idhdl* myroot=getmyroot(); 469 sprintf(name, " :%u:%p:_shared_: ", ++counter, arg->Data()); 470 assume((*myroot)->get(name, 0) == NULL); 471 idhdl handle = (*myroot)->set(name, 0, arg->Typ(), FALSE); 472 ++(*myroot)->ref; 473 474 IDDATA(handle) = (char*) arg->CopyD(); 475 arg->CleanUp(); 476 arg->data = handle; 477 arg->rtyp = IDHDL; 478 arg->name = name; 479 498 idhdl handle = CountedRefEnv::newid(arg->Typ(), arg->CopyD()); 499 arg->CleanUp(); 500 arg->data = handle; 501 arg->rtyp = IDHDL; 480 502 return arg; 481 503 } … … 483 505 void kill() { 484 506 if (m_data->count() > 1) return; 485 507 486 508 LeftvShallow data = base::operator*(); 487 idhdl* myroot = getmyroot(); 488 killhdl2((idhdl)(data->data), myroot, currRing); 509 CountedRefEnv::erase((idhdl)data->data); 489 510 data->data = NULL; 490 511 data->rtyp = NONE; 491 492 if(--((*myroot)->ref)) {493 killhdl2(*myroot, &IDROOT, currRing);494 (*myroot) = NULL;495 }496 512 } 497 513 };
Note: See TracChangeset
for help on using the changeset viewer.