Commit Graph

36 Commits

Author SHA1 Message Date
rdb 8034cb5a92 dtoolbase: Introduce patomic<> as replacement for AtomicAdjust
This typedefs to std::atomic<> when building with true threading, and uses a dummy implementation without.

This lets us use the full range of atomic operations offered by C++11, including explicit specification of memory fences.  Using barriers lets the compiler generate more optimal code since currently we are using the quite strict sequential-consistent memory ordering for all operations.  ReferenceCount has been changed to use the correct barriers (I hope).  This may especially make a difference on weak ordering systems such as ARM.

Over time we should gradually replace the use of AtomicAdjust with the new patomic file.
2022-01-30 01:53:36 +01:00
rdb c5c1d4557b pgraph: fix double free if weak ptr to state is locked while being gc'ed
Fixes #499
2020-03-10 12:10:23 +01:00
Sam Edwards f1eb811c0e general: Break apart BUILDING_PANDAEXPRESS 2018-06-10 01:37:31 -06:00
rdb f2d429b817 express: weakptr.lock() should return null during object destruction
This came up in #330; the Character destructor caused something to call lock() on a weak pointer to that character, which would induce a ref() and unref() pair, but since the refcount was 0, this would call the destructor and thereby create infinite recursion.

I considered instead calling mark_deleted() inside unref() so that the callbacks get to run before the object is actually deleted, and was_deleted() will become true as soon as unref() reaches 0.  However, this would require grabbing the lock in unref() to be fully thread-safe, since we would need to bring the refcount to 0 and mark the object as deleted in one atomic operation, so this would be an unacceptable general performance penalty.

Instead, WeakPointerTo::lock() now atomically increments the reference count if it is not already zero, and returns null otherwise.  This should be safe because the object cannot be deleted while the WeakReferenceList lock is held.
2018-05-27 15:37:03 +02:00
rdb 0bb81a43c9 express: make a thread safe weak pointer implementation (#321)
To access a WeakPointerTo in a thread-safe way, use something like this:

    if (auto ptr = weak_ptr.lock()) {
      ..use ptr as regular PointerTo
    }

The new implementation no longer needs a reference to be stored to all weak pointers on the WeakReferenceList; a mere count of weak pointers is sufficient.  Therefore, callbacks theoretically no longer require a WeakPointerTo to be constructed.

The WeakPointerTo class is not actually atomic; it could be made so, but I don't believe it's worth it at this time.
2018-05-15 13:40:21 +02:00
tobspr 0fcfb8e372 New file headers, new comment style 2016-02-17 17:47:48 +01:00
rdb 6480e82e3b First pass adding properties to many Panda classes 2015-12-10 16:23:06 +01:00
rdb 9513046e59 Various substantial changes to Interrogate:
* Allow arbitrary selection of optional keyword arguments in some cases
* Reduce code bloat of generated bindings
* Work around awkward resolution of set_shader_input overloads
* Document the code a bit better
* Make coercion a bit cleaner for reference counted types
* A few optimization tweaks
* Use generic errors in NDEBUG build to reduce size of string pool
2015-02-15 13:48:13 +01:00
David Rose 539b61571c guarantee word alignment for AtomicAdjust stuff 2011-11-17 23:31:31 +00:00
David Rose aefe3d35c2 merge dev_bam_2009 to trunk 2009-06-10 17:54:40 +00:00
David Rose fb9c56432a we are now using the modified BSD license 2008-05-28 18:37:20 +00:00
David Rose d85b062b2d don't limit counters to 32-bit 2007-11-21 22:42:56 +00:00
David Rose 190208d359 remove references to objectDeletor.h 2007-07-14 22:47:29 +00:00
David Rose 68cd3322a9 better thread protection in reference counts, esp. TransformState etc. 2007-07-14 21:32:48 +00:00
David Rose 55225290b8 add MemoryBase to fix malloc issues, especially on OSX 2006-11-17 02:13:10 +00:00
David Rose 57338ee24d better windows tau support; better threaded DeletedChain support; beginning PipelineReader classes 2006-04-20 04:03:16 +00:00
David Rose 1fabf70443 add ObjectDeletor; avoid unnecessary locks on RenderState 2006-04-10 21:19:48 +00:00
David Rose 889228f403 name mutexes for debugging; better UpdateSeq thread behavior 2006-04-09 23:23:15 +00:00
David Rose 82c0b5625f ALLOC_DELETED_CHAIN in RefCountObj 2006-04-05 22:34:05 +00:00
David Rose 8a78fffd8f multithreading optimizations, tau profiler, related changes 2006-04-05 19:36:05 +00:00
David Rose 7fdf481b0f posix threads 2006-02-10 18:52:41 +00:00
David Rose ace4407e7e regularize length of comment slashes 2005-05-19 00:22:28 +00:00
David Rose 0bd34f9f4b runtime improvements 2005-05-10 22:43:44 +00:00
David Rose 05ba41b4d6 add ReferenceCount::local_object(), clarify GeomVertexCache 2005-04-17 17:38:51 +00:00
David Rose 557060cb1d weak pointers, and FadeLODNode fixes for instances/multiple cameras 2004-09-30 21:29:25 +00:00
David Rose 843c0331ae update license, change remaining local #includes to use quotation marks 2004-02-13 19:27:33 +00:00
Dave Schuyler f8efe985d2 changed includes to use application path 2003-10-28 06:10:41 +00:00
David Rose 58b5397d87 first pass at new ipc 2002-08-09 22:58:13 +00:00
cxgeorge 1bc98e49cd eliminate erroneous export of template class 2002-02-05 02:57:42 +00:00
David Rose 22288e7e48 improved memory tracking tools 2001-06-05 21:34:36 +00:00
David Rose 2f4e207edb Update copyright header 2001-05-25 21:27:38 +00:00
David Rose fcb24f02ef remove tab characters 2001-05-25 15:56:49 +00:00
David Rose 0824e8031c *** empty log message *** 2001-05-12 15:57:34 +00:00
David Rose faa13d10e5 *** empty log message *** 2001-01-09 03:07:29 +00:00
David Rose 7d38626876 *** empty log message *** 2000-11-17 04:49:21 +00:00
David Rose 2fd714e52f Initial revision 2000-10-04 01:14:41 +00:00