diff --git a/contrib/src/ai/aiCharacter.cxx b/contrib/src/ai/aiCharacter.cxx index 7009a353f1..240f1a4ea3 100644 --- a/contrib/src/ai/aiCharacter.cxx +++ b/contrib/src/ai/aiCharacter.cxx @@ -24,6 +24,8 @@ AICharacter::AICharacter(string model_name, NodePath model_np, double mass, doub _velocity = LVecBase3(0.0, 0.0, 0.0); _steering_force = LVecBase3(0.0, 0.0, 0.0); + _world = nullptr; + _steering = new AIBehaviors(); _steering->_ai_char = this; @@ -31,6 +33,7 @@ AICharacter::AICharacter(string model_name, NodePath model_np, double mass, doub } AICharacter::~AICharacter() { + nassertv(_world == nullptr); } /** diff --git a/contrib/src/ai/aiCharacter.h b/contrib/src/ai/aiCharacter.h index 244f9bc45e..30adf21ced 100644 --- a/contrib/src/ai/aiCharacter.h +++ b/contrib/src/ai/aiCharacter.h @@ -15,6 +15,7 @@ #define _AICHARACTER_H #include "aiBehaviors.h" +#include "referenceCount.h" /** * This class is used for creating the AI characters. It assigns both physics @@ -25,7 +26,7 @@ class AIBehaviors; class AIWorld; -class EXPCL_PANDAAI AICharacter { +class EXPCL_PANDAAI AICharacter : public ReferenceCount { public: double _mass; double _max_force; diff --git a/contrib/src/ai/aiWorld.cxx b/contrib/src/ai/aiWorld.cxx index 6abac9f990..8210046497 100644 --- a/contrib/src/ai/aiWorld.cxx +++ b/contrib/src/ai/aiWorld.cxx @@ -14,44 +14,56 @@ #include "aiWorld.h" AIWorld::AIWorld(NodePath render) { - _ai_char_pool = new AICharPool(); - _render = render; + _render = move(render); } AIWorld::~AIWorld() { } void AIWorld::add_ai_char(AICharacter *ai_char) { - _ai_char_pool->append(ai_char); + _ai_char_pool.push_back(ai_char); ai_char->_window_render = _render; ai_char->_world = this; } void AIWorld::remove_ai_char(string name) { - _ai_char_pool->del(name); - remove_ai_char_from_flock(name); + AICharPool::iterator it; + for (it = _ai_char_pool.begin(); it != _ai_char_pool.end(); ++it) { + AICharacter *ai_char = *it; + if (ai_char->_name == name) { + nassertv(ai_char->_world == this); + ai_char->_world = nullptr; + _ai_char_pool.erase(it); + break; + } + } + + remove_ai_char_from_flock(move(name)); } void AIWorld::remove_ai_char_from_flock(string name) { - AICharPool::node *ai_pool; - ai_pool = _ai_char_pool->_head; - while((ai_pool) != NULL) { - for(unsigned int i = 0; i < _flock_pool.size(); ++i) { - if(ai_pool->_ai_char->_ai_char_flock_id == _flock_pool[i]->get_id()) { - for(unsigned int j = 0; j<_flock_pool[i]->_ai_char_list.size(); ++j) { - if(_flock_pool[i]->_ai_char_list[j]->_name == name) { - _flock_pool[i]->_ai_char_list.erase(_flock_pool[i]->_ai_char_list.begin() + j); + for (AICharacter *ai_char : _ai_char_pool) { + for (Flock *flock : _flock_pool) { + if (ai_char->_ai_char_flock_id == flock->get_id()) { + for (size_t j = 0; j < flock->_ai_char_list.size(); ++j) { + if (flock->_ai_char_list[j]->_name == name) { + flock->_ai_char_list.erase(flock->_ai_char_list.begin() + j); return; } } } } - ai_pool = ai_pool->_next; } } +/** + * This function prints the names of the AI characters that have been added to + * the AIWorld. Useful for debugging purposes. + */ void AIWorld::print_list() { - _ai_char_pool->print_list(); + for (AICharacter *ai_char : _ai_char_pool) { + cout << ai_char->_name << endl; + } } /** @@ -59,12 +71,8 @@ void AIWorld::print_list() { * characters which have been added to the AIWorld. */ void AIWorld::update() { - AICharPool::node *ai_pool; - ai_pool = _ai_char_pool->_head; - - while((ai_pool)!=NULL) { - ai_pool->_ai_char->update(); - ai_pool = ai_pool->_next; + for (AICharacter *ai_char : _ai_char_pool) { + ai_char->update(); } } @@ -142,86 +150,6 @@ void AIWorld::flock_on(unsigned int flock_id) { } } -AICharPool::AICharPool() { - _head = NULL; -} - -AICharPool::~AICharPool() { -} - -void AICharPool::append(AICharacter *ai_ch) { - node *q; - node *t; - - if(_head == NULL) { - q = new node(); - q->_ai_char = ai_ch; - q->_next = NULL; - _head = q; - } - else { - q = _head; - while( q->_next != NULL) { - q = q->_next; - } - - t = new node(); - t->_ai_char = ai_ch; - t->_next = NULL; - q->_next = t; - } -} - -void AICharPool::del(string name) { - node *q; - node *r; - q = _head; - - if(_head==NULL) { - return; - } - - // Only one node in the linked list - if(q->_next == NULL) { - if(q->_ai_char->_name == name) { - _head = NULL; - delete q; - } - return; - } - - r = q; - while( q != NULL) { - if( q->_ai_char->_name == name) { - // Special case - if(q == _head) { - _head = q->_next; - delete q; - return; - } - - r->_next = q->_next; - delete q; - return; - } - r = q; - q = q->_next; - } -} - -/** - * This function prints the ai characters in the AICharPool. Used for - * debugging purposes. - */ -void AICharPool::print_list() { - node* q; - q = _head; - while(q != NULL) { - cout<_ai_char->_name<_next; - } -} - /** * This function adds the nodepath as an obstacle that is needed by the * obstacle avoidance behavior. diff --git a/contrib/src/ai/aiWorld.h b/contrib/src/ai/aiWorld.h index f85e1dc584..64cecefc2d 100644 --- a/contrib/src/ai/aiWorld.h +++ b/contrib/src/ai/aiWorld.h @@ -21,27 +21,6 @@ class AICharacter; class Flock; -/** - * This class implements a linked list of AI Characters allowing the user to - * add and delete characters from the linked list. This will be used in the - * AIWorld class. - */ -class EXPCL_PANDAAI AICharPool { - public: - struct node { - AICharacter * _ai_char; - node * _next; - } ; - - node* _head; - AICharPool(); - ~AICharPool(); - void append(AICharacter *ai_ch); - void del(string name); - void print_list(); -}; - - /** * A class that implements the virtual AI world which keeps track of the AI * characters active at any given time. It contains a linked list of AI @@ -51,7 +30,8 @@ class EXPCL_PANDAAI AICharPool { */ class EXPCL_PANDAAI AIWorld { private: - AICharPool * _ai_char_pool; + typedef std::vector AICharPool; + AICharPool _ai_char_pool; NodePath _render; public: vector _obstacles; diff --git a/contrib/src/ai/flock.h b/contrib/src/ai/flock.h index c5e508a837..c353781890 100644 --- a/contrib/src/ai/flock.h +++ b/contrib/src/ai/flock.h @@ -40,7 +40,7 @@ public: unsigned int _alignment_wt; // This vector will hold all the ai characters which belong to this flock. - typedef std::vector AICharList; + typedef std::vector AICharList; AICharList _ai_char_list; PUBLISHED: diff --git a/direct/src/showbase/Audio3DManager.py b/direct/src/showbase/Audio3DManager.py index 463d3b5bf0..4a67c9bc27 100644 --- a/direct/src/showbase/Audio3DManager.py +++ b/direct/src/showbase/Audio3DManager.py @@ -2,8 +2,8 @@ __all__ = ['Audio3DManager'] -from panda3d.core import Vec3, VBase3 -from direct.task import Task +from panda3d.core import Vec3, VBase3, WeakNodePath +from direct.task.TaskManagerGlobal import Task, taskMgr # class Audio3DManager: @@ -181,7 +181,8 @@ class Audio3DManager: def attachSoundToObject(self, sound, object): """ - Sound will come from the location of the object it is attached to + Sound will come from the location of the object it is attached to. + If the object is deleted, the sound will automatically be removed. """ # sound is an AudioSound # object is any Panda object with coordinates @@ -197,7 +198,7 @@ class Audio3DManager: del self.sound_dict[known_object] if object not in self.sound_dict: - self.sound_dict[object] = [] + self.sound_dict[WeakNodePath(object)] = [] self.sound_dict[object].append(sound) return 1 @@ -258,14 +259,18 @@ class Audio3DManager: if self.audio_manager.getActive()==0: return Task.cont - for known_object in list(self.sound_dict.keys()): - tracked_sound = 0 - while tracked_sound < len(self.sound_dict[known_object]): - sound = self.sound_dict[known_object][tracked_sound] - pos = known_object.getPos(self.root) + for known_object, sounds in list(self.sound_dict.items()): + node_path = known_object.getNodePath() + if not node_path: + # The node has been deleted. + del self.sound_dict[known_object] + continue + + pos = node_path.getPos(self.root) + + for sound in sounds: vel = self.getSoundVelocity(sound) sound.set3dAttributes(pos[0], pos[1], pos[2], vel[0], vel[1], vel[2]) - tracked_sound += 1 # Update the position of the listener based on the object # to which it is attached diff --git a/direct/src/stdpy/glob.py b/direct/src/stdpy/glob.py index 28eee2cb6e..d1a4946c0e 100755 --- a/direct/src/stdpy/glob.py +++ b/direct/src/stdpy/glob.py @@ -4,7 +4,6 @@ virtual file system. """ import sys import os -import re import fnmatch from direct.stdpy import file @@ -76,7 +75,27 @@ def glob0(dirname, basename): return [] -magic_check = re.compile('[*?[]') - def has_magic(s): - return magic_check.search(s) is not None + if isinstance(s, bytes): + return b'*' in s or b'?' in s or b'[' in s + else: + return '*' in s or '?' in s or '[' in s + +def escape(pathname): + drive, pathname = os.path.splitdrive(pathname) + if sys.version_info >= (3, 0) and isinstance(pathname, bytes): + newpath = bytearray(drive) + for c in pathname: + if c == 42 or c == 63 or c == 91: + newpath += bytes((91, c, 93)) + else: + newpath.append(c) + return bytes(newpath) + else: + newpath = drive + for c in pathname: + if c == '*' or c == '?' or c == '[': + newpath += '[' + c + ']' + else: + newpath += c + return newpath diff --git a/dtool/src/dtoolbase/atomicAdjustDummyImpl.I b/dtool/src/dtoolbase/atomicAdjustDummyImpl.I index a08d6ce130..54d6e6b860 100644 --- a/dtool/src/dtoolbase/atomicAdjustDummyImpl.I +++ b/dtool/src/dtoolbase/atomicAdjustDummyImpl.I @@ -30,10 +30,13 @@ dec(TVOLATILE AtomicAdjustDummyImpl::Integer &var) { /** * Atomically computes var += delta. It is legal for delta to be negative. + * Returns the result of the addition. */ -ALWAYS_INLINE void AtomicAdjustDummyImpl:: +ALWAYS_INLINE AtomicAdjustDummyImpl::Integer AtomicAdjustDummyImpl:: add(TVOLATILE AtomicAdjustDummyImpl::Integer &var, AtomicAdjustDummyImpl::Integer delta) { - var += delta; + Integer new_value = var + delta; + var = new_value; + return new_value; } /** diff --git a/dtool/src/dtoolbase/atomicAdjustDummyImpl.h b/dtool/src/dtoolbase/atomicAdjustDummyImpl.h index 120fbe195a..3257ae8dfd 100644 --- a/dtool/src/dtoolbase/atomicAdjustDummyImpl.h +++ b/dtool/src/dtoolbase/atomicAdjustDummyImpl.h @@ -31,7 +31,7 @@ public: ALWAYS_INLINE static void inc(TVOLATILE Integer &var); ALWAYS_INLINE static bool dec(TVOLATILE Integer &var); - ALWAYS_INLINE static void add(TVOLATILE Integer &var, Integer delta); + ALWAYS_INLINE static Integer add(TVOLATILE Integer &var, Integer delta); ALWAYS_INLINE static Integer set(TVOLATILE Integer &var, Integer new_value); ALWAYS_INLINE static Integer get(const TVOLATILE Integer &var); diff --git a/dtool/src/dtoolbase/atomicAdjustGccImpl.I b/dtool/src/dtoolbase/atomicAdjustGccImpl.I index 5becaaa4c0..682b14bed3 100644 --- a/dtool/src/dtoolbase/atomicAdjustGccImpl.I +++ b/dtool/src/dtoolbase/atomicAdjustGccImpl.I @@ -30,11 +30,12 @@ dec(TVOLATILE AtomicAdjustGccImpl::Integer &var) { /** * Atomically computes var += delta. It is legal for delta to be negative. + * Returns the result of the addition. */ -INLINE void AtomicAdjustGccImpl:: +INLINE AtomicAdjustGccImpl::Integer AtomicAdjustGccImpl:: add(TVOLATILE AtomicAdjustGccImpl::Integer &var, AtomicAdjustGccImpl::Integer delta) { - __atomic_fetch_add(&var, delta, __ATOMIC_SEQ_CST); + return __atomic_add_fetch(&var, delta, __ATOMIC_SEQ_CST); } /** diff --git a/dtool/src/dtoolbase/atomicAdjustGccImpl.h b/dtool/src/dtoolbase/atomicAdjustGccImpl.h index 7ae44037ff..57389c1349 100644 --- a/dtool/src/dtoolbase/atomicAdjustGccImpl.h +++ b/dtool/src/dtoolbase/atomicAdjustGccImpl.h @@ -35,7 +35,7 @@ public: INLINE static void inc(TVOLATILE Integer &var); INLINE static bool dec(TVOLATILE Integer &var); - INLINE static void add(TVOLATILE Integer &var, Integer delta); + INLINE static Integer add(TVOLATILE Integer &var, Integer delta); INLINE static Integer set(TVOLATILE Integer &var, Integer new_value); INLINE static Integer get(const TVOLATILE Integer &var); diff --git a/dtool/src/dtoolbase/atomicAdjustI386Impl.I b/dtool/src/dtoolbase/atomicAdjustI386Impl.I index 3841479b28..98208c8655 100644 --- a/dtool/src/dtoolbase/atomicAdjustI386Impl.I +++ b/dtool/src/dtoolbase/atomicAdjustI386Impl.I @@ -59,14 +59,18 @@ dec(TVOLATILE AtomicAdjustI386Impl::Integer &var) { /** * Atomically computes var += delta. It is legal for delta to be negative. + * Returns the result of the addition. */ -INLINE void AtomicAdjustI386Impl:: +INLINE AtomicAdjustI386Impl::Integer AtomicAdjustI386Impl:: add(TVOLATILE AtomicAdjustI386Impl::Integer &var, AtomicAdjustI386Impl::Integer delta) { assert((((size_t)&var) & (sizeof(Integer) - 1)) == 0); Integer orig_value = var; - while (compare_and_exchange(var, orig_value, orig_value + delta) != orig_value) { + Integer new_value = orig_value + delta; + while (compare_and_exchange(var, orig_value, new_value) != orig_value) { orig_value = var; + new_value = orig_value + delta; } + return new_value; } /** diff --git a/dtool/src/dtoolbase/atomicAdjustI386Impl.h b/dtool/src/dtoolbase/atomicAdjustI386Impl.h index eac5ce6a97..bcd1a62c61 100644 --- a/dtool/src/dtoolbase/atomicAdjustI386Impl.h +++ b/dtool/src/dtoolbase/atomicAdjustI386Impl.h @@ -34,7 +34,7 @@ public: INLINE static void inc(TVOLATILE Integer &var); INLINE static bool dec(TVOLATILE Integer &var); - INLINE static void add(TVOLATILE Integer &var, Integer delta); + INLINE static Integer add(TVOLATILE Integer &var, Integer delta); INLINE static Integer set(TVOLATILE Integer &var, Integer new_value); INLINE static Integer get(const TVOLATILE Integer &var); diff --git a/dtool/src/dtoolbase/atomicAdjustPosixImpl.I b/dtool/src/dtoolbase/atomicAdjustPosixImpl.I index ef3d43f053..09636c39c7 100644 --- a/dtool/src/dtoolbase/atomicAdjustPosixImpl.I +++ b/dtool/src/dtoolbase/atomicAdjustPosixImpl.I @@ -35,13 +35,16 @@ dec(TVOLATILE AtomicAdjustPosixImpl::Integer &var) { /** * Atomically computes var += delta. It is legal for delta to be negative. + * Returns the result of the addition. */ -INLINE void AtomicAdjustPosixImpl:: +INLINE AtomicAdjustPosixImpl::Integer AtomicAdjustPosixImpl:: add(TVOLATILE AtomicAdjustPosixImpl::Integer &var, AtomicAdjustPosixImpl::Integer delta) { pthread_mutex_lock(&_mutex); - var += delta; + Integer new_value = var + delta; + var = new_value; pthread_mutex_unlock(&_mutex); + return new_value; } /** diff --git a/dtool/src/dtoolbase/atomicAdjustPosixImpl.h b/dtool/src/dtoolbase/atomicAdjustPosixImpl.h index 3b98499129..8c2b2b5887 100644 --- a/dtool/src/dtoolbase/atomicAdjustPosixImpl.h +++ b/dtool/src/dtoolbase/atomicAdjustPosixImpl.h @@ -35,7 +35,7 @@ public: INLINE static void inc(TVOLATILE Integer &var); INLINE static bool dec(TVOLATILE Integer &var); - INLINE static void add(TVOLATILE Integer &var, Integer delta); + INLINE static Integer add(TVOLATILE Integer &var, Integer delta); INLINE static Integer set(TVOLATILE Integer &var, Integer new_value); INLINE static Integer get(const TVOLATILE Integer &var); diff --git a/dtool/src/dtoolbase/atomicAdjustWin32Impl.I b/dtool/src/dtoolbase/atomicAdjustWin32Impl.I index a0e213c638..851c9f05e2 100644 --- a/dtool/src/dtoolbase/atomicAdjustWin32Impl.I +++ b/dtool/src/dtoolbase/atomicAdjustWin32Impl.I @@ -40,17 +40,21 @@ dec(TVOLATILE AtomicAdjustWin32Impl::Integer &var) { /** * Atomically computes var += delta. It is legal for delta to be negative. + * Returns the result of the addition. */ -INLINE void AtomicAdjustWin32Impl:: +INLINE AtomicAdjustWin32Impl::Integer AtomicAdjustWin32Impl:: add(TVOLATILE AtomicAdjustWin32Impl::Integer &var, AtomicAdjustWin32Impl::Integer delta) { assert((((size_t)&var) & (sizeof(Integer) - 1)) == 0); #ifdef _WIN64 - InterlockedAdd64(&var, delta); + return InterlockedAdd64(&var, delta); #else - AtomicAdjustWin32Impl::Integer orig_value = var; - while (compare_and_exchange(var, orig_value, orig_value + delta) != orig_value) { + Integer orig_value = var; + Integer new_value = orig_value + delta; + while (compare_and_exchange(var, orig_value, new_value) != orig_value) { orig_value = var; + new_value = orig_value + delta; } + return new_value; #endif // _WIN64 } diff --git a/dtool/src/dtoolbase/atomicAdjustWin32Impl.h b/dtool/src/dtoolbase/atomicAdjustWin32Impl.h index 6f64d2a781..25f2e78066 100644 --- a/dtool/src/dtoolbase/atomicAdjustWin32Impl.h +++ b/dtool/src/dtoolbase/atomicAdjustWin32Impl.h @@ -44,7 +44,7 @@ public: ALWAYS_INLINE static void inc(TVOLATILE Integer &var); ALWAYS_INLINE static bool dec(TVOLATILE Integer &var); - INLINE static void add(TVOLATILE Integer &var, Integer delta); + INLINE static Integer add(TVOLATILE Integer &var, Integer delta); ALWAYS_INLINE static Integer set(TVOLATILE Integer &var, Integer new_value); ALWAYS_INLINE static Integer get(const TVOLATILE Integer &var); diff --git a/dtool/src/dtoolbase/deletedBufferChain.cxx b/dtool/src/dtoolbase/deletedBufferChain.cxx index 27d7214d79..71756f3e25 100644 --- a/dtool/src/dtoolbase/deletedBufferChain.cxx +++ b/dtool/src/dtoolbase/deletedBufferChain.cxx @@ -43,11 +43,11 @@ allocate(size_t size, TypeHandle type_handle) { ObjectNode *obj; - _lock.acquire(); + _lock.lock(); if (_deleted_chain != (ObjectNode *)NULL) { obj = _deleted_chain; _deleted_chain = _deleted_chain->_next; - _lock.release(); + _lock.unlock(); #ifdef USE_DELETEDCHAINFLAG assert(obj->_flag == (AtomicAdjust::Integer)DCF_deleted); @@ -64,7 +64,7 @@ allocate(size_t size, TypeHandle type_handle) { return ptr; } - _lock.release(); + _lock.unlock(); // If we get here, the deleted_chain is empty; we have to allocate a new // object from the system pool. @@ -126,12 +126,12 @@ deallocate(void *ptr, TypeHandle type_handle) { assert(orig_flag == (AtomicAdjust::Integer)DCF_alive); #endif // USE_DELETEDCHAINFLAG - _lock.acquire(); + _lock.lock(); obj->_next = _deleted_chain; _deleted_chain = obj; - _lock.release(); + _lock.unlock(); #else // USE_DELETED_CHAIN PANDA_FREE_SINGLE(ptr); diff --git a/dtool/src/dtoolbase/dtoolbase_cc.h b/dtool/src/dtoolbase/dtoolbase_cc.h index 81968085bc..98bf992cf9 100644 --- a/dtool/src/dtoolbase/dtoolbase_cc.h +++ b/dtool/src/dtoolbase/dtoolbase_cc.h @@ -19,6 +19,13 @@ #ifdef __cplusplus +// By including checkPandaVersion.h, we guarantee that runtime attempts to +// load any DLL will fail if they inadvertently link with the wrong version of +// dtool, which, transitively, means all DLLs must be from the same +// (ABI-compatible) version of Panda. + +#include "checkPandaVersion.h" + #ifdef USE_TAU // Tau provides this destructive version of stdbool.h that we must mask. #define __PDT_STDBOOL_H_ @@ -33,16 +40,7 @@ using namespace std; #define INLINE inline #define ALWAYS_INLINE inline #define TYPENAME typename -#define CONSTEXPR constexpr -#define ALWAYS_INLINE_CONSTEXPR constexpr -#define NOEXCEPT noexcept -#define FINAL final #define MOVE(x) x -#define DEFAULT_CTOR = default -#define DEFAULT_DTOR = default -#define DEFAULT_ASSIGN = default -#define DELETED = delete -#define DELETED_ASSIGN = delete #define EXPORT_TEMPLATE_CLASS(expcl, exptp, classname) @@ -81,15 +79,9 @@ typedef int ios_seekdir; #include #include -#ifdef HAVE_NAMESPACE using namespace std; -#endif -#ifdef HAVE_TYPENAME #define TYPENAME typename -#else -#define TYPENAME -#endif #ifndef HAVE_WCHAR_T // Some C++ libraries (os x 3.1) don't define this. @@ -124,18 +116,20 @@ typedef ios::seekdir ios_seekdir; #if defined(__GLIBCXX__) && __GLIBCXX__ <= 20070719 #include -using std::tr1::tuple; -using std::tr1::tie; +namespace std { + using std::tr1::tuple; + using std::tr1::tie; -typedef decltype(nullptr) nullptr_t; + typedef decltype(nullptr) nullptr_t; -template struct remove_reference {typedef T type;}; -template struct remove_reference {typedef T type;}; -template struct remove_reference{typedef T type;}; + template struct remove_reference {typedef T type;}; + template struct remove_reference {typedef T type;}; + template struct remove_reference{typedef T type;}; -template typename remove_reference::type &&move(T &&t) { - return static_cast::type&&>(t); -} + template typename remove_reference::type &&move(T &&t) { + return static_cast::type&&>(t); + } +}; #endif #ifdef _MSC_VER @@ -156,110 +150,12 @@ template typename remove_reference::type &&move(T &&t) { #endif // Determine the availability of C++11 features. -#if defined(__has_extension) // Clang magic. -# if __has_extension(cxx_constexpr) -# if !defined(__apple_build_version__) || __apple_build_version__ >= 5000000 -# define CONSTEXPR constexpr -# endif -# endif -# if __has_extension(cxx_noexcept) -# define NOEXCEPT noexcept -# endif -# if __has_extension(cxx_rvalue_references) && (__cplusplus >= 201103L) -# define USE_MOVE_SEMANTICS -# define MOVE(x) move(x) -# endif -# if __has_extension(cxx_override_control) && (__cplusplus >= 201103L) -# define FINAL final -# endif -# if __has_extension(cxx_defaulted_functions) -# define DEFAULT_CTOR = default -# define DEFAULT_DTOR = default -# define DEFAULT_ASSIGN = default -# endif -# if __has_extension(cxx_deleted_functions) -# define DELETED = delete -# endif -#elif defined(__GNUC__) // GCC - -// Starting at GCC 4.4 -# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) -# define DEFAULT_CTOR = default -# define DEFAULT_DTOR = default -# define DEFAULT_ASSIGN = default -# define DELETED = delete -# endif - -// Starting at GCC 4.6 -# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -# define CONSTEXPR constexpr -# define NOEXCEPT noexcept -# define USE_MOVE_SEMANTICS -# define MOVE(x) move(x) -# endif - -// Starting at GCC 4.7 -# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) -# define FINAL final -# endif - -// GCC defines several macros which we can query. List of all supported -// builtin macros: https://gcc.gnu.org/projects/cxx-status.html -# if !defined(CONSTEXPR) && __cpp_constexpr >= 200704 -# define CONSTEXPR constexpr -# endif - -#elif defined(_MSC_VER) && _MSC_VER >= 1900 // Visual Studio 2015 -# define CONSTEXPR constexpr -# define NOEXCEPT noexcept -# define USE_MOVE_SEMANTICS -# define FINAL final -# define MOVE(x) move(x) -#elif defined(_MSC_VER) && _MSC_VER >= 1600 // Visual Studio 2010 -# define NOEXCEPT throw() -# define USE_MOVE_SEMANTICS -# define FINAL sealed -# define MOVE(x) move(x) +#if defined(_MSC_VER) && _MSC_VER < 1900 // Visual Studio 2015 +#error Microsoft Visual C++ 2015 or later is required to compile Panda3D. #endif -#if defined(_MSC_VER) && _MSC_VER >= 1800 // Visual Studio 2013 -# define DEFAULT_CTOR = default -# define DEFAULT_DTOR = default -# define DEFAULT_ASSIGN = default -# define DELETED = delete -#endif - -// Fallbacks if features are not supported -#ifndef CONSTEXPR -# define CONSTEXPR INLINE -# define ALWAYS_INLINE_CONSTEXPR ALWAYS_INLINE -#else -# define ALWAYS_INLINE_CONSTEXPR ALWAYS_INLINE CONSTEXPR -#endif -#ifndef NOEXCEPT -# define NOEXCEPT -#endif -#ifndef MOVE -# define MOVE(x) x -#endif -#ifndef FINAL -# define FINAL -#endif -#ifndef DEFAULT_CTOR -# define DEFAULT_CTOR {} -#endif -#ifndef DEFAULT_DTOR -# define DEFAULT_DTOR {} -#endif -#ifndef DEFAULT_ASSIGN -# define DEFAULT_ASSIGN {return *this;} -#endif -#ifndef DELETED -# define DELETED {assert(false);} -# define DELETED_ASSIGN {assert(false);return *this;} -#else -# define DELETED_ASSIGN DELETED -#endif +// This is just to support code generated with older versions of interrogate. +#define MOVE(x) (std::move(x)) #ifndef LINK_ALL_STATIC diff --git a/dtool/src/dtoolbase/fakestringstream.h b/dtool/src/dtoolbase/fakestringstream.h index 6711eb8d2a..4ff2a971f0 100644 --- a/dtool/src/dtoolbase/fakestringstream.h +++ b/dtool/src/dtoolbase/fakestringstream.h @@ -18,9 +18,7 @@ #include #include -#ifdef HAVE_NAMESPACE using namespace std; -#endif class fake_istream_buffer { public: diff --git a/dtool/src/dtoolbase/memoryHook.I b/dtool/src/dtoolbase/memoryHook.I index bd5a55af79..cc4f972f6b 100644 --- a/dtool/src/dtoolbase/memoryHook.I +++ b/dtool/src/dtoolbase/memoryHook.I @@ -34,15 +34,6 @@ dec_heap(size_t size) { #endif // DO_MEMORY_USAGE } -/** - * Returns the global memory alignment. This is the number of bytes at which - * each allocated memory pointer will be aligned. - */ -CONSTEXPR size_t MemoryHook:: -get_memory_alignment() { - return MEMORY_HOOK_ALIGNMENT; -} - /** * Returns the operating system page size. This is the minimum granularity * required for calls to mmap_alloc(). Also see round_up_to_page_size(). diff --git a/dtool/src/dtoolbase/memoryHook.cxx b/dtool/src/dtoolbase/memoryHook.cxx index 510b5b2688..710ea9e65f 100644 --- a/dtool/src/dtoolbase/memoryHook.cxx +++ b/dtool/src/dtoolbase/memoryHook.cxx @@ -223,9 +223,9 @@ MemoryHook(const MemoryHook ©) : _total_mmap_size(copy._total_mmap_size), _max_heap_size(copy._max_heap_size) { - copy._lock.acquire(); + copy._lock.lock(); _deleted_chains = copy._deleted_chains; - copy._lock.release(); + copy._lock.unlock(); } /** @@ -249,9 +249,9 @@ heap_alloc_single(size_t size) { size_t inflated_size = inflate_size(size); #ifdef MEMORY_HOOK_MALLOC_LOCK - _lock.acquire(); + _lock.lock(); void *alloc = call_malloc(inflated_size); - _lock.release(); + _lock.unlock(); #else void *alloc = call_malloc(inflated_size); #endif @@ -259,9 +259,9 @@ heap_alloc_single(size_t size) { while (alloc == (void *)NULL) { alloc_fail(inflated_size); #ifdef MEMORY_HOOK_MALLOC_LOCK - _lock.acquire(); + _lock.lock(); alloc = call_malloc(inflated_size); - _lock.release(); + _lock.unlock(); #else alloc = call_malloc(inflated_size); #endif @@ -305,9 +305,9 @@ heap_free_single(void *ptr) { #endif // DO_MEMORY_USAGE #ifdef MEMORY_HOOK_MALLOC_LOCK - _lock.acquire(); + _lock.lock(); call_free(alloc); - _lock.release(); + _lock.unlock(); #else call_free(alloc); #endif @@ -326,9 +326,9 @@ heap_alloc_array(size_t size) { size_t inflated_size = inflate_size(size); #ifdef MEMORY_HOOK_MALLOC_LOCK - _lock.acquire(); + _lock.lock(); void *alloc = call_malloc(inflated_size); - _lock.release(); + _lock.unlock(); #else void *alloc = call_malloc(inflated_size); #endif @@ -336,9 +336,9 @@ heap_alloc_array(size_t size) { while (alloc == (void *)NULL) { alloc_fail(inflated_size); #ifdef MEMORY_HOOK_MALLOC_LOCK - _lock.acquire(); + _lock.lock(); alloc = call_malloc(inflated_size); - _lock.release(); + _lock.unlock(); #else alloc = call_malloc(inflated_size); #endif @@ -380,9 +380,9 @@ heap_realloc_array(void *ptr, size_t size) { void *alloc1 = alloc; #ifdef MEMORY_HOOK_MALLOC_LOCK - _lock.acquire(); + _lock.lock(); alloc1 = call_realloc(alloc1, inflated_size); - _lock.release(); + _lock.unlock(); #else alloc1 = call_realloc(alloc1, inflated_size); #endif @@ -394,9 +394,9 @@ heap_realloc_array(void *ptr, size_t size) { alloc1 = alloc; #ifdef MEMORY_HOOK_MALLOC_LOCK - _lock.acquire(); + _lock.lock(); alloc1 = call_realloc(alloc1, inflated_size); - _lock.release(); + _lock.unlock(); #else alloc1 = call_realloc(alloc1, inflated_size); #endif @@ -453,9 +453,9 @@ heap_free_array(void *ptr) { #endif // DO_MEMORY_USAGE #ifdef MEMORY_HOOK_MALLOC_LOCK - _lock.acquire(); + _lock.lock(); call_free(alloc); - _lock.release(); + _lock.unlock(); #else call_free(alloc); #endif @@ -478,11 +478,11 @@ heap_trim(size_t pad) { // Since malloc_trim() isn't standard C, we can't be sure it exists on a // given platform. But if we're using dlmalloc, we know we have // dlmalloc_trim. - _lock.acquire(); + _lock.lock(); if (dlmalloc_trim(pad)) { trimmed = true; } - _lock.release(); + _lock.unlock(); #endif #ifdef WIN32 @@ -596,7 +596,7 @@ DeletedBufferChain *MemoryHook:: get_deleted_chain(size_t buffer_size) { DeletedBufferChain *chain; - _lock.acquire(); + _lock.lock(); DeletedChains::iterator dci = _deleted_chains.find(buffer_size); if (dci != _deleted_chains.end()) { chain = (*dci).second; @@ -606,7 +606,7 @@ get_deleted_chain(size_t buffer_size) { _deleted_chains.insert(DeletedChains::value_type(buffer_size, chain)); } - _lock.release(); + _lock.unlock(); return chain; } diff --git a/dtool/src/dtoolbase/memoryHook.h b/dtool/src/dtoolbase/memoryHook.h index 9472983d75..bb30e7f03d 100644 --- a/dtool/src/dtoolbase/memoryHook.h +++ b/dtool/src/dtoolbase/memoryHook.h @@ -52,7 +52,9 @@ public: bool heap_trim(size_t pad); - CONSTEXPR static size_t get_memory_alignment(); + constexpr static size_t get_memory_alignment() { + return MEMORY_HOOK_ALIGNMENT; + } virtual void *mmap_alloc(size_t size, bool allow_exec); virtual void mmap_free(void *ptr, size_t size); diff --git a/dtool/src/dtoolbase/mutexDummyImpl.I b/dtool/src/dtoolbase/mutexDummyImpl.I index 94afaa2cc5..26a4dd6242 100644 --- a/dtool/src/dtoolbase/mutexDummyImpl.I +++ b/dtool/src/dtoolbase/mutexDummyImpl.I @@ -15,14 +15,14 @@ * */ ALWAYS_INLINE void MutexDummyImpl:: -acquire() { +lock() { } /** * */ ALWAYS_INLINE bool MutexDummyImpl:: -try_acquire() { +try_lock() { return true; } @@ -30,5 +30,5 @@ try_acquire() { * */ ALWAYS_INLINE void MutexDummyImpl:: -release() { +unlock() { } diff --git a/dtool/src/dtoolbase/mutexDummyImpl.h b/dtool/src/dtoolbase/mutexDummyImpl.h index 772f3f8201..3474d443ed 100644 --- a/dtool/src/dtoolbase/mutexDummyImpl.h +++ b/dtool/src/dtoolbase/mutexDummyImpl.h @@ -23,16 +23,15 @@ */ class EXPCL_DTOOL_DTOOLBASE MutexDummyImpl { public: - CONSTEXPR MutexDummyImpl() DEFAULT_CTOR; + constexpr MutexDummyImpl() = default; + MutexDummyImpl(const MutexDummyImpl ©) = delete; -private: - MutexDummyImpl(const MutexDummyImpl ©) DELETED; - MutexDummyImpl &operator = (const MutexDummyImpl ©) DELETED_ASSIGN; + MutexDummyImpl &operator = (const MutexDummyImpl ©) = delete; public: - ALWAYS_INLINE void acquire(); - ALWAYS_INLINE bool try_acquire(); - ALWAYS_INLINE void release(); + ALWAYS_INLINE void lock(); + ALWAYS_INLINE bool try_lock(); + ALWAYS_INLINE void unlock(); }; #include "mutexDummyImpl.I" diff --git a/dtool/src/dtoolbase/mutexPosixImpl.I b/dtool/src/dtoolbase/mutexPosixImpl.I index 05acfae1c2..0bc338a2eb 100644 --- a/dtool/src/dtoolbase/mutexPosixImpl.I +++ b/dtool/src/dtoolbase/mutexPosixImpl.I @@ -14,8 +14,8 @@ /** * */ -CONSTEXPR MutexPosixImpl:: -MutexPosixImpl() NOEXCEPT : _lock(PTHREAD_MUTEX_INITIALIZER) { +constexpr MutexPosixImpl:: +MutexPosixImpl() noexcept : _lock(PTHREAD_MUTEX_INITIALIZER) { } /** @@ -32,8 +32,8 @@ INLINE MutexPosixImpl:: * */ INLINE void MutexPosixImpl:: -acquire() { - TAU_PROFILE("void MutexPosixImpl::acquire", " ", TAU_USER); +lock() { + TAU_PROFILE("void MutexPosixImpl::lock", " ", TAU_USER); int result = pthread_mutex_lock(&_lock); assert(result == 0); } @@ -42,8 +42,8 @@ acquire() { * */ INLINE bool MutexPosixImpl:: -try_acquire() { - TAU_PROFILE("bool MutexPosixImpl::try_acquire", " ", TAU_USER); +try_lock() { + TAU_PROFILE("bool MutexPosixImpl::try_lock", " ", TAU_USER); int result = pthread_mutex_trylock(&_lock); assert(result == 0 || result == EBUSY); return (result == 0); @@ -53,26 +53,18 @@ try_acquire() { * */ INLINE void MutexPosixImpl:: -release() { - TAU_PROFILE("void MutexPosixImpl::release", " ", TAU_USER); +unlock() { + TAU_PROFILE("void MutexPosixImpl::unlock", " ", TAU_USER); int result = pthread_mutex_unlock(&_lock); assert(result == 0); } -/** - * Returns the underlying Posix lock handle. - */ -INLINE pthread_mutex_t *MutexPosixImpl:: -get_posix_lock() { - return &_lock; -} - /** * */ #ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP -CONSTEXPR ReMutexPosixImpl:: -ReMutexPosixImpl() NOEXCEPT : _lock(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) { +constexpr ReMutexPosixImpl:: +ReMutexPosixImpl() noexcept : _lock(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) { } #else INLINE ReMutexPosixImpl:: @@ -101,8 +93,8 @@ INLINE ReMutexPosixImpl:: * */ INLINE void ReMutexPosixImpl:: -acquire() { - TAU_PROFILE("void ReMutexPosixImpl::acquire", " ", TAU_USER); +lock() { + TAU_PROFILE("void ReMutexPosixImpl::lock", " ", TAU_USER); int result = pthread_mutex_lock(&_lock); assert(result == 0); } @@ -111,8 +103,8 @@ acquire() { * */ INLINE bool ReMutexPosixImpl:: -try_acquire() { - TAU_PROFILE("bool ReMutexPosixImpl::try_acquire", " ", TAU_USER); +try_lock() { + TAU_PROFILE("bool ReMutexPosixImpl::try_lock", " ", TAU_USER); int result = pthread_mutex_trylock(&_lock); assert(result == 0 || result == EBUSY); return (result == 0); @@ -122,16 +114,8 @@ try_acquire() { * */ INLINE void ReMutexPosixImpl:: -release() { - TAU_PROFILE("void ReMutexPosixImpl::release", " ", TAU_USER); +unlock() { + TAU_PROFILE("void ReMutexPosixImpl::unlock", " ", TAU_USER); int result = pthread_mutex_unlock(&_lock); assert(result == 0); } - -/** - * Returns the underlying Posix lock handle. - */ -INLINE pthread_mutex_t *ReMutexPosixImpl:: -get_posix_lock() { - return &_lock; -} diff --git a/dtool/src/dtoolbase/mutexPosixImpl.h b/dtool/src/dtoolbase/mutexPosixImpl.h index 44b5ab193f..996001b114 100644 --- a/dtool/src/dtoolbase/mutexPosixImpl.h +++ b/dtool/src/dtoolbase/mutexPosixImpl.h @@ -28,19 +28,16 @@ */ class EXPCL_DTOOL_DTOOLBASE MutexPosixImpl { public: - CONSTEXPR MutexPosixImpl() NOEXCEPT; + constexpr MutexPosixImpl() noexcept; + MutexPosixImpl(const MutexPosixImpl ©) = delete; INLINE ~MutexPosixImpl(); -private: - MutexPosixImpl(const MutexPosixImpl ©) DELETED; - MutexPosixImpl &operator = (const MutexPosixImpl ©) DELETED_ASSIGN; + MutexPosixImpl &operator = (const MutexPosixImpl ©) = delete; public: - INLINE void acquire(); - INLINE bool try_acquire(); - INLINE void release(); - - INLINE pthread_mutex_t *get_posix_lock(); + INLINE void lock(); + INLINE bool try_lock(); + INLINE void unlock(); private: pthread_mutex_t _lock; @@ -53,22 +50,19 @@ private: class EXPCL_DTOOL_DTOOLBASE ReMutexPosixImpl { public: #ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP - CONSTEXPR ReMutexPosixImpl() NOEXCEPT; + constexpr ReMutexPosixImpl() noexcept; #else INLINE ReMutexPosixImpl(); #endif + ReMutexPosixImpl(const ReMutexPosixImpl ©) = delete; INLINE ~ReMutexPosixImpl(); -private: - ReMutexPosixImpl(const ReMutexPosixImpl ©) DELETED; - ReMutexPosixImpl &operator = (const ReMutexPosixImpl ©) DELETED; + ReMutexPosixImpl &operator = (const ReMutexPosixImpl ©) = delete; public: - INLINE void acquire(); - INLINE bool try_acquire(); - INLINE void release(); - - INLINE pthread_mutex_t *get_posix_lock(); + INLINE void lock(); + INLINE bool try_lock(); + INLINE void unlock(); private: pthread_mutex_t _lock; diff --git a/dtool/src/dtoolbase/mutexSpinlockImpl.I b/dtool/src/dtoolbase/mutexSpinlockImpl.I index 9fca1e9bf6..b3eb084181 100644 --- a/dtool/src/dtoolbase/mutexSpinlockImpl.I +++ b/dtool/src/dtoolbase/mutexSpinlockImpl.I @@ -14,7 +14,7 @@ /** * */ -CONSTEXPR MutexSpinlockImpl:: +constexpr MutexSpinlockImpl:: MutexSpinlockImpl() : _lock(0) { } @@ -22,8 +22,8 @@ MutexSpinlockImpl() : _lock(0) { * */ INLINE void MutexSpinlockImpl:: -acquire() { - if (!try_acquire()) { +lock() { + if (!try_lock()) { do_lock(); } } @@ -32,7 +32,7 @@ acquire() { * */ INLINE bool MutexSpinlockImpl:: -try_acquire() { +try_lock() { return (AtomicAdjust::compare_and_exchange(_lock, 0, 1) == 0); } @@ -40,6 +40,6 @@ try_acquire() { * */ INLINE void MutexSpinlockImpl:: -release() { +unlock() { AtomicAdjust::set(_lock, 0); } diff --git a/dtool/src/dtoolbase/mutexSpinlockImpl.h b/dtool/src/dtoolbase/mutexSpinlockImpl.h index 33514127f4..c7dfb72cf2 100644 --- a/dtool/src/dtoolbase/mutexSpinlockImpl.h +++ b/dtool/src/dtoolbase/mutexSpinlockImpl.h @@ -29,16 +29,15 @@ */ class EXPCL_DTOOL_DTOOLBASE MutexSpinlockImpl { public: - CONSTEXPR MutexSpinlockImpl(); + constexpr MutexSpinlockImpl(); + MutexSpinlockImpl(const MutexSpinlockImpl ©) = delete; -private: - MutexSpinlockImpl(const MutexSpinlockImpl ©) DELETED; - MutexSpinlockImpl &operator = (const MutexSpinlockImpl ©) DELETED_ASSIGN; + MutexSpinlockImpl &operator = (const MutexSpinlockImpl ©) = delete; public: - INLINE void acquire(); - INLINE bool try_acquire(); - INLINE void release(); + INLINE void lock(); + INLINE bool try_lock(); + INLINE void unlock(); private: void do_lock(); diff --git a/dtool/src/dtoolbase/mutexWin32Impl.I b/dtool/src/dtoolbase/mutexWin32Impl.I index cd9b3d1fb1..acbbd68b56 100644 --- a/dtool/src/dtoolbase/mutexWin32Impl.I +++ b/dtool/src/dtoolbase/mutexWin32Impl.I @@ -23,7 +23,7 @@ INLINE MutexWin32Impl:: * */ INLINE void MutexWin32Impl:: -acquire() { +lock() { EnterCriticalSection(&_lock); } @@ -31,7 +31,7 @@ acquire() { * */ INLINE bool MutexWin32Impl:: -try_acquire() { +try_lock() { return (TryEnterCriticalSection(&_lock) != 0); } @@ -39,6 +39,6 @@ try_acquire() { * */ INLINE void MutexWin32Impl:: -release() { +unlock() { LeaveCriticalSection(&_lock); } diff --git a/dtool/src/dtoolbase/mutexWin32Impl.h b/dtool/src/dtoolbase/mutexWin32Impl.h index 08fc6eab24..550d4944ab 100644 --- a/dtool/src/dtoolbase/mutexWin32Impl.h +++ b/dtool/src/dtoolbase/mutexWin32Impl.h @@ -29,16 +29,15 @@ class EXPCL_DTOOL_DTOOLBASE MutexWin32Impl { public: MutexWin32Impl(); + MutexWin32Impl(const MutexWin32Impl ©) = delete; INLINE ~MutexWin32Impl(); -private: - MutexWin32Impl(const MutexWin32Impl ©) DELETED; - MutexWin32Impl &operator = (const MutexWin32Impl ©) DELETED_ASSIGN; + MutexWin32Impl &operator = (const MutexWin32Impl ©) = delete; public: - INLINE void acquire(); - INLINE bool try_acquire(); - INLINE void release(); + INLINE void lock(); + INLINE bool try_lock(); + INLINE void unlock(); private: CRITICAL_SECTION _lock; diff --git a/dtool/src/dtoolbase/nearly_zero.h b/dtool/src/dtoolbase/nearly_zero.h index af71ad9419..0f31fdfb2e 100644 --- a/dtool/src/dtoolbase/nearly_zero.h +++ b/dtool/src/dtoolbase/nearly_zero.h @@ -24,17 +24,17 @@ // identifier, and then returning the value of that identifier, seems to lead // to compilation errors (at least in VC7) in which sometimes // IS_THRESHOLD_COMPEQ(a, a, get_nearly_zero_value(a)) != 0. -CONSTEXPR double +constexpr double get_nearly_zero_value(double) { return 1.0e-12; } -CONSTEXPR float +constexpr float get_nearly_zero_value(float) { return 1.0e-6f; } -CONSTEXPR int +constexpr int get_nearly_zero_value(int) { // This is a bit silly, but we should nevertheless define it in case it is // called for an integer type. diff --git a/dtool/src/dtoolbase/neverFreeMemory.I b/dtool/src/dtoolbase/neverFreeMemory.I index 2156209616..f34bdae28d 100644 --- a/dtool/src/dtoolbase/neverFreeMemory.I +++ b/dtool/src/dtoolbase/neverFreeMemory.I @@ -48,9 +48,9 @@ get_total_used() { INLINE size_t NeverFreeMemory:: get_total_unused() { NeverFreeMemory *global_ptr = get_global_ptr(); - global_ptr->_lock.acquire(); + global_ptr->_lock.lock(); size_t total_unused = global_ptr->_total_alloc - global_ptr->_total_used; - global_ptr->_lock.release(); + global_ptr->_lock.unlock(); return total_unused; } diff --git a/dtool/src/dtoolbase/neverFreeMemory.cxx b/dtool/src/dtoolbase/neverFreeMemory.cxx index fd10b683d8..a1f720cfba 100644 --- a/dtool/src/dtoolbase/neverFreeMemory.cxx +++ b/dtool/src/dtoolbase/neverFreeMemory.cxx @@ -37,7 +37,7 @@ NeverFreeMemory() { */ void *NeverFreeMemory:: ns_alloc(size_t size) { - _lock.acquire(); + _lock.lock(); //NB: we no longer do alignment here. The only class that uses this is // DeletedBufferChain, and we can do the alignment potentially more @@ -55,7 +55,7 @@ ns_alloc(size_t size) { if (page._remaining >= min_page_remaining_size) { _pages.insert(page); } - _lock.release(); + _lock.unlock(); return result; } @@ -71,7 +71,7 @@ ns_alloc(size_t size) { if (page._remaining >= min_page_remaining_size) { _pages.insert(page); } - _lock.release(); + _lock.unlock(); return result; } diff --git a/dtool/src/dtoolbase/pallocator.T b/dtool/src/dtoolbase/pallocator.T index e9bfd3f98e..59af0f0ec1 100644 --- a/dtool/src/dtoolbase/pallocator.T +++ b/dtool/src/dtoolbase/pallocator.T @@ -13,7 +13,7 @@ template INLINE pallocator_single:: -pallocator_single(TypeHandle type_handle) NOEXCEPT : +pallocator_single(TypeHandle type_handle) noexcept : _type_handle(type_handle) { } @@ -37,7 +37,7 @@ deallocate(TYPENAME pallocator_single::pointer p, TYPENAME pallocator_sing template INLINE pallocator_array:: -pallocator_array(TypeHandle type_handle) NOEXCEPT : +pallocator_array(TypeHandle type_handle) noexcept : _type_handle(type_handle) { } diff --git a/dtool/src/dtoolbase/pallocator.h b/dtool/src/dtoolbase/pallocator.h index 3c91b6cc7e..8dfbb8178d 100644 --- a/dtool/src/dtoolbase/pallocator.h +++ b/dtool/src/dtoolbase/pallocator.h @@ -52,11 +52,11 @@ public: typedef TYPENAME allocator::const_reference const_reference; typedef TYPENAME allocator::size_type size_type; - INLINE pallocator_single(TypeHandle type_handle) NOEXCEPT; + INLINE pallocator_single(TypeHandle type_handle) noexcept; // template member functions in VC++ can only be defined in-class. template - INLINE pallocator_single(const pallocator_single ©) NOEXCEPT : + INLINE pallocator_single(const pallocator_single ©) noexcept : _type_handle(copy._type_handle) { } INLINE Type *allocate(size_type n, allocator::const_pointer hint = 0) @@ -81,11 +81,11 @@ public: typedef TYPENAME allocator::const_reference const_reference; typedef TYPENAME allocator::size_type size_type; - INLINE pallocator_array(TypeHandle type_handle = TypeHandle::none()) NOEXCEPT; + INLINE pallocator_array(TypeHandle type_handle = TypeHandle::none()) noexcept; // template member functions in VC++ can only be defined in-class. template - INLINE pallocator_array(const pallocator_array ©) NOEXCEPT : + INLINE pallocator_array(const pallocator_array ©) noexcept : _type_handle(copy._type_handle) { } INLINE Type *allocate(size_type n, allocator::const_pointer hint = 0) diff --git a/dtool/src/dtoolbase/pvector.h b/dtool/src/dtoolbase/pvector.h index 14bd542f37..8da0e88b85 100644 --- a/dtool/src/dtoolbase/pvector.h +++ b/dtool/src/dtoolbase/pvector.h @@ -43,27 +43,24 @@ class pvector : public vector > { public: typedef pallocator_array allocator; typedef vector base_class; - typedef TYPENAME base_class::size_type size_type; + typedef typename base_class::size_type size_type; explicit pvector(TypeHandle type_handle = pvector_type_handle) : base_class(allocator(type_handle)) { } pvector(const pvector ©) : base_class(copy) { } + pvector(pvector &&from) noexcept : base_class(move(from)) {}; explicit pvector(size_type n, TypeHandle type_handle = pvector_type_handle) : base_class(n, Type(), allocator(type_handle)) { } explicit pvector(size_type n, const Type &value, TypeHandle type_handle = pvector_type_handle) : base_class(n, value, allocator(type_handle)) { } pvector(const Type *begin, const Type *end, TypeHandle type_handle = pvector_type_handle) : base_class(begin, end, allocator(type_handle)) { } -#ifdef USE_MOVE_SEMANTICS - pvector(pvector &&from) NOEXCEPT : base_class(move(from)) {}; - - pvector &operator =(pvector &&from) NOEXCEPT { - base_class::operator =(move(from)); - return *this; - } -#endif - pvector &operator =(const pvector ©) { base_class::operator =(copy); return *this; } + + pvector &operator =(pvector &&from) noexcept { + base_class::operator =(move(from)); + return *this; + } }; #endif // USE_STL_ALLOCATOR diff --git a/dtool/src/dtoolbase/typeHandle.I b/dtool/src/dtoolbase/typeHandle.I index 3e9e53a9ae..c63524c18c 100644 --- a/dtool/src/dtoolbase/typeHandle.I +++ b/dtool/src/dtoolbase/typeHandle.I @@ -191,14 +191,6 @@ output(ostream &out) const { out << get_name(); } -/** - * Returns a special zero-valued TypeHandle that is used to indicate no type. - */ -CONSTEXPR TypeHandle TypeHandle:: -none() { - return TypeHandle(0); -} - /** * TypeHandle::none() evaluates to false, everything else evaluates to true. */ @@ -207,21 +199,10 @@ operator bool () const { return (_index != 0); } -/** - * Creates a TypeHandle from a type index without error checking, for use by - * internal functions. - * - * See TypeRegistry::find_type_by_id(). - */ -CONSTEXPR TypeHandle TypeHandle:: -from_index(int index) { - return TypeHandle(index); -} - /** * Private constructor for initializing a TypeHandle from an index, used by * none() and by from_index(). */ -CONSTEXPR TypeHandle:: +constexpr TypeHandle:: TypeHandle(int index) : _index(index) { } diff --git a/dtool/src/dtoolbase/typeHandle.h b/dtool/src/dtoolbase/typeHandle.h index 3138d51e4b..b1b99c4ae0 100644 --- a/dtool/src/dtoolbase/typeHandle.h +++ b/dtool/src/dtoolbase/typeHandle.h @@ -78,9 +78,9 @@ class TypedObject; * that ancestry of a particular type may be queried, and the type name may be * retrieved for run-time display. */ -class EXPCL_DTOOL_DTOOLBASE TypeHandle FINAL { +class EXPCL_DTOOL_DTOOLBASE TypeHandle final { PUBLISHED: - TypeHandle() NOEXCEPT DEFAULT_CTOR; + TypeHandle() noexcept = default; enum MemoryClass { MC_singleton, @@ -129,7 +129,7 @@ PUBLISHED: INLINE int get_index() const; INLINE void output(ostream &out) const; - CONSTEXPR static TypeHandle none(); + constexpr static TypeHandle none() { return TypeHandle(0); } INLINE operator bool () const; MAKE_PROPERTY(index, get_index); @@ -142,10 +142,10 @@ public: void *reallocate_array(void *ptr, size_t size) RETURNS_ALIGNED(MEMORY_HOOK_ALIGNMENT); void deallocate_array(void *ptr); - CONSTEXPR static TypeHandle from_index(int index); + constexpr static TypeHandle from_index(int index) { return TypeHandle(index); } private: - CONSTEXPR TypeHandle(int index); + constexpr TypeHandle(int index); // Only kept temporarily for ABI compatibility. static TypeHandle _none; diff --git a/dtool/src/dtoolbase/typeRegistry.cxx b/dtool/src/dtoolbase/typeRegistry.cxx index 01b8ec498a..7935f3221a 100644 --- a/dtool/src/dtoolbase/typeRegistry.cxx +++ b/dtool/src/dtoolbase/typeRegistry.cxx @@ -32,7 +32,7 @@ TypeRegistry *TypeRegistry::_global_pointer = NULL; */ bool TypeRegistry:: register_type(TypeHandle &type_handle, const string &name) { - _lock->acquire(); + _lock->lock(); if (type_handle != TypeHandle::none()) { // Here's a type that was already registered. Just make sure everything's @@ -40,7 +40,7 @@ register_type(TypeHandle &type_handle, const string &name) { TypeRegistryNode *rnode = look_up(type_handle, NULL); if (&type_handle == &rnode->_ref) { // No problem. - _lock->release(); + _lock->unlock(); assert(rnode->_name == name); return false; } @@ -62,7 +62,7 @@ register_type(TypeHandle &type_handle, const string &name) { _derivations_fresh = false; type_handle = new_handle; - _lock->release(); + _lock->unlock(); return true; } TypeRegistryNode *rnode = (*ri).second; @@ -78,7 +78,7 @@ register_type(TypeHandle &type_handle, const string &name) { if (type_handle == rnode->_handle) { // No problem. - _lock->release(); + _lock->unlock(); return false; } // But wait--the type_handle has changed! We kept a reference to the @@ -87,7 +87,7 @@ register_type(TypeHandle &type_handle, const string &name) { // time, but now it's different! Bad juju. cerr << "Reregistering " << name << "\n"; type_handle = rnode->_handle; - _lock->release(); + _lock->unlock(); return false; } @@ -103,7 +103,7 @@ register_type(TypeHandle &type_handle, const string &name) { type_handle = rnode->_handle; } - _lock->release(); + _lock->unlock(); return false; } @@ -114,7 +114,7 @@ register_type(TypeHandle &type_handle, const string &name) { */ TypeHandle TypeRegistry:: register_dynamic_type(const string &name) { - _lock->acquire(); + _lock->lock(); NameRegistry::iterator ri; ri = _name_registry.find(name); @@ -134,14 +134,14 @@ register_dynamic_type(const string &name) { _name_registry[name] = rnode; _derivations_fresh = false; - _lock->release(); + _lock->unlock(); return *new_handle; } // Return the TypeHandle previously obtained. TypeRegistryNode *rnode = (*ri).second; TypeHandle handle = rnode->_handle; - _lock->release(); + _lock->unlock(); return handle; } @@ -152,7 +152,7 @@ register_dynamic_type(const string &name) { */ void TypeRegistry:: record_derivation(TypeHandle child, TypeHandle parent) { - _lock->acquire(); + _lock->lock(); TypeRegistryNode *cnode = look_up(child, NULL); assert(cnode != (TypeRegistryNode *)NULL); @@ -171,7 +171,7 @@ record_derivation(TypeHandle child, TypeHandle parent) { _derivations_fresh = false; } - _lock->release(); + _lock->unlock(); } /** @@ -182,7 +182,7 @@ record_derivation(TypeHandle child, TypeHandle parent) { */ void TypeRegistry:: record_alternate_name(TypeHandle type, const string &name) { - _lock->acquire(); + _lock->lock(); TypeRegistryNode *rnode = look_up(type, (TypedObject *)NULL); if (rnode != (TypeRegistryNode *)NULL) { @@ -190,7 +190,7 @@ record_alternate_name(TypeHandle type, const string &name) { _name_registry.insert(NameRegistry::value_type(name, rnode)).first; if ((*ri).second != rnode) { - _lock->release(); + _lock->unlock(); cerr << "Name " << name << " already assigned to TypeHandle " << rnode->_name << "; cannot reassign to " << type << "\n"; @@ -199,7 +199,7 @@ record_alternate_name(TypeHandle type, const string &name) { } - _lock->release(); + _lock->unlock(); } /** @@ -208,7 +208,7 @@ record_alternate_name(TypeHandle type, const string &name) { */ TypeHandle TypeRegistry:: find_type(const string &name) const { - _lock->acquire(); + _lock->lock(); TypeHandle handle = TypeHandle::none(); NameRegistry::const_iterator ri; @@ -216,7 +216,7 @@ find_type(const string &name) const { if (ri != _name_registry.end()) { handle = (*ri).second->_handle; } - _lock->release(); + _lock->unlock(); return handle; } @@ -248,11 +248,11 @@ find_type_by_id(int id) const { */ string TypeRegistry:: get_name(TypeHandle type, TypedObject *object) const { - _lock->acquire(); + _lock->lock(); TypeRegistryNode *rnode = look_up(type, object); assert(rnode != (TypeRegistryNode *)NULL); string name = rnode->_name; - _lock->release(); + _lock->unlock(); return name; } @@ -273,7 +273,7 @@ get_name(TypeHandle type, TypedObject *object) const { bool TypeRegistry:: is_derived_from(TypeHandle child, TypeHandle base, TypedObject *child_object) { - _lock->acquire(); + _lock->lock(); const TypeRegistryNode *child_node = look_up(child, child_object); const TypeRegistryNode *base_node = look_up(base, (TypedObject *)NULL); @@ -284,7 +284,7 @@ is_derived_from(TypeHandle child, TypeHandle base, freshen_derivations(); bool result = TypeRegistryNode::is_derived_from(child_node, base_node); - _lock->release(); + _lock->unlock(); return result; } @@ -293,9 +293,9 @@ is_derived_from(TypeHandle child, TypeHandle base, */ int TypeRegistry:: get_num_typehandles() { - _lock->acquire(); + _lock->lock(); int num_types = (int)_handle_registry.size(); - _lock->release(); + _lock->unlock(); return num_types; } @@ -304,12 +304,12 @@ get_num_typehandles() { */ TypeHandle TypeRegistry:: get_typehandle(int n) { - _lock->acquire(); + _lock->lock(); TypeRegistryNode *rnode = NULL; if (n >= 0 && n < (int)_handle_registry.size()) { rnode = _handle_registry[n]; } - _lock->release(); + _lock->unlock(); if (rnode != (TypeRegistryNode *)NULL) { return rnode->_handle; @@ -324,10 +324,10 @@ get_typehandle(int n) { */ int TypeRegistry:: get_num_root_classes() { - _lock->acquire(); + _lock->lock(); freshen_derivations(); int num_roots = (int)_root_classes.size(); - _lock->release(); + _lock->unlock(); return num_roots; } @@ -336,7 +336,7 @@ get_num_root_classes() { */ TypeHandle TypeRegistry:: get_root_class(int n) { - _lock->acquire(); + _lock->lock(); freshen_derivations(); TypeHandle handle; if (n >= 0 && n < (int)_root_classes.size()) { @@ -344,7 +344,7 @@ get_root_class(int n) { } else { handle = TypeHandle::none(); } - _lock->release(); + _lock->unlock(); return handle; } @@ -362,11 +362,11 @@ get_root_class(int n) { */ int TypeRegistry:: get_num_parent_classes(TypeHandle child, TypedObject *child_object) const { - _lock->acquire(); + _lock->lock(); TypeRegistryNode *rnode = look_up(child, child_object); assert(rnode != (TypeRegistryNode *)NULL); int num_parents = (int)rnode->_parent_classes.size(); - _lock->release(); + _lock->unlock(); return num_parents; } @@ -376,7 +376,7 @@ get_num_parent_classes(TypeHandle child, TypedObject *child_object) const { */ TypeHandle TypeRegistry:: get_parent_class(TypeHandle child, int index) const { - _lock->acquire(); + _lock->lock(); TypeHandle handle; TypeRegistryNode *rnode = look_up(child, (TypedObject *)NULL); assert(rnode != (TypeRegistryNode *)NULL); @@ -385,7 +385,7 @@ get_parent_class(TypeHandle child, int index) const { } else { handle = TypeHandle::none(); } - _lock->release(); + _lock->unlock(); return handle; } @@ -399,11 +399,11 @@ get_parent_class(TypeHandle child, int index) const { */ int TypeRegistry:: get_num_child_classes(TypeHandle child, TypedObject *child_object) const { - _lock->acquire(); + _lock->lock(); TypeRegistryNode *rnode = look_up(child, child_object); assert(rnode != (TypeRegistryNode *)NULL); int num_children = (int)rnode->_child_classes.size(); - _lock->release(); + _lock->unlock(); return num_children; } @@ -413,7 +413,7 @@ get_num_child_classes(TypeHandle child, TypedObject *child_object) const { */ TypeHandle TypeRegistry:: get_child_class(TypeHandle child, int index) const { - _lock->acquire(); + _lock->lock(); TypeHandle handle; TypeRegistryNode *rnode = look_up(child, (TypedObject *)NULL); assert(rnode != (TypeRegistryNode *)NULL); @@ -422,7 +422,7 @@ get_child_class(TypeHandle child, int index) const { } else { handle = TypeHandle::none(); } - _lock->release(); + _lock->unlock(); return handle; } @@ -439,7 +439,7 @@ get_child_class(TypeHandle child, int index) const { TypeHandle TypeRegistry:: get_parent_towards(TypeHandle child, TypeHandle base, TypedObject *child_object) { - _lock->acquire(); + _lock->lock(); TypeHandle handle; const TypeRegistryNode *child_node = look_up(child, child_object); const TypeRegistryNode *base_node = look_up(base, NULL); @@ -447,7 +447,7 @@ get_parent_towards(TypeHandle child, TypeHandle base, base_node != (TypeRegistryNode *)NULL); freshen_derivations(); handle = TypeRegistryNode::get_parent_towards(child_node, base_node); - _lock->release(); + _lock->unlock(); return handle; } @@ -462,7 +462,7 @@ get_parent_towards(TypeHandle child, TypeHandle base, void TypeRegistry:: reregister_types() { init_lock(); - _lock->acquire(); + _lock->lock(); HandleRegistry::iterator ri; TypeRegistry *reg = ptr(); for (ri = reg->_handle_registry.begin(); @@ -473,7 +473,7 @@ reregister_types() { cerr << "Reregistering " << rnode->_name << "\n"; } } - _lock->release(); + _lock->unlock(); } @@ -483,9 +483,9 @@ reregister_types() { */ void TypeRegistry:: write(ostream &out) const { - _lock->acquire(); + _lock->lock(); do_write(out); - _lock->release(); + _lock->unlock(); } /** @@ -613,9 +613,9 @@ look_up_invalid(TypeHandle handle, TypedObject *object) const { // But we're lucky enough to have a TypedObject pointer handy! Maybe we // can use it to resolve the error. We have to drop the lock while we // do this, so we don't get a recursive lock. - _lock->release(); + _lock->unlock(); handle = object->force_init_type(); - _lock->acquire(); + _lock->lock(); if (handle._index == 0) { // Strange. diff --git a/dtool/src/dtoolbase/typedObject.h b/dtool/src/dtoolbase/typedObject.h index f3d6c193e3..dd60515f16 100644 --- a/dtool/src/dtoolbase/typedObject.h +++ b/dtool/src/dtoolbase/typedObject.h @@ -87,9 +87,9 @@ */ class EXPCL_DTOOL_DTOOLBASE TypedObject : public MemoryBase { public: - INLINE TypedObject() DEFAULT_CTOR; - INLINE TypedObject(const TypedObject ©) DEFAULT_CTOR; - INLINE TypedObject &operator = (const TypedObject ©) DEFAULT_ASSIGN; + INLINE TypedObject() = default; + INLINE TypedObject(const TypedObject ©) = default; + INLINE TypedObject &operator = (const TypedObject ©) = default; PUBLISHED: // A virtual destructor is just a good idea. diff --git a/dtool/src/dtoolutil/filename.I b/dtool/src/dtoolutil/filename.I index 9bc23dfca3..2f099548e3 100644 --- a/dtool/src/dtoolutil/filename.I +++ b/dtool/src/dtoolutil/filename.I @@ -54,24 +54,20 @@ Filename(const Filename ©) : { } -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE Filename:: -Filename(string &&filename) NOEXCEPT { - _flags = 0; - (*this) = move(filename); +Filename(string &&filename) noexcept : _flags(0) { + (*this) = std::move(filename); } -#endif // USE_MOVE_SEMANTICS -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE Filename:: -Filename(Filename &&from) NOEXCEPT : - _filename(move(from._filename)), +Filename(Filename &&from) noexcept : + _filename(std::move(from._filename)), _dirname_end(from._dirname_end), _basename_start(from._basename_start), _basename_end(from._basename_end), @@ -81,7 +77,6 @@ Filename(Filename &&from) NOEXCEPT : _flags(from._flags) { } -#endif // USE_MOVE_SEMANTICS /** * Creates an empty Filename. @@ -217,28 +212,25 @@ operator = (const Filename ©) { return *this; } -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE Filename &Filename:: -operator = (string &&filename) NOEXCEPT { - _filename = move(filename); +operator = (string &&filename) noexcept { + _filename = std::move(filename); locate_basename(); locate_extension(); locate_hash(); return *this; } -#endif // USE_MOVE_SEMANTICS -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE Filename &Filename:: -operator = (Filename &&from) NOEXCEPT { - _filename = move(from._filename); +operator = (Filename &&from) noexcept { + _filename = std::move(from._filename); _dirname_end = from._dirname_end; _basename_start = from._basename_start; _basename_end = from._basename_end; @@ -248,7 +240,6 @@ operator = (Filename &&from) NOEXCEPT { _flags = from._flags; return *this; } -#endif // USE_MOVE_SEMANTICS /** * diff --git a/dtool/src/dtoolutil/filename.cxx b/dtool/src/dtoolutil/filename.cxx index d2c566b557..42bdf12e2f 100644 --- a/dtool/src/dtoolutil/filename.cxx +++ b/dtool/src/dtoolutil/filename.cxx @@ -48,7 +48,7 @@ #include #endif -#if defined(__ANDROID__) && !defined(HAVE_LOCKF) +#if defined(__ANDROID__) && !defined(PHAVE_LOCKF) // Needed for flock. #include #endif @@ -2752,7 +2752,7 @@ atomic_compare_and_exchange_contents(string &orig_contents, orig_contents = string(); -#ifdef HAVE_LOCKF +#ifdef PHAVE_LOCKF if (lockf(fd, F_LOCK, 0) != 0) { #else if (flock(fd, LOCK_EX) != 0) { @@ -2868,7 +2868,7 @@ atomic_read_contents(string &contents) const { contents = string(); -#ifdef HAVE_LOCKF +#ifdef PHAVE_LOCKF if (lockf(fd, F_LOCK, 0) != 0) { #else if (flock(fd, LOCK_EX) != 0) { diff --git a/dtool/src/dtoolutil/filename.h b/dtool/src/dtoolutil/filename.h index 76ee5e0b39..07927a846c 100644 --- a/dtool/src/dtoolutil/filename.h +++ b/dtool/src/dtoolutil/filename.h @@ -58,11 +58,8 @@ public: INLINE Filename(const string &filename); INLINE Filename(const wstring &filename); INLINE Filename(const Filename ©); - -#ifdef USE_MOVE_SEMANTICS - INLINE Filename(string &&filename) NOEXCEPT; - INLINE Filename(Filename &&from) NOEXCEPT; -#endif + INLINE Filename(string &&filename) noexcept; + INLINE Filename(Filename &&from) noexcept; PUBLISHED: INLINE Filename(); @@ -106,11 +103,8 @@ PUBLISHED: INLINE Filename &operator = (const wstring &filename); INLINE Filename &operator = (const char *filename); INLINE Filename &operator = (const Filename ©); - -#ifdef USE_MOVE_SEMANTICS - INLINE Filename &operator = (string &&filename) NOEXCEPT; - INLINE Filename &operator = (Filename &&from) NOEXCEPT; -#endif + INLINE Filename &operator = (string &&filename) noexcept; + INLINE Filename &operator = (Filename &&from) noexcept; // And retrieval is by any of the classic string operations. INLINE operator const string & () const; diff --git a/dtool/src/interrogate/interfaceMakerPythonNative.cxx b/dtool/src/interrogate/interfaceMakerPythonNative.cxx index 5ae2d3fca9..7542569d46 100644 --- a/dtool/src/interrogate/interfaceMakerPythonNative.cxx +++ b/dtool/src/interrogate/interfaceMakerPythonNative.cxx @@ -2601,7 +2601,6 @@ write_module_class(ostream &out, Object *obj) { // compare_to function, which is mapped to the tp_compare slot, which // Python 3 no longer has. So, we'll write code to fall back to that if // no matching comparison operator was found. - out << "#if PY_MAJOR_VERSION >= 3\n"; out << " // All is not lost; we still have the compare_to function to fall back onto.\n"; out << " int cmpval = " << slots["tp_compare"]._wrapper_name << "(self, arg);\n"; out << " if (cmpval == -1 && _PyErr_OCCURRED()) {\n"; @@ -2625,7 +2624,6 @@ write_module_class(ostream &out, Object *obj) { out << " case Py_GE:\n"; out << " return PyBool_FromLong(cmpval >= 0);\n"; out << " }\n"; - out << "#endif\n\n"; } out << " Py_INCREF(Py_NotImplemented);\n"; diff --git a/dtool/src/prc/configVariableFilename.cxx b/dtool/src/prc/configVariableFilename.cxx index 3939199148..1679082ef5 100644 --- a/dtool/src/prc/configVariableFilename.cxx +++ b/dtool/src/prc/configVariableFilename.cxx @@ -23,7 +23,7 @@ reload_cache() { // thread-safe manner. But chances are that the first time this is called // is at static init time, when there is no risk of data races. static MutexImpl lock; - lock.acquire(); + lock.lock(); // We check again for cache validity since another thread may have beaten // us to the punch while we were waiting for the lock. @@ -42,5 +42,5 @@ reload_cache() { mark_cache_valid(_local_modified); } - lock.release(); + lock.unlock(); } diff --git a/dtool/src/prc/configVariableString.cxx b/dtool/src/prc/configVariableString.cxx index 3dcaaf6deb..ebb4a751d2 100644 --- a/dtool/src/prc/configVariableString.cxx +++ b/dtool/src/prc/configVariableString.cxx @@ -22,7 +22,7 @@ reload_cache() { // thread-safe manner. But chances are that the first time this is called // is at static init time, when there is no risk of data races. static MutexImpl lock; - lock.acquire(); + lock.lock(); // We check again for cache validity since another thread may have beaten // us to the punch while we were waiting for the lock. @@ -31,5 +31,5 @@ reload_cache() { mark_cache_valid(_local_modified); } - lock.release(); + lock.unlock(); } diff --git a/dtool/src/prc/notifyCategory.I b/dtool/src/prc/notifyCategory.I index 46aca56bb2..62a332b388 100644 --- a/dtool/src/prc/notifyCategory.I +++ b/dtool/src/prc/notifyCategory.I @@ -88,7 +88,7 @@ is_debug() const { * "debug" severities, and these methods are redefined to be static to make it * more obvious to the compiler. */ -CONSTEXPR bool NotifyCategory:: +constexpr bool NotifyCategory:: is_spam() { return false; } @@ -98,7 +98,7 @@ is_spam() { * "debug" severities, and these methods are redefined to be static to make it * more obvious to the compiler. */ -CONSTEXPR bool NotifyCategory:: +constexpr bool NotifyCategory:: is_debug() { return false; } diff --git a/dtool/src/prc/notifyCategory.h b/dtool/src/prc/notifyCategory.h index 61f4e71906..ee25b56268 100644 --- a/dtool/src/prc/notifyCategory.h +++ b/dtool/src/prc/notifyCategory.h @@ -55,8 +55,8 @@ PUBLISHED: INLINE bool is_spam() const; INLINE bool is_debug() const; #else - CONSTEXPR static bool is_spam(); - CONSTEXPR static bool is_debug(); + constexpr static bool is_spam(); + constexpr static bool is_debug(); #endif INLINE bool is_info() const; INLINE bool is_warning() const; diff --git a/dtool/src/prc/notifyCategoryProxy.I b/dtool/src/prc/notifyCategoryProxy.I index 9a05f35625..8c0a5dc47d 100644 --- a/dtool/src/prc/notifyCategoryProxy.I +++ b/dtool/src/prc/notifyCategoryProxy.I @@ -74,7 +74,7 @@ is_spam() { } #else template -CONSTEXPR bool NotifyCategoryProxy:: +constexpr bool NotifyCategoryProxy:: is_spam() { return false; } @@ -92,7 +92,7 @@ is_debug() { } #else template -CONSTEXPR bool NotifyCategoryProxy:: +constexpr bool NotifyCategoryProxy:: is_debug() { return false; } diff --git a/dtool/src/prc/notifyCategoryProxy.h b/dtool/src/prc/notifyCategoryProxy.h index 653da558de..eaa83a8282 100644 --- a/dtool/src/prc/notifyCategoryProxy.h +++ b/dtool/src/prc/notifyCategoryProxy.h @@ -75,8 +75,8 @@ public: INLINE bool is_spam(); INLINE bool is_debug(); #else - CONSTEXPR static bool is_spam(); - CONSTEXPR static bool is_debug(); + constexpr static bool is_spam(); + constexpr static bool is_debug(); #endif INLINE bool is_info(); INLINE bool is_warning(); diff --git a/dtool/src/prc/streamWrapper.I b/dtool/src/prc/streamWrapper.I index 788498aceb..a6438e318e 100644 --- a/dtool/src/prc/streamWrapper.I +++ b/dtool/src/prc/streamWrapper.I @@ -36,7 +36,7 @@ StreamWrapperBase() { */ INLINE void StreamWrapperBase:: acquire() { - _lock.acquire(); + _lock.lock(); #ifdef SIMPLE_THREADS while (_lock_flag) { thread_yield(); @@ -55,7 +55,7 @@ release() { assert(_lock_flag); _lock_flag = false; #endif - _lock.release(); + _lock.unlock(); } /** diff --git a/dtool/src/prc/streamWrapper.h b/dtool/src/prc/streamWrapper.h index f3e4028c1b..62e57fa9e1 100644 --- a/dtool/src/prc/streamWrapper.h +++ b/dtool/src/prc/streamWrapper.h @@ -24,9 +24,7 @@ class EXPCL_DTOOL_PRC StreamWrapperBase { protected: INLINE StreamWrapperBase(); - -private: - INLINE StreamWrapperBase(const StreamWrapperBase ©) DELETED; + INLINE StreamWrapperBase(const StreamWrapperBase ©) = delete; PUBLISHED: INLINE void acquire(); diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 56ffecdbd5..a810da13af 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -315,9 +315,7 @@ def parseopts(args): usage("Invalid SHA-1 hash given for --git-commit option!") if GetTarget() == 'windows': - show_warning = False if not MSVC_VERSION: - show_warning = True print("No MSVC version specified. Defaulting to 14 (Visual Studio 2015).") MSVC_VERSION = (14, 0) else: @@ -325,22 +323,19 @@ def parseopts(args): MSVC_VERSION = tuple(int(d) for d in MSVC_VERSION.split('.'))[:2] if (len(MSVC_VERSION) == 1): MSVC_VERSION += (0,) - if MSVC_VERSION < (14, 0): - show_warning = True except: usage("Invalid setting for --msvc-version") - if show_warning: - warn_prefix = "%sWARNING:%s " % (GetColor("red"), GetColor()) + if MSVC_VERSION < (14, 0): + warn_prefix = "%sERROR:%s " % (GetColor("red"), GetColor()) print("=========================================================================") - print(warn_prefix + "Support for MSVC versions before 2015 will soon be discontinued.") - print(warn_prefix + "If you wish to keep using MSVC 2010, make your voice heard at:") + print(warn_prefix + "Support for MSVC versions before 2015 has been discontinued.") + print(warn_prefix + "For more information, or any questions, please visit:") print(warn_prefix + " https://github.com/panda3d/panda3d/issues/288") - if MSVC_VERSION >= (14, 0): - print(warn_prefix + "To squelch this warning, pass --msvc-version {0}.{1}".format(*MSVC_VERSION)) print("=========================================================================") sys.stdout.flush() time.sleep(1.0) + sys.exit(1) if not WINDOWS_SDK: print("No Windows SDK version specified. Defaulting to '7.1'.") @@ -2272,12 +2267,10 @@ DTOOL_CONFIG=[ ("DO_PIPELINING", '1', '1'), ("DEFAULT_PATHSEP", '";"', '":"'), ("WORDS_BIGENDIAN", 'UNDEF', 'UNDEF'), - ("HAVE_NAMESPACE", '1', '1'), ("HAVE_OPEN_MASK", 'UNDEF', 'UNDEF'), - ("HAVE_LOCKF", '1', '1'), + ("PHAVE_LOCKF", '1', '1'), ("HAVE_WCHAR_T", '1', '1'), ("HAVE_WSTRING", '1', '1'), - ("HAVE_TYPENAME", '1', '1'), ("SIMPLE_STRUCT_POINTERS", '1', 'UNDEF'), ("HAVE_DINKUM", 'UNDEF', 'UNDEF'), ("HAVE_STL_HASH", 'UNDEF', 'UNDEF'), @@ -2452,7 +2445,7 @@ def WriteConfigSettings(): # Android does have RTTI, but we disable it anyway. dtool_config["HAVE_RTTI"] = 'UNDEF' dtool_config["PHAVE_GLOB_H"] = 'UNDEF' - dtool_config["HAVE_LOCKF"] = 'UNDEF' + dtool_config["PHAVE_LOCKF"] = 'UNDEF' dtool_config["HAVE_VIDEO4LINUX"] = 'UNDEF' if (GetOptimize() <= 2 and GetTarget() == "windows"): @@ -2613,18 +2606,21 @@ PANDAVERSION_H_RUNTIME=""" CHECKPANDAVERSION_CXX=""" # include "dtoolbase.h" -EXPCL_DTOOL_DTOOLUTIL int panda_version_$VERSION1_$VERSION2 = 0; +EXPCL_DTOOL_DTOOLBASE int panda_version_$VERSION1_$VERSION2 = 0; """ CHECKPANDAVERSION_H=""" +# ifndef CHECKPANDAVERSION_H +# define CHECKPANDAVERSION_H # include "dtoolbase.h" -extern EXPCL_DTOOL_DTOOLUTIL int panda_version_$VERSION1_$VERSION2; -# ifndef WIN32 -/* For Windows, exporting the symbol from the DLL is sufficient; the - DLL will not load unless all expected public symbols are defined. - Other systems may not mind if the symbol is absent unless we - explictly write code that references it. */ -static int check_panda_version = panda_version_$VERSION1_$VERSION2; +extern EXPCL_DTOOL_DTOOLBASE int panda_version_$VERSION1_$VERSION2; +// Hack to forcibly depend on the check +template +class CheckPandaVersion { +public: + int check_version() { return panda_version_$VERSION1_$VERSION2; } +}; +template class CheckPandaVersion; # endif """ diff --git a/panda/metalibs/panda/panda.cxx b/panda/metalibs/panda/panda.cxx index 8a193a8a28..9c9cb8bb60 100644 --- a/panda/metalibs/panda/panda.cxx +++ b/panda/metalibs/panda/panda.cxx @@ -14,12 +14,6 @@ #include "config_pstatclient.h" #endif -// By including checkPandaVersion.h, we guarantee that runtime attempts to -// load libpanda.so.dll will fail if they inadvertently link with the wrong -// version of libdtool.so.dll. - -#include "checkPandaVersion.h" - #if !defined(CPPPARSER) && !defined(BUILDING_LIBPANDA) #error Buildsystem error: BUILDING_LIBPANDA not defined #endif diff --git a/panda/metalibs/pandabullet/pandabullet.cxx b/panda/metalibs/pandabullet/pandabullet.cxx index 4eaa6fcd04..588d47266e 100644 --- a/panda/metalibs/pandabullet/pandabullet.cxx +++ b/panda/metalibs/pandabullet/pandabullet.cxx @@ -7,12 +7,6 @@ #include "pandabullet.h" #include "config_bullet.h" -// By including checkPandaVersion.h, we guarantee that runtime attempts to -// load libpandabullet.so.dll will fail if they inadvertently link with the -// wrong version of libdtool.so.dll. - -#include "checkPandaVersion.h" - /** * Initializes the library. This must be called at least once before any of * the functions or classes in this library can be used. Normally it will be diff --git a/panda/metalibs/pandadx9/pandadx9.cxx b/panda/metalibs/pandadx9/pandadx9.cxx index 8953365225..a54bb7dbf2 100644 --- a/panda/metalibs/pandadx9/pandadx9.cxx +++ b/panda/metalibs/pandadx9/pandadx9.cxx @@ -9,12 +9,6 @@ #include "config_dxgsg9.h" #include "wdxGraphicsPipe9.h" -// By including checkPandaVersion.h, we guarantee that runtime attempts to -// load libpandadx9.dll will fail if they inadvertently link with the wrong -// version of libdtool.dll. - -#include "checkPandaVersion.h" - /** * Initializes the library. This must be called at least once before any of * the functions or classes in this library can be used. Normally it will be diff --git a/panda/metalibs/pandaegg/pandaegg.cxx b/panda/metalibs/pandaegg/pandaegg.cxx index 7bb592e488..235dc62a5b 100644 --- a/panda/metalibs/pandaegg/pandaegg.cxx +++ b/panda/metalibs/pandaegg/pandaegg.cxx @@ -9,12 +9,6 @@ #include "config_egg.h" #include "config_egg2pg.h" -// By including checkPandaVersion.h, we guarantee that runtime attempts to -// load libpandaegg.so.dll will fail if they inadvertently link with the wrong -// version of libdtool.so.dll. - -#include "checkPandaVersion.h" - /** * Initializes the library. This must be called at least once before any of * the functions or classes in this library can be used. Normally it will be diff --git a/panda/metalibs/pandaegg/pandaeggnopg.cxx b/panda/metalibs/pandaegg/pandaeggnopg.cxx index 1b72143237..2a5c86fead 100644 --- a/panda/metalibs/pandaegg/pandaeggnopg.cxx +++ b/panda/metalibs/pandaegg/pandaeggnopg.cxx @@ -8,12 +8,6 @@ #include "config_egg.h" -// By including checkPandaVersion.h, we guarantee that runtime attempts to -// load libpandaegg.so.dll will fail if they inadvertently link with the wrong -// version of libdtool.so.dll. - -#include "checkPandaVersion.h" - /** * Initializes the library. This must be called at least once before any of * the functions or classes in this library can be used. Normally it will be diff --git a/panda/metalibs/pandaexpress/pandaexpress.cxx b/panda/metalibs/pandaexpress/pandaexpress.cxx index 6c6adc0e77..d50aead132 100644 --- a/panda/metalibs/pandaexpress/pandaexpress.cxx +++ b/panda/metalibs/pandaexpress/pandaexpress.cxx @@ -3,9 +3,3 @@ * @author drose * @date 2000-05-15 */ - -// By including checkPandaVersion.h, we guarantee that runtime attempts to -// load libpandaexpress.so.dll will fail if they inadvertently link with the -// wrong version of libdtool.so.dll. - -#include "checkPandaVersion.h" diff --git a/panda/metalibs/pandafx/pandafx.cxx b/panda/metalibs/pandafx/pandafx.cxx index 968ab2f285..64f4a3abd8 100644 --- a/panda/metalibs/pandafx/pandafx.cxx +++ b/panda/metalibs/pandafx/pandafx.cxx @@ -8,12 +8,6 @@ #include "config_distort.h" -// By including checkPandaVersion.h, we guarantee that runtime attempts to -// load libpandafx.so.dll will fail if they inadvertently link with the wrong -// version of libdtool.so.dll. - -#include "checkPandaVersion.h" - /** * Initializes the library. This must be called at least once before any of * the functions or classes in this library can be used. Normally it will be diff --git a/panda/metalibs/pandagl/pandagl.cxx b/panda/metalibs/pandagl/pandagl.cxx index 71b6e83025..0e33961c9f 100644 --- a/panda/metalibs/pandagl/pandagl.cxx +++ b/panda/metalibs/pandagl/pandagl.cxx @@ -30,12 +30,6 @@ #error One of HAVE_WGL, HAVE_COCOA, HAVE_CARBON or HAVE_GLX must be defined when compiling pandagl! #endif -// By including checkPandaVersion.h, we guarantee that runtime attempts to -// load libpandagl.so.dll will fail if they inadvertently link with the wrong -// version of libdtool.so.dll. - -#include "checkPandaVersion.h" - /** * Initializes the library. This must be called at least once before any of * the functions or classes in this library can be used. Normally it will be diff --git a/panda/metalibs/pandagles/pandagles.cxx b/panda/metalibs/pandagles/pandagles.cxx index 27053534c6..f2ed5f3e1a 100644 --- a/panda/metalibs/pandagles/pandagles.cxx +++ b/panda/metalibs/pandagles/pandagles.cxx @@ -17,12 +17,6 @@ #include "eglGraphicsPipe.h" #endif -// By including checkPandaVersion.h, we guarantee that runtime attempts to -// load libpandagles.so.dll will fail if they inadvertently link with the -// wrong version of libdtool.so.dll. - -#include "checkPandaVersion.h" - /** * Initializes the library. This must be called at least once before any of * the functions or classes in this library can be used. Normally it will be diff --git a/panda/metalibs/pandagles2/pandagles2.cxx b/panda/metalibs/pandagles2/pandagles2.cxx index 4810bd60af..b0b36c63ff 100644 --- a/panda/metalibs/pandagles2/pandagles2.cxx +++ b/panda/metalibs/pandagles2/pandagles2.cxx @@ -12,12 +12,6 @@ #include "config_egldisplay.h" #include "eglGraphicsPipe.h" -// By including checkPandaVersion.h, we guarantee that runtime attempts to -// load libpandagles2.so.dll will fail if they inadvertently link with the -// wrong version of libdtool.so.dll. - -#include "checkPandaVersion.h" - /** * Initializes the library. This must be called at least once before any of * the functions or classes in this library can be used. Normally it will be diff --git a/panda/metalibs/pandaode/pandaode.cxx b/panda/metalibs/pandaode/pandaode.cxx index 583b9c3a9d..2b19c71e3b 100644 --- a/panda/metalibs/pandaode/pandaode.cxx +++ b/panda/metalibs/pandaode/pandaode.cxx @@ -7,12 +7,6 @@ #include "pandaode.h" #include "config_ode.h" -// By including checkPandaVersion.h, we guarantee that runtime attempts to -// load libpandaode.so.dll will fail if they inadvertently link with the wrong -// version of libdtool.so.dll. - -#include "checkPandaVersion.h" - /** * Initializes the library. This must be called at least once before any of * the functions or classes in this library can be used. Normally it will be diff --git a/panda/metalibs/pandaphysics/pandaphysics.cxx b/panda/metalibs/pandaphysics/pandaphysics.cxx index 890d450d47..02997a1505 100644 --- a/panda/metalibs/pandaphysics/pandaphysics.cxx +++ b/panda/metalibs/pandaphysics/pandaphysics.cxx @@ -8,12 +8,6 @@ #include "config_physics.h" #include "config_particlesystem.h" -// By including checkPandaVersion.h, we guarantee that runtime attempts to -// load libpandaphysics.so.dll will fail if they inadvertently link with the -// wrong version of libdtool.so.dll. - -#include "checkPandaVersion.h" - /** * Initializes the library. This must be called at least once before any of * the functions or classes in this library can be used. Normally it will be diff --git a/panda/metalibs/pandaphysx/pandaphysx.cxx b/panda/metalibs/pandaphysx/pandaphysx.cxx index fd75ee86b5..3e505f1d7d 100644 --- a/panda/metalibs/pandaphysx/pandaphysx.cxx +++ b/panda/metalibs/pandaphysx/pandaphysx.cxx @@ -7,12 +7,6 @@ #include "pandaphysx.h" #include "config_physx.h" -// By including checkPandaVersion.h, we guarantee that runtime attempts to -// load libpandaphysx.so.dll will fail if they inadvertently link with the -// wrong version of libdtool.so.dll. - -#include "checkPandaVersion.h" - /** * Initializes the library. This must be called at least once before any of * the functions or classes in this library can be used. Normally it will be diff --git a/panda/src/android/pview.cxx b/panda/src/android/pview.cxx index 2b31bb7577..6683b6206b 100644 --- a/panda/src/android/pview.cxx +++ b/panda/src/android/pview.cxx @@ -21,12 +21,6 @@ #include "bamCache.h" #include "virtualFileSystem.h" -// By including checkPandaVersion.h, we guarantee that runtime attempts to run -// pview will fail if it inadvertently links with the wrong version of -// libdtool.so.dll. - -#include "checkPandaVersion.h" - int main(int argc, char **argv) { PandaFramework framework; framework.open_framework(argc, argv); diff --git a/panda/src/bullet/bulletSoftBodyNode.cxx b/panda/src/bullet/bulletSoftBodyNode.cxx index c4094af652..8321c610f1 100644 --- a/panda/src/bullet/bulletSoftBodyNode.cxx +++ b/panda/src/bullet/bulletSoftBodyNode.cxx @@ -134,7 +134,7 @@ BulletSoftBodyNodeElement BulletSoftBodyNode:: get_node(int idx) const { LightMutexHolder holder(BulletWorld::get_global_lock()); - nassertr(idx >=0 && idx < get_num_nodes(), BulletSoftBodyNodeElement::empty()); + nassertr(idx >= 0 && idx < _soft->m_nodes.size(), BulletSoftBodyNodeElement::empty()); return BulletSoftBodyNodeElement(_soft->m_nodes[idx]); } diff --git a/panda/src/bullet/bulletTriangleMesh.h b/panda/src/bullet/bulletTriangleMesh.h index 0f9cb8174b..27c0598b13 100644 --- a/panda/src/bullet/bulletTriangleMesh.h +++ b/panda/src/bullet/bulletTriangleMesh.h @@ -32,7 +32,7 @@ class EXPCL_PANDABULLET BulletTriangleMesh : public TypedWritableReferenceCount { PUBLISHED: BulletTriangleMesh(); - ~BulletTriangleMesh() DEFAULT_DTOR; + ~BulletTriangleMesh() = default; void add_triangle(const LPoint3 &p0, const LPoint3 &p1, diff --git a/panda/src/chan/partBundle.cxx b/panda/src/chan/partBundle.cxx index f519d09a60..3806f812a5 100644 --- a/panda/src/chan/partBundle.cxx +++ b/panda/src/chan/partBundle.cxx @@ -153,7 +153,7 @@ apply_transform(const TransformState *transform) { if ((*ati).first.is_valid_pointer() && (*ati).second.is_valid_pointer()) { // Here's our cached result. - return (*ati).second.p(); + return (*ati).second.lock(); } } diff --git a/panda/src/char/characterJoint.cxx b/panda/src/char/characterJoint.cxx index 6ce5b0be88..fee1a90f76 100644 --- a/panda/src/char/characterJoint.cxx +++ b/panda/src/char/characterJoint.cxx @@ -214,7 +214,7 @@ bool CharacterJoint:: remove_net_transform(PandaNode *node) { CPT(RenderEffect) effect = node->get_effect(CharacterJointEffect::get_class_type()); if (effect != (RenderEffect *)NULL && - DCAST(CharacterJointEffect, effect)->get_character() == _character) { + DCAST(CharacterJointEffect, effect)->matches_character(_character)) { node->clear_effect(CharacterJointEffect::get_class_type()); } @@ -244,7 +244,7 @@ clear_net_transforms() { CPT(RenderEffect) effect = node->get_effect(CharacterJointEffect::get_class_type()); if (effect != (RenderEffect *)NULL && - DCAST(CharacterJointEffect, effect)->get_character() == _character) { + DCAST(CharacterJointEffect, effect)->matches_character(_character)) { node->clear_effect(CharacterJointEffect::get_class_type()); } } @@ -306,7 +306,7 @@ bool CharacterJoint:: remove_local_transform(PandaNode *node) { CPT(RenderEffect) effect = node->get_effect(CharacterJointEffect::get_class_type()); if (effect != (RenderEffect *)NULL && - DCAST(CharacterJointEffect, effect)->get_character() == _character) { + DCAST(CharacterJointEffect, effect)->matches_character(_character)) { node->clear_effect(CharacterJointEffect::get_class_type()); } @@ -336,7 +336,7 @@ clear_local_transforms() { CPT(RenderEffect) effect = node->get_effect(CharacterJointEffect::get_class_type()); if (effect != (RenderEffect *)NULL && - DCAST(CharacterJointEffect, effect)->get_character() == _character) { + DCAST(CharacterJointEffect, effect)->matches_character(_character)) { node->clear_effect(CharacterJointEffect::get_class_type()); } } @@ -427,7 +427,7 @@ set_character(Character *character) { CPT(RenderEffect) effect = node->get_effect(CharacterJointEffect::get_class_type()); if (effect != (RenderEffect *)NULL && - DCAST(CharacterJointEffect, effect)->get_character() == _character) { + DCAST(CharacterJointEffect, effect)->matches_character(_character)) { node->clear_effect(CharacterJointEffect::get_class_type()); } } @@ -438,7 +438,7 @@ set_character(Character *character) { CPT(RenderEffect) effect = node->get_effect(CharacterJointEffect::get_class_type()); if (effect != (RenderEffect *)NULL && - DCAST(CharacterJointEffect, effect)->get_character() == _character) { + DCAST(CharacterJointEffect, effect)->matches_character(_character)) { node->clear_effect(CharacterJointEffect::get_class_type()); } } diff --git a/panda/src/char/characterJointEffect.I b/panda/src/char/characterJointEffect.I index fb911569b3..e4d596dafe 100644 --- a/panda/src/char/characterJointEffect.I +++ b/panda/src/char/characterJointEffect.I @@ -23,11 +23,17 @@ CharacterJointEffect() { * Returns the Character that will get update() called on it when this node's * relative transform is queried, or NULL if there is no such character. */ -INLINE Character *CharacterJointEffect:: +INLINE PT(Character) CharacterJointEffect:: get_character() const { - if (_character.is_valid_pointer()) { - return _character; - } else { - return NULL; - } + return _character.lock(); +} + +/** + * Returns true if this CharacterJointEffect contains the given Character. + * This exists because it is faster to check than get_character() and can even + * be called while the Character is destructing. + */ +INLINE bool CharacterJointEffect:: +matches_character(Character *character) const { + return _character == character; } diff --git a/panda/src/char/characterJointEffect.cxx b/panda/src/char/characterJointEffect.cxx index 33441e35c2..50b1a878e8 100644 --- a/panda/src/char/characterJointEffect.cxx +++ b/panda/src/char/characterJointEffect.cxx @@ -89,8 +89,9 @@ safe_to_combine() const { void CharacterJointEffect:: output(ostream &out) const { out << get_type(); - if (_character.is_valid_pointer()) { - out << "(" << _character->get_name() << ")"; + PT(Character) character = get_character(); + if (character != nullptr) { + out << "(" << character->get_name() << ")"; } else { out << "(**invalid**)"; } @@ -122,8 +123,8 @@ void CharacterJointEffect:: cull_callback(CullTraverser *trav, CullTraverserData &data, CPT(TransformState) &node_transform, CPT(RenderState) &) const { - if (_character.is_valid_pointer()) { - _character->update(); + if (auto character = _character.lock()) { + character->update(); } node_transform = data.node()->get_transform(); } @@ -150,8 +151,8 @@ void CharacterJointEffect:: adjust_transform(CPT(TransformState) &net_transform, CPT(TransformState) &node_transform, const PandaNode *node) const { - if (_character.is_valid_pointer()) { - _character->update(); + if (auto character = _character.lock()) { + character->update(); } node_transform = node->get_transform(); } @@ -202,11 +203,8 @@ void CharacterJointEffect:: write_datagram(BamWriter *manager, Datagram &dg) { RenderEffect::write_datagram(manager, dg); - if (_character.is_valid_pointer()) { - manager->write_pointer(dg, _character); - } else { - manager->write_pointer(dg, NULL); - } + PT(Character) character = get_character(); + manager->write_pointer(dg, character); } /** diff --git a/panda/src/char/characterJointEffect.h b/panda/src/char/characterJointEffect.h index 0df4cea6fd..372013df54 100644 --- a/panda/src/char/characterJointEffect.h +++ b/panda/src/char/characterJointEffect.h @@ -38,9 +38,11 @@ private: PUBLISHED: static CPT(RenderEffect) make(Character *character); - INLINE Character *get_character() const; + INLINE PT(Character) get_character() const; public: + INLINE bool matches_character(Character *character) const; + virtual bool safe_to_transform() const; virtual bool safe_to_combine() const; virtual void output(ostream &out) const; diff --git a/panda/src/display/displayRegion.I b/panda/src/display/displayRegion.I index 8982461879..a1f55f5e7f 100644 --- a/panda/src/display/displayRegion.I +++ b/panda/src/display/displayRegion.I @@ -479,13 +479,8 @@ INLINE void DisplayRegion:: set_cull_result(PT(CullResult) cull_result, PT(SceneSetup) scene_setup, Thread *current_thread) { CDCullWriter cdata(_cycler_cull, true, current_thread); -#ifdef USE_MOVE_SEMANTICS cdata->_cull_result = move(cull_result); cdata->_scene_setup = move(scene_setup); -#else - swap(cdata->_cull_result, cull_result); - swap(cdata->_scene_setup, scene_setup); -#endif } /** @@ -572,22 +567,6 @@ DisplayRegionPipelineReader(DisplayRegion *object, Thread *current_thread) : #endif // _DEBUG } -/** - * Don't attempt to copy these objects. - */ -INLINE DisplayRegionPipelineReader:: -DisplayRegionPipelineReader(const DisplayRegionPipelineReader &) { - nassertv(false); -} - -/** - * Don't attempt to copy these objects. - */ -INLINE void DisplayRegionPipelineReader:: -operator = (const DisplayRegionPipelineReader &) { - nassertv(false); -} - /** * */ diff --git a/panda/src/display/displayRegion.cxx b/panda/src/display/displayRegion.cxx index 99aea51477..a84a8728e8 100644 --- a/panda/src/display/displayRegion.cxx +++ b/panda/src/display/displayRegion.cxx @@ -46,25 +46,6 @@ DisplayRegion(GraphicsOutput *window, const LVecBase4 &dimensions) : _window->add_display_region(this); } -/** - * - */ -DisplayRegion:: -DisplayRegion(const DisplayRegion ©) : - _window(NULL), - _cull_region_pcollector("Cull:Invalid"), - _draw_region_pcollector("Draw:Invalid") -{ -} - -/** - * - */ -void DisplayRegion:: -operator = (const DisplayRegion&) { - nassertv(false); -} - /** * */ diff --git a/panda/src/display/displayRegion.h b/panda/src/display/displayRegion.h index 091f17e13f..7599f17c9d 100644 --- a/panda/src/display/displayRegion.h +++ b/panda/src/display/displayRegion.h @@ -57,10 +57,8 @@ class CullTraverser; class EXPCL_PANDA_DISPLAY DisplayRegion : public TypedReferenceCount, public DrawableRegion { protected: DisplayRegion(GraphicsOutput *window, const LVecBase4 &dimensions); - -private: - DisplayRegion(const DisplayRegion ©); - void operator = (const DisplayRegion ©); + DisplayRegion(const DisplayRegion ©) = delete; + void operator = (const DisplayRegion ©) = delete; public: virtual ~DisplayRegion(); @@ -310,9 +308,8 @@ private: class EXPCL_PANDA_DISPLAY DisplayRegionPipelineReader { public: INLINE DisplayRegionPipelineReader(DisplayRegion *object, Thread *current_thread); -private: - INLINE DisplayRegionPipelineReader(const DisplayRegionPipelineReader ©); - INLINE void operator = (const DisplayRegionPipelineReader ©); + DisplayRegionPipelineReader(const DisplayRegionPipelineReader ©) = delete; + void operator = (const DisplayRegionPipelineReader ©) = delete; public: INLINE ~DisplayRegionPipelineReader(); diff --git a/panda/src/display/graphicsDevice.cxx b/panda/src/display/graphicsDevice.cxx index fb74bca7d8..665e12534e 100644 --- a/panda/src/display/graphicsDevice.cxx +++ b/panda/src/display/graphicsDevice.cxx @@ -34,22 +34,6 @@ GraphicsDevice(GraphicsPipe *pipe) { } } -/** - * - */ -GraphicsDevice:: -GraphicsDevice(const GraphicsDevice &) { - nassertv(false); -} - -/** - * - */ -void GraphicsDevice:: -operator = (const GraphicsDevice &) { - nassertv(false); -} - /** * */ diff --git a/panda/src/display/graphicsDevice.h b/panda/src/display/graphicsDevice.h index afb1edb697..532024642a 100644 --- a/panda/src/display/graphicsDevice.h +++ b/panda/src/display/graphicsDevice.h @@ -30,10 +30,8 @@ class GraphicsPipe; class EXPCL_PANDA_DISPLAY GraphicsDevice : public TypedReferenceCount { public: GraphicsDevice(GraphicsPipe *pipe); - -private: - GraphicsDevice(const GraphicsDevice ©); - void operator = (const GraphicsDevice ©); + GraphicsDevice(const GraphicsDevice ©) = delete; + GraphicsDevice &operator = (const GraphicsDevice ©) = delete; PUBLISHED: virtual ~GraphicsDevice(); diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index f65c5377fc..b3f931e44b 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/panda/src/display/graphicsEngine.cxx @@ -1538,7 +1538,7 @@ cull_to_bins(GraphicsEngine::Windows wlist, Thread *current_thread) { } // Save the results for next frame. - dr->set_cull_result(MOVE(cull_result), MOVE(scene_setup), current_thread); + dr->set_cull_result(move(cull_result), MOVE(scene_setup), current_thread); } } } diff --git a/panda/src/display/graphicsOutput.cxx b/panda/src/display/graphicsOutput.cxx index 4d8a1e27a1..cb2f69ff6c 100644 --- a/panda/src/display/graphicsOutput.cxx +++ b/panda/src/display/graphicsOutput.cxx @@ -159,25 +159,6 @@ GraphicsOutput(GraphicsEngine *engine, GraphicsPipe *pipe, set_clear_color(background_color.get_value()); } -/** - * - */ -GraphicsOutput:: -GraphicsOutput(const GraphicsOutput &) : - _cull_window_pcollector(_cull_pcollector, "Invalid"), - _draw_window_pcollector(_draw_pcollector, "Invalid") -{ - nassertv(false); -} - -/** - * - */ -void GraphicsOutput:: -operator = (const GraphicsOutput &) { - nassertv(false); -} - /** * */ diff --git a/panda/src/display/graphicsOutput.h b/panda/src/display/graphicsOutput.h index 2f9eff8683..93db287a74 100644 --- a/panda/src/display/graphicsOutput.h +++ b/panda/src/display/graphicsOutput.h @@ -70,10 +70,8 @@ protected: GraphicsStateGuardian *gsg, GraphicsOutput *host, bool default_stereo_flags); - -private: - GraphicsOutput(const GraphicsOutput ©); - void operator = (const GraphicsOutput ©); + GraphicsOutput(const GraphicsOutput ©) = delete; + GraphicsOutput &operator = (const GraphicsOutput ©) = delete; PUBLISHED: enum RenderTextureMode { diff --git a/panda/src/display/graphicsPipe.h b/panda/src/display/graphicsPipe.h index f7994b92e1..501cc535be 100644 --- a/panda/src/display/graphicsPipe.h +++ b/panda/src/display/graphicsPipe.h @@ -52,9 +52,8 @@ class DisplayInformation; class EXPCL_PANDA_DISPLAY GraphicsPipe : public TypedReferenceCount { protected: GraphicsPipe(); -private: - GraphicsPipe(const GraphicsPipe ©) DELETED; - GraphicsPipe &operator = (const GraphicsPipe ©) DELETED_ASSIGN; + GraphicsPipe(const GraphicsPipe ©) = delete; + GraphicsPipe &operator = (const GraphicsPipe ©) = delete; PUBLISHED: virtual ~GraphicsPipe(); diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index e508be9c6a..fecce7e56a 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -286,7 +286,7 @@ PUBLISHED: MAKE_PROPERTY(driver_shader_version_minor, get_driver_shader_version_minor); bool set_scene(SceneSetup *scene_setup); - virtual SceneSetup *get_scene() const FINAL; + virtual SceneSetup *get_scene() const final; MAKE_PROPERTY(scene, get_scene, set_scene); public: diff --git a/panda/src/downloader/multiplexStreamBuf.cxx b/panda/src/downloader/multiplexStreamBuf.cxx index 96d4a22755..783558f587 100644 --- a/panda/src/downloader/multiplexStreamBuf.cxx +++ b/panda/src/downloader/multiplexStreamBuf.cxx @@ -122,9 +122,9 @@ add_output(MultiplexStreamBuf::BufferType buffer_type, o._owns_obj = owns_obj; // Ensure that we have the mutex while we fiddle with the list of outputs. - _lock.acquire(); + _lock.lock(); _outputs.push_back(o); - _lock.release(); + _lock.unlock(); } @@ -133,9 +133,9 @@ add_output(MultiplexStreamBuf::BufferType buffer_type, */ void MultiplexStreamBuf:: flush() { - _lock.acquire(); + _lock.lock(); write_chars("", 0, true); - _lock.release(); + _lock.unlock(); } /** @@ -144,7 +144,7 @@ flush() { */ int MultiplexStreamBuf:: overflow(int ch) { - _lock.acquire(); + _lock.lock(); streamsize n = pptr() - pbase(); @@ -159,7 +159,7 @@ overflow(int ch) { write_chars(&c, 1, false); } - _lock.release(); + _lock.unlock(); return 0; } @@ -169,7 +169,7 @@ overflow(int ch) { */ int MultiplexStreamBuf:: sync() { - _lock.acquire(); + _lock.lock(); streamsize n = pptr() - pbase(); @@ -181,7 +181,7 @@ sync() { write_chars(pbase(), n, false); pbump(-n); - _lock.release(); + _lock.unlock(); return 0; // Return 0 for success, EOF to indicate write full. } diff --git a/panda/src/downloader/virtualFileMountHTTP.cxx b/panda/src/downloader/virtualFileMountHTTP.cxx index 78b06a2f44..9ad783da87 100644 --- a/panda/src/downloader/virtualFileMountHTTP.cxx +++ b/panda/src/downloader/virtualFileMountHTTP.cxx @@ -238,7 +238,7 @@ output(ostream &out) const { PT(HTTPChannel) VirtualFileMountHTTP:: get_channel() { PT(HTTPChannel) channel; - _channels_lock.acquire(); + _channels_lock.lock(); if (!_channels.empty()) { // If we have some channels sitting around, grab one. Grab the one on the @@ -251,7 +251,7 @@ get_channel() { channel = _http->make_channel(true); } - _channels_lock.release(); + _channels_lock.unlock(); return channel; } @@ -262,9 +262,9 @@ get_channel() { */ void VirtualFileMountHTTP:: recycle_channel(HTTPChannel *channel) { - _channels_lock.acquire(); + _channels_lock.lock(); _channels.push_back(channel); - _channels_lock.release(); + _channels_lock.unlock(); } #endif // HAVE_OPENSSL diff --git a/panda/src/dxgsg9/dxGeomMunger9.I b/panda/src/dxgsg9/dxGeomMunger9.I index eee877c668..223e6478cb 100644 --- a/panda/src/dxgsg9/dxGeomMunger9.I +++ b/panda/src/dxgsg9/dxGeomMunger9.I @@ -31,6 +31,6 @@ DXGeomMunger9(GraphicsStateGuardian *gsg, const RenderState *state) : } // Set a callback to unregister ourselves when either the Texture or the // TexGen object gets deleted. - _texture.set_callback(this); - _tex_gen.set_callback(this); + _texture.add_callback(this); + _tex_gen.add_callback(this); } diff --git a/panda/src/dxgsg9/dxGeomMunger9.cxx b/panda/src/dxgsg9/dxGeomMunger9.cxx index 44729ae0cd..e9b9ba498e 100644 --- a/panda/src/dxgsg9/dxGeomMunger9.cxx +++ b/panda/src/dxgsg9/dxGeomMunger9.cxx @@ -28,6 +28,9 @@ DXGeomMunger9:: unref_delete(_filtered_texture); _reffed_filtered_texture = false; } + + _texture.remove_callback(this); + _tex_gen.remove_callback(this); } /** diff --git a/panda/src/event/asyncFuture.cxx b/panda/src/event/asyncFuture.cxx index 25ae6bfa1c..d97173d54d 100644 --- a/panda/src/event/asyncFuture.cxx +++ b/panda/src/event/asyncFuture.cxx @@ -273,9 +273,9 @@ wake_task(AsyncTask *task) { } { - manager->_lock.release(); + manager->_lock.unlock(); task->upon_birth(manager); - manager->_lock.acquire(); + manager->_lock.lock(); nassertv(task->_manager == nullptr && task->_state == AsyncTask::S_inactive); diff --git a/panda/src/event/asyncFuture.h b/panda/src/event/asyncFuture.h index cbed94b158..18d5b773f1 100644 --- a/panda/src/event/asyncFuture.h +++ b/panda/src/event/asyncFuture.h @@ -160,7 +160,7 @@ INLINE ostream &operator << (ostream &out, const AsyncFuture &fut) { /** * Specific future that collects the results of several futures. */ -class EXPCL_PANDA_EVENT AsyncGatheringFuture FINAL : public AsyncFuture { +class EXPCL_PANDA_EVENT AsyncGatheringFuture final : public AsyncFuture { private: AsyncGatheringFuture(AsyncFuture::Futures futures); diff --git a/panda/src/event/asyncTask.cxx b/panda/src/event/asyncTask.cxx index 9f70f0e5ad..95b4e5aad1 100644 --- a/panda/src/event/asyncTask.cxx +++ b/panda/src/event/asyncTask.cxx @@ -415,7 +415,7 @@ unlock_and_do_task() { #endif // __GNUC__ // It's important to release the lock while the task is being serviced. - _manager->_lock.release(); + _manager->_lock.unlock(); double start = clock->get_real_time(); _task_pcollector.start(); @@ -424,7 +424,7 @@ unlock_and_do_task() { double end = clock->get_real_time(); // Now reacquire the lock (so we can return with the lock held). - _manager->_lock.acquire(); + _manager->_lock.lock(); _dt = end - start; _max_dt = max(_dt, _max_dt); diff --git a/panda/src/event/asyncTask.h b/panda/src/event/asyncTask.h index 9712daa0f5..e36c3c8324 100644 --- a/panda/src/event/asyncTask.h +++ b/panda/src/event/asyncTask.h @@ -103,8 +103,8 @@ protected: void jump_to_task_chain(AsyncTaskManager *manager); DoneStatus unlock_and_do_task(); - virtual bool cancel() FINAL; - virtual bool is_task() const FINAL {return true;} + virtual bool cancel() final; + virtual bool is_task() const final {return true;} virtual bool is_runnable(); virtual DoneStatus do_task(); diff --git a/panda/src/event/asyncTaskChain.cxx b/panda/src/event/asyncTaskChain.cxx index bb82e00f92..1d131d62df 100644 --- a/panda/src/event/asyncTaskChain.cxx +++ b/panda/src/event/asyncTaskChain.cxx @@ -596,11 +596,11 @@ do_cleanup() { nassertv(_num_tasks == 0 || _num_tasks == 1); // Now go back and call the upon_death functions. - _manager->_lock.release(); + _manager->_lock.unlock(); for (ti = dead.begin(); ti != dead.end(); ++ti) { (*ti)->upon_death(_manager, false); } - _manager->_lock.acquire(); + _manager->_lock.lock(); if (task_cat.is_spam()) { do_output(task_cat.spam()); @@ -791,9 +791,9 @@ cleanup_task(AsyncTask *task, bool upon_death, bool clean_exit) { task->_manager = nullptr; if (upon_death) { - _manager->_lock.release(); + _manager->_lock.unlock(); task->upon_death(_manager, clean_exit); - _manager->_lock.acquire(); + _manager->_lock.lock(); } } @@ -1031,7 +1031,7 @@ do_stop_threads() { // We have to release the lock while we join, so the threads can wake up // and see that we're shutting down. - _manager->_lock.release(); + _manager->_lock.unlock(); Threads::iterator ti; for (ti = wait_threads.begin(); ti != wait_threads.end(); ++ti) { if (task_cat.is_debug()) { @@ -1046,7 +1046,7 @@ do_stop_threads() { << *Thread::get_current_thread() << "\n"; } } - _manager->_lock.acquire(); + _manager->_lock.lock(); _state = S_initial; diff --git a/panda/src/event/asyncTaskManager.cxx b/panda/src/event/asyncTaskManager.cxx index 5e1bf9601c..c19c194e60 100644 --- a/panda/src/event/asyncTaskManager.cxx +++ b/panda/src/event/asyncTaskManager.cxx @@ -200,9 +200,9 @@ add(AsyncTask *task) { task->_state == AsyncTask::S_inactive); nassertv(!do_has_task(task)); - _lock.release(); + _lock.unlock(); task->upon_birth(this); - _lock.acquire(); + _lock.lock(); nassertv(task->_manager == NULL && task->_state == AsyncTask::S_inactive); nassertv(!do_has_task(task)); diff --git a/panda/src/event/eventParameter.h b/panda/src/event/eventParameter.h index 65dbf550c8..24ea3ec1e2 100644 --- a/panda/src/event/eventParameter.h +++ b/panda/src/event/eventParameter.h @@ -34,7 +34,7 @@ */ class EXPCL_PANDA_EVENT EventParameter { PUBLISHED: - INLINE EventParameter() DEFAULT_CTOR; + INLINE EventParameter() = default; INLINE EventParameter(nullptr_t) {}; INLINE EventParameter(const TypedWritableReferenceCount *ptr); INLINE EventParameter(const TypedReferenceCount *ptr); diff --git a/panda/src/event/pythonTask.h b/panda/src/event/pythonTask.h index 48826769de..33dde9af0a 100644 --- a/panda/src/event/pythonTask.h +++ b/panda/src/event/pythonTask.h @@ -26,7 +26,7 @@ * This class exists to allow association of a Python function or coroutine * with the AsyncTaskManager. */ -class PythonTask FINAL : public AsyncTask { +class PythonTask final : public AsyncTask { PUBLISHED: PythonTask(PyObject *function = Py_None, const string &name = string()); virtual ~PythonTask(); diff --git a/panda/src/express/datagram.h b/panda/src/express/datagram.h index 00a46ef36f..7cf50368fc 100644 --- a/panda/src/express/datagram.h +++ b/panda/src/express/datagram.h @@ -40,9 +40,13 @@ PUBLISHED: INLINE Datagram(); INLINE Datagram(const void *data, size_t size); INLINE explicit Datagram(vector_uchar data); - + Datagram(const Datagram ©) = default; + Datagram(Datagram &&from) noexcept = default; virtual ~Datagram(); + Datagram &operator = (const Datagram ©) = default; + Datagram &operator = (Datagram &&from) noexcept = default; + virtual void clear(); void dump_hex(ostream &out, unsigned int indent=0) const; diff --git a/panda/src/express/multifile.cxx b/panda/src/express/multifile.cxx index 5a7d86f17b..0bedba8909 100644 --- a/panda/src/express/multifile.cxx +++ b/panda/src/express/multifile.cxx @@ -136,25 +136,6 @@ Multifile:: close(); } -/** - * Don't try to copy Multifiles. - */ -Multifile:: -Multifile(const Multifile ©) : - _read_filew(_read_file), - _read_write_filew(_read_write_file) -{ - nassertv(false); -} - -/** - * Don't try to copy Multifiles. - */ -void Multifile:: -operator = (const Multifile ©) { - nassertv(false); -} - /** * Opens the named Multifile on disk for reading. The Multifile index is read * in, and the list of subfiles becomes available; individual subfiles may diff --git a/panda/src/express/multifile.h b/panda/src/express/multifile.h index d9f7217dfd..ad0296055c 100644 --- a/panda/src/express/multifile.h +++ b/panda/src/express/multifile.h @@ -37,11 +37,10 @@ typedef struct evp_pkey_st EVP_PKEY; class EXPCL_PANDAEXPRESS Multifile : public ReferenceCount { PUBLISHED: Multifile(); + Multifile(const Multifile ©) = delete; ~Multifile(); -private: - Multifile(const Multifile ©); - void operator = (const Multifile ©); + Multifile &operator = (const Multifile ©) = delete; PUBLISHED: BLOCKING bool open_read(const Filename &multifile_name, const streampos &offset = 0); diff --git a/panda/src/express/nodePointerTo.I b/panda/src/express/nodePointerTo.I index 5485adcaaa..c035cd34cf 100644 --- a/panda/src/express/nodePointerTo.I +++ b/panda/src/express/nodePointerTo.I @@ -33,14 +33,13 @@ NodePointerTo(const NodePointerTo ©) : } #endif // CPPPARSER -#ifdef USE_MOVE_SEMANTICS #ifndef CPPPARSER /** * */ template INLINE NodePointerTo:: -NodePointerTo(NodePointerTo &&from) NOEXCEPT : +NodePointerTo(NodePointerTo &&from) noexcept : NodePointerToBase((NodePointerToBase &&)from) { } @@ -52,12 +51,11 @@ NodePointerTo(NodePointerTo &&from) NOEXCEPT : */ template INLINE NodePointerTo &NodePointerTo:: -operator = (NodePointerTo &&from) NOEXCEPT { +operator = (NodePointerTo &&from) noexcept { this->reassign(move(from)); return *this; } #endif // CPPPARSER -#endif // USE_MOVE_SEMANTICS #ifndef CPPPARSER /** @@ -167,14 +165,13 @@ NodeConstPointerTo(const NodeConstPointerTo ©) : } #endif // CPPPARSER -#ifdef USE_MOVE_SEMANTICS #ifndef CPPPARSER /** * */ template INLINE NodeConstPointerTo:: -NodeConstPointerTo(NodePointerTo &&from) NOEXCEPT : +NodeConstPointerTo(NodePointerTo &&from) noexcept : NodePointerToBase((NodePointerToBase &&)from) { } @@ -186,7 +183,7 @@ NodeConstPointerTo(NodePointerTo &&from) NOEXCEPT : */ template INLINE NodeConstPointerTo:: -NodeConstPointerTo(NodeConstPointerTo &&from) NOEXCEPT : +NodeConstPointerTo(NodeConstPointerTo &&from) noexcept : NodePointerToBase((NodePointerToBase &&)from) { } @@ -198,7 +195,7 @@ NodeConstPointerTo(NodeConstPointerTo &&from) NOEXCEPT : */ template INLINE NodeConstPointerTo &NodeConstPointerTo:: -operator = (NodePointerTo &&from) NOEXCEPT { +operator = (NodePointerTo &&from) noexcept { this->reassign(move(from)); return *this; } @@ -210,12 +207,11 @@ operator = (NodePointerTo &&from) NOEXCEPT { */ template INLINE NodeConstPointerTo &NodeConstPointerTo:: -operator = (NodeConstPointerTo &&from) NOEXCEPT { +operator = (NodeConstPointerTo &&from) noexcept { this->reassign(move(from)); return *this; } #endif // CPPPARSER -#endif // USE_MOVE_SEMANTICS #ifndef CPPPARSER /** diff --git a/panda/src/express/nodePointerTo.h b/panda/src/express/nodePointerTo.h index ca9832d424..169aeb71e5 100644 --- a/panda/src/express/nodePointerTo.h +++ b/panda/src/express/nodePointerTo.h @@ -31,11 +31,9 @@ public: typedef TYPENAME NodePointerToBase::To To; INLINE NodePointerTo(To *ptr = (To *)NULL); INLINE NodePointerTo(const NodePointerTo ©); + INLINE NodePointerTo(NodePointerTo &&from) noexcept; -#ifdef USE_MOVE_SEMANTICS - INLINE NodePointerTo(NodePointerTo &&from) NOEXCEPT; - INLINE NodePointerTo &operator = (NodePointerTo &&from) NOEXCEPT; -#endif + INLINE NodePointerTo &operator = (NodePointerTo &&from) noexcept; INLINE To &operator *() const; INLINE To *operator -> () const; @@ -65,13 +63,11 @@ public: INLINE NodeConstPointerTo(const To *ptr = (const To *)NULL); INLINE NodeConstPointerTo(const NodePointerTo ©); INLINE NodeConstPointerTo(const NodeConstPointerTo ©); + INLINE NodeConstPointerTo(NodePointerTo &&from) noexcept; + INLINE NodeConstPointerTo(NodeConstPointerTo &&from) noexcept; -#ifdef USE_MOVE_SEMANTICS - INLINE NodeConstPointerTo(NodePointerTo &&from) NOEXCEPT; - INLINE NodeConstPointerTo(NodeConstPointerTo &&from) NOEXCEPT; - INLINE NodeConstPointerTo &operator = (NodePointerTo &&from) NOEXCEPT; - INLINE NodeConstPointerTo &operator = (NodeConstPointerTo &&from) NOEXCEPT; -#endif + INLINE NodeConstPointerTo &operator = (NodePointerTo &&from) noexcept; + INLINE NodeConstPointerTo &operator = (NodeConstPointerTo &&from) noexcept; INLINE const To &operator *() const; INLINE const To *operator -> () const; @@ -86,12 +82,12 @@ public: }; template -void swap(NodePointerTo &one, NodePointerTo &two) NOEXCEPT { +void swap(NodePointerTo &one, NodePointerTo &two) noexcept { one.swap(two); } template -void swap(NodeConstPointerTo &one, NodeConstPointerTo &two) NOEXCEPT { +void swap(NodeConstPointerTo &one, NodeConstPointerTo &two) noexcept { one.swap(two); } diff --git a/panda/src/express/nodePointerToBase.I b/panda/src/express/nodePointerToBase.I index 18f04def9a..1cb22132d5 100644 --- a/panda/src/express/nodePointerToBase.I +++ b/panda/src/express/nodePointerToBase.I @@ -38,13 +38,12 @@ INLINE NodePointerToBase:: reassign((To *)NULL); } -#ifdef USE_MOVE_SEMANTICS /** * */ template INLINE NodePointerToBase:: -NodePointerToBase(NodePointerToBase &&from) NOEXCEPT { +NodePointerToBase(NodePointerToBase &&from) noexcept { _void_ptr = from._void_ptr; from._void_ptr = (void *)NULL; } @@ -57,7 +56,7 @@ NodePointerToBase(NodePointerToBase &&from) NOEXCEPT { */ template INLINE void NodePointerToBase:: -reassign(NodePointerToBase &&from) NOEXCEPT { +reassign(NodePointerToBase &&from) noexcept { To *old_ptr = (To *)this->_void_ptr; this->_void_ptr = from._void_ptr; @@ -68,7 +67,6 @@ reassign(NodePointerToBase &&from) NOEXCEPT { node_unref_delete(old_ptr); } } -#endif // USE_MOVE_SEMANTICS /** * This is the main work of the NodePointerTo family. When the pointer is diff --git a/panda/src/express/nodePointerToBase.h b/panda/src/express/nodePointerToBase.h index e7bb9ad526..0b28a5c6bc 100644 --- a/panda/src/express/nodePointerToBase.h +++ b/panda/src/express/nodePointerToBase.h @@ -36,11 +36,9 @@ protected: INLINE NodePointerToBase(To *ptr); INLINE NodePointerToBase(const NodePointerToBase ©); INLINE ~NodePointerToBase(); + INLINE NodePointerToBase(NodePointerToBase &&from) noexcept; -#ifdef USE_MOVE_SEMANTICS - INLINE NodePointerToBase(NodePointerToBase &&from) NOEXCEPT; - INLINE void reassign(NodePointerToBase &&from) NOEXCEPT; -#endif + INLINE void reassign(NodePointerToBase &&from) noexcept; void reassign(To *ptr); INLINE void reassign(const NodePointerToBase ©); diff --git a/panda/src/express/pointerTo.I b/panda/src/express/pointerTo.I index 62962a83e3..bc71cfbfd9 100644 --- a/panda/src/express/pointerTo.I +++ b/panda/src/express/pointerTo.I @@ -16,7 +16,7 @@ */ template ALWAYS_INLINE PointerTo:: -PointerTo(To *ptr) NOEXCEPT : PointerToBase(ptr) { +PointerTo(To *ptr) noexcept : PointerToBase(ptr) { } /** @@ -29,13 +29,12 @@ PointerTo(const PointerTo ©) : { } -#ifdef USE_MOVE_SEMANTICS /** * */ template INLINE PointerTo:: -PointerTo(PointerTo &&from) NOEXCEPT : +PointerTo(PointerTo &&from) noexcept : PointerToBase(move(from)) { } @@ -45,18 +44,17 @@ PointerTo(PointerTo &&from) NOEXCEPT : */ template INLINE PointerTo &PointerTo:: -operator = (PointerTo &&from) NOEXCEPT { +operator = (PointerTo &&from) noexcept { this->reassign(move(from)); return *this; } -#endif // USE_MOVE_SEMANTICS /** * */ template -CONSTEXPR TYPENAME PointerTo::To &PointerTo:: -operator *() const NOEXCEPT { +constexpr TYPENAME PointerTo::To &PointerTo:: +operator *() const noexcept { return *((To *)(this->_void_ptr)); } @@ -64,8 +62,8 @@ operator *() const NOEXCEPT { * */ template -CONSTEXPR TYPENAME PointerTo::To *PointerTo:: -operator -> () const NOEXCEPT { +constexpr TYPENAME PointerTo::To *PointerTo:: +operator -> () const noexcept { return (To *)(this->_void_ptr); } @@ -76,8 +74,8 @@ operator -> () const NOEXCEPT { * goes because either will be correct. */ template -CONSTEXPR PointerTo:: -operator T * () const NOEXCEPT { +constexpr PointerTo:: +operator T * () const noexcept { return (To *)(this->_void_ptr); } @@ -99,8 +97,8 @@ cheat() { * compiler problems, particularly for implicit upcasts. */ template -CONSTEXPR TYPENAME PointerTo::To *PointerTo:: -p() const NOEXCEPT { +constexpr TYPENAME PointerTo::To *PointerTo:: +p() const noexcept { return (To *)(this->_void_ptr); } @@ -129,7 +127,7 @@ operator = (const PointerTo ©) { */ template ALWAYS_INLINE ConstPointerTo:: -ConstPointerTo(const TYPENAME ConstPointerTo::To *ptr) NOEXCEPT : +ConstPointerTo(const TYPENAME ConstPointerTo::To *ptr) noexcept : PointerToBase((TYPENAME ConstPointerTo::To *)ptr) { } @@ -154,13 +152,12 @@ ConstPointerTo(const ConstPointerTo ©) : { } -#ifdef USE_MOVE_SEMANTICS /** * */ template INLINE ConstPointerTo:: -ConstPointerTo(PointerTo &&from) NOEXCEPT : +ConstPointerTo(PointerTo &&from) noexcept : PointerToBase(move(from)) { } @@ -170,7 +167,7 @@ ConstPointerTo(PointerTo &&from) NOEXCEPT : */ template INLINE ConstPointerTo:: -ConstPointerTo(ConstPointerTo &&from) NOEXCEPT : +ConstPointerTo(ConstPointerTo &&from) noexcept : PointerToBase(move(from)) { } @@ -180,7 +177,7 @@ ConstPointerTo(ConstPointerTo &&from) NOEXCEPT : */ template INLINE ConstPointerTo &ConstPointerTo:: -operator = (PointerTo &&from) NOEXCEPT { +operator = (PointerTo &&from) noexcept { this->reassign(move(from)); return *this; } @@ -190,18 +187,17 @@ operator = (PointerTo &&from) NOEXCEPT { */ template INLINE ConstPointerTo &ConstPointerTo:: -operator = (ConstPointerTo &&from) NOEXCEPT { +operator = (ConstPointerTo &&from) noexcept { this->reassign(move(from)); return *this; } -#endif // USE_MOVE_SEMANTICS /** * */ template -CONSTEXPR const TYPENAME ConstPointerTo::To &ConstPointerTo:: -operator *() const NOEXCEPT { +constexpr const TYPENAME ConstPointerTo::To &ConstPointerTo:: +operator *() const noexcept { return *((To *)(this->_void_ptr)); } @@ -209,8 +205,8 @@ operator *() const NOEXCEPT { * */ template -CONSTEXPR const TYPENAME ConstPointerTo::To *ConstPointerTo:: -operator -> () const NOEXCEPT { +constexpr const TYPENAME ConstPointerTo::To *ConstPointerTo:: +operator -> () const noexcept { return (To *)(this->_void_ptr); } @@ -221,8 +217,8 @@ operator -> () const NOEXCEPT { * don't care which way it goes because either will be correct. */ template -CONSTEXPR ConstPointerTo:: -operator const T * () const NOEXCEPT { +constexpr ConstPointerTo:: +operator const T * () const noexcept { return (To *)(this->_void_ptr); } @@ -244,8 +240,8 @@ cheat() { * around compiler problems, particularly for implicit upcasts. */ template -CONSTEXPR const TYPENAME ConstPointerTo::To *ConstPointerTo:: -p() const NOEXCEPT { +constexpr const TYPENAME ConstPointerTo::To *ConstPointerTo:: +p() const noexcept { return (To *)(this->_void_ptr); } diff --git a/panda/src/express/pointerTo.h b/panda/src/express/pointerTo.h index 62abdf8e57..313ad41a55 100644 --- a/panda/src/express/pointerTo.h +++ b/panda/src/express/pointerTo.h @@ -70,20 +70,18 @@ class PointerTo : public PointerToBase { public: typedef TYPENAME PointerToBase::To To; PUBLISHED: - ALWAYS_INLINE_CONSTEXPR PointerTo() NOEXCEPT DEFAULT_CTOR; - ALWAYS_INLINE PointerTo(To *ptr) NOEXCEPT; + ALWAYS_INLINE constexpr PointerTo() noexcept = default; + ALWAYS_INLINE PointerTo(To *ptr) noexcept; INLINE PointerTo(const PointerTo ©); public: -#ifdef USE_MOVE_SEMANTICS - INLINE PointerTo(PointerTo &&from) NOEXCEPT; - INLINE PointerTo &operator = (PointerTo &&from) NOEXCEPT; -#endif + INLINE PointerTo(PointerTo &&from) noexcept; + INLINE PointerTo &operator = (PointerTo &&from) noexcept; - CONSTEXPR To &operator *() const NOEXCEPT; - CONSTEXPR To *operator -> () const NOEXCEPT; + constexpr To &operator *() const noexcept; + constexpr To *operator -> () const noexcept; // MSVC.NET 2005 insists that we use T *, and not To *, here. - CONSTEXPR operator T *() const NOEXCEPT; + constexpr operator T *() const noexcept; INLINE T *&cheat(); @@ -100,7 +98,7 @@ PUBLISHED: // the DCAST macro defined in typedObject.h instead, e.g. DCAST(MyType, // ptr). This provides a clean downcast that doesn't require .p() or any // double-casting, and it can be run-time checked for correctness. - CONSTEXPR To *p() const NOEXCEPT; + constexpr To *p() const noexcept; INLINE PointerTo &operator = (To *ptr); INLINE PointerTo &operator = (const PointerTo ©); @@ -133,27 +131,25 @@ class ConstPointerTo : public PointerToBase { public: typedef TYPENAME PointerToBase::To To; PUBLISHED: - ALWAYS_INLINE_CONSTEXPR ConstPointerTo() NOEXCEPT DEFAULT_CTOR; - ALWAYS_INLINE ConstPointerTo(const To *ptr) NOEXCEPT; + ALWAYS_INLINE constexpr ConstPointerTo() noexcept = default; + ALWAYS_INLINE ConstPointerTo(const To *ptr) noexcept; INLINE ConstPointerTo(const PointerTo ©); INLINE ConstPointerTo(const ConstPointerTo ©); public: -#ifdef USE_MOVE_SEMANTICS - INLINE ConstPointerTo(PointerTo &&from) NOEXCEPT; - INLINE ConstPointerTo(ConstPointerTo &&from) NOEXCEPT; - INLINE ConstPointerTo &operator = (PointerTo &&from) NOEXCEPT; - INLINE ConstPointerTo &operator = (ConstPointerTo &&from) NOEXCEPT; -#endif + INLINE ConstPointerTo(PointerTo &&from) noexcept; + INLINE ConstPointerTo(ConstPointerTo &&from) noexcept; + INLINE ConstPointerTo &operator = (PointerTo &&from) noexcept; + INLINE ConstPointerTo &operator = (ConstPointerTo &&from) noexcept; - CONSTEXPR const To &operator *() const NOEXCEPT; - CONSTEXPR const To *operator -> () const NOEXCEPT; - CONSTEXPR operator const T *() const NOEXCEPT; + constexpr const To &operator *() const noexcept; + constexpr const To *operator -> () const noexcept; + constexpr operator const T *() const noexcept; INLINE const T *&cheat(); PUBLISHED: - CONSTEXPR const To *p() const NOEXCEPT; + constexpr const To *p() const noexcept; INLINE ConstPointerTo &operator = (const To *ptr); INLINE ConstPointerTo &operator = (const PointerTo ©); @@ -173,12 +169,12 @@ PUBLISHED: // PointerTo objects without incurring the cost of unnecessary reference count // changes. The performance difference is dramatic! template -void swap(PointerTo &one, PointerTo &two) NOEXCEPT { +void swap(PointerTo &one, PointerTo &two) noexcept { one.swap(two); } template -void swap(ConstPointerTo &one, ConstPointerTo &two) NOEXCEPT { +void swap(ConstPointerTo &one, ConstPointerTo &two) noexcept { one.swap(two); } diff --git a/panda/src/express/pointerToArray.I b/panda/src/express/pointerToArray.I index 535de63d01..f665e38415 100644 --- a/panda/src/express/pointerToArray.I +++ b/panda/src/express/pointerToArray.I @@ -79,20 +79,17 @@ PointerToArray(const Element *begin, const Element *end, TypeHandle type_handle) { } -#ifdef USE_MOVE_SEMANTICS /** * */ template INLINE PointerToArray:: -PointerToArray(PointerToArray &&from) NOEXCEPT : +PointerToArray(PointerToArray &&from) noexcept : PointerToArrayBase(move(from)), _type_handle(from._type_handle) { } -#endif // USE_MOVE_SEMANTICS -#ifdef USE_MOVE_SEMANTICS /** * Initializes the PTA from a vector. */ @@ -103,7 +100,6 @@ PointerToArray(pvector &&from, TypeHandle type_handle) : _type_handle(type_handle) { } -#endif // USE_MOVE_SEMANTICS /** * @@ -628,18 +624,16 @@ operator = (const PointerToArray ©) { return *this; } -#ifdef USE_MOVE_SEMANTICS /** * */ template INLINE PointerToArray &PointerToArray:: -operator = (PointerToArray &&from) NOEXCEPT { +operator = (PointerToArray &&from) noexcept { _type_handle = from._type_handle; ((PointerToArray *)this)->reassign(move(from)); return *this; } -#endif // USE_MOVE_SEMANTICS /** * To empty the PTA, use the clear() method, since assignment to NULL is @@ -697,33 +691,28 @@ ConstPointerToArray(const ConstPointerToArray ©) : { } -#ifdef USE_MOVE_SEMANTICS /** * */ template INLINE ConstPointerToArray:: -ConstPointerToArray(PointerToArray &&from) NOEXCEPT : +ConstPointerToArray(PointerToArray &&from) noexcept : PointerToArrayBase(move(from)), _type_handle(from._type_handle) { } -#endif // USE_MOVE_SEMANTICS -#ifdef USE_MOVE_SEMANTICS /** * */ template INLINE ConstPointerToArray:: -ConstPointerToArray(ConstPointerToArray &&from) NOEXCEPT : +ConstPointerToArray(ConstPointerToArray &&from) noexcept : PointerToArrayBase(move(from)), _type_handle(from._type_handle) { } -#endif // USE_MOVE_SEMANTICS -#ifdef USE_MOVE_SEMANTICS /** * Initializes the PTA from a vector. */ @@ -734,7 +723,6 @@ ConstPointerToArray(pvector &&from, TypeHandle type_handle) : _type_handle(type_handle) { } -#endif // USE_MOVE_SEMANTICS /** * @@ -1090,31 +1078,27 @@ operator = (const ConstPointerToArray ©) { return *this; } -#ifdef USE_MOVE_SEMANTICS /** * */ template INLINE ConstPointerToArray &ConstPointerToArray:: -operator = (PointerToArray &&from) NOEXCEPT { +operator = (PointerToArray &&from) noexcept { _type_handle = from._type_handle; ((ConstPointerToArray *)this)->reassign(move(from)); return *this; } -#endif // USE_MOVE_SEMANTICS -#ifdef USE_MOVE_SEMANTICS /** * */ template INLINE ConstPointerToArray &ConstPointerToArray:: -operator = (ConstPointerToArray &&from) NOEXCEPT { +operator = (ConstPointerToArray &&from) noexcept { _type_handle = from._type_handle; ((ConstPointerToArray *)this)->reassign(move(from)); return *this; } -#endif // USE_MOVE_SEMANTICS /** * To empty the PTA, use the clear() method, since assignment to NULL is diff --git a/panda/src/express/pointerToArray.h b/panda/src/express/pointerToArray.h index 4e8a052e0f..1df1193b3c 100644 --- a/panda/src/express/pointerToArray.h +++ b/panda/src/express/pointerToArray.h @@ -98,6 +98,8 @@ PUBLISHED: EXTENSION(PointerToArray(PyObject *self, PyObject *source)); + INLINE void clear(); + INLINE size_type size() const; INLINE void push_back(const Element &x); INLINE void pop_back(); @@ -138,11 +140,8 @@ public: INLINE PointerToArray(size_type n, const Element &value, TypeHandle type_handle = get_type_handle(Element)); INLINE PointerToArray(const Element *begin, const Element *end, TypeHandle type_handle = get_type_handle(Element)); INLINE PointerToArray(const PointerToArray ©); - -#ifdef USE_MOVE_SEMANTICS - INLINE PointerToArray(PointerToArray &&from) NOEXCEPT; + INLINE PointerToArray(PointerToArray &&from) noexcept; INLINE explicit PointerToArray(pvector &&from, TypeHandle type_handle = get_type_handle(Element)); -#endif public: // Duplicating the interface of vector. The following member functions are @@ -160,6 +159,8 @@ public: INLINE size_type max_size() const; INLINE bool empty() const; + INLINE void clear(); + // Functions specific to vectors. INLINE void reserve(size_type n); INLINE void resize(size_type n); @@ -219,29 +220,25 @@ public: INLINE size_t count(const Element &) const; +#endif // CPPPARSER + +public: // Reassignment is by pointer, not memberwise as with a vector. INLINE PointerToArray & operator = (ReferenceCountedVector *ptr); INLINE PointerToArray & operator = (const PointerToArray ©); - -#ifdef USE_MOVE_SEMANTICS INLINE PointerToArray & - operator = (PointerToArray &&from) NOEXCEPT; -#endif - - INLINE void clear(); + operator = (PointerToArray &&from) noexcept; private: TypeHandle _type_handle; -private: // This static empty array is kept around just so we can return something // meaningful when begin() or end() is called and we have a NULL pointer. // It might not be shared properly between different .so's, since it's a // static member of a template class, but we don't really care. static pvector _empty_array; -#endif // CPPPARSER friend class ConstPointerToArray; }; @@ -262,6 +259,8 @@ PUBLISHED: INLINE ConstPointerToArray(const PointerToArray ©); INLINE ConstPointerToArray(const ConstPointerToArray ©); + INLINE void clear(); + typedef TYPENAME pvector::size_type size_type; INLINE size_type size() const; INLINE const Element &get_element(size_type n) const; @@ -299,12 +298,9 @@ PUBLISHED: INLINE ConstPointerToArray(const Element *begin, const Element *end, TypeHandle type_handle = get_type_handle(Element)); INLINE ConstPointerToArray(const PointerToArray ©); INLINE ConstPointerToArray(const ConstPointerToArray ©); - -#ifdef USE_MOVE_SEMANTICS - INLINE ConstPointerToArray(PointerToArray &&from) NOEXCEPT; - INLINE ConstPointerToArray(ConstPointerToArray &&from) NOEXCEPT; + INLINE ConstPointerToArray(PointerToArray &&from) noexcept; + INLINE ConstPointerToArray(ConstPointerToArray &&from) noexcept; INLINE explicit ConstPointerToArray(pvector &&from, TypeHandle type_handle = get_type_handle(Element)); -#endif // Duplicating the interface of vector. @@ -320,6 +316,8 @@ PUBLISHED: INLINE size_type max_size() const; INLINE bool empty() const; + INLINE void clear(); + // Functions specific to vectors. INLINE size_type capacity() const; INLINE reference front() const; @@ -351,6 +349,9 @@ PUBLISHED: INLINE size_t count(const Element &) const; +#endif // CPPPARSER + +public: // Reassignment is by pointer, not memberwise as with a vector. INLINE ConstPointerToArray & operator = (ReferenceCountedVector *ptr); @@ -358,26 +359,19 @@ PUBLISHED: operator = (const PointerToArray ©); INLINE ConstPointerToArray & operator = (const ConstPointerToArray ©); - -#ifdef USE_MOVE_SEMANTICS INLINE ConstPointerToArray & - operator = (PointerToArray &&from) NOEXCEPT; + operator = (PointerToArray &&from) noexcept; INLINE ConstPointerToArray & - operator = (ConstPointerToArray &&from) NOEXCEPT; -#endif - - INLINE void clear(); + operator = (ConstPointerToArray &&from) noexcept; private: TypeHandle _type_handle; -private: // This static empty array is kept around just so we can return something // meangful when begin() or end() is called and we have a NULL pointer. It // might not be shared properly between different .so's, since it's a static // member of a template class, but we don't really care. static pvector _empty_array; -#endif // CPPPARSER friend class PointerToArray; }; diff --git a/panda/src/express/pointerToArrayBase.I b/panda/src/express/pointerToArrayBase.I index de8c17d843..2b60162abc 100644 --- a/panda/src/express/pointerToArrayBase.I +++ b/panda/src/express/pointerToArrayBase.I @@ -132,17 +132,15 @@ PointerToArrayBase(const PointerToArrayBase ©) : { } -#ifdef USE_MOVE_SEMANTICS /** * */ template INLINE PointerToArrayBase:: -PointerToArrayBase(PointerToArrayBase &&from) NOEXCEPT : +PointerToArrayBase(PointerToArrayBase &&from) noexcept : PointerToBase >(move(from)) { } -#endif // USE_MOVE_SEMANTICS /** * diff --git a/panda/src/express/pointerToArrayBase.h b/panda/src/express/pointerToArrayBase.h index 8c33f69be2..6f6128e26b 100644 --- a/panda/src/express/pointerToArrayBase.h +++ b/panda/src/express/pointerToArrayBase.h @@ -73,10 +73,7 @@ public: protected: INLINE PointerToArrayBase(ReferenceCountedVector *ptr); INLINE PointerToArrayBase(const PointerToArrayBase ©); - -#ifdef USE_MOVE_SEMANTICS - INLINE PointerToArrayBase(PointerToArrayBase &&from) NOEXCEPT; -#endif + INLINE PointerToArrayBase(PointerToArrayBase &&from) noexcept; PUBLISHED: INLINE ~PointerToArrayBase(); diff --git a/panda/src/express/pointerToBase.I b/panda/src/express/pointerToBase.I index bf4ff877f0..27a02daa46 100644 --- a/panda/src/express/pointerToBase.I +++ b/panda/src/express/pointerToBase.I @@ -51,13 +51,12 @@ INLINE PointerToBase:: } } -#ifdef USE_MOVE_SEMANTICS /** * */ template INLINE PointerToBase:: -PointerToBase(PointerToBase &&from) NOEXCEPT { +PointerToBase(PointerToBase &&from) noexcept { _void_ptr = from._void_ptr; from._void_ptr = (void *)NULL; } @@ -70,7 +69,7 @@ PointerToBase(PointerToBase &&from) NOEXCEPT { */ template INLINE void PointerToBase:: -reassign(PointerToBase &&from) NOEXCEPT { +reassign(PointerToBase &&from) noexcept { // Protect against self-move-assignment. if (from._void_ptr != this->_void_ptr) { To *old_ptr = (To *)this->_void_ptr; @@ -84,7 +83,6 @@ reassign(PointerToBase &&from) NOEXCEPT { } } } -#endif // USE_MOVE_SEMANTICS /** * This is the main work of the PointerTo family. When the pointer is diff --git a/panda/src/express/pointerToBase.h b/panda/src/express/pointerToBase.h index 919f596c33..4ac546993c 100644 --- a/panda/src/express/pointerToBase.h +++ b/panda/src/express/pointerToBase.h @@ -31,18 +31,15 @@ public: typedef T To; protected: - ALWAYS_INLINE_CONSTEXPR PointerToBase() NOEXCEPT DEFAULT_CTOR; + ALWAYS_INLINE constexpr PointerToBase() noexcept = default; INLINE PointerToBase(To *ptr); INLINE PointerToBase(const PointerToBase ©); + INLINE PointerToBase(PointerToBase &&from) noexcept; INLINE ~PointerToBase(); -#ifdef USE_MOVE_SEMANTICS - INLINE PointerToBase(PointerToBase &&from) NOEXCEPT; - INLINE void reassign(PointerToBase &&from) NOEXCEPT; -#endif - INLINE void reassign(To *ptr); INLINE void reassign(const PointerToBase ©); + INLINE void reassign(PointerToBase &&from) noexcept; INLINE void update_type(To *ptr); diff --git a/panda/src/express/pointerToVoid.I b/panda/src/express/pointerToVoid.I index ee3a36e303..c6f981a7fb 100644 --- a/panda/src/express/pointerToVoid.I +++ b/panda/src/express/pointerToVoid.I @@ -14,8 +14,8 @@ /** * */ -CONSTEXPR PointerToVoid:: -PointerToVoid() NOEXCEPT : _void_ptr(nullptr) { +constexpr PointerToVoid:: +PointerToVoid() noexcept : _void_ptr(nullptr) { } /** @@ -30,7 +30,7 @@ PointerToVoid() NOEXCEPT : _void_ptr(nullptr) { * Returns true if the PointerTo is a NULL pointer, false otherwise. (Direct * comparison to a NULL pointer also works.) */ -CONSTEXPR bool PointerToVoid:: +constexpr bool PointerToVoid:: is_null() const { return _void_ptr == nullptr; } @@ -82,7 +82,7 @@ operator != (const PointerToVoid &other) const { * For internal use only. Use the global swap() function instead. */ INLINE void PointerToVoid:: -swap(PointerToVoid &other) NOEXCEPT { +swap(PointerToVoid &other) noexcept { AtomicAdjust::Pointer temp = _void_ptr; _void_ptr = other._void_ptr; other._void_ptr = temp; diff --git a/panda/src/express/pointerToVoid.h b/panda/src/express/pointerToVoid.h index 0d2c1d33e9..aca9ba15e7 100644 --- a/panda/src/express/pointerToVoid.h +++ b/panda/src/express/pointerToVoid.h @@ -32,14 +32,14 @@ */ class EXPCL_PANDAEXPRESS PointerToVoid : public MemoryBase { protected: - CONSTEXPR PointerToVoid() NOEXCEPT; + constexpr PointerToVoid() noexcept; //INLINE ~PointerToVoid(); private: - PointerToVoid(const PointerToVoid ©) DELETED; + PointerToVoid(const PointerToVoid ©) = delete; PUBLISHED: - CONSTEXPR bool is_null() const; + constexpr bool is_null() const; INLINE size_t get_hash() const; public: @@ -51,7 +51,7 @@ public: INLINE bool operator == (const PointerToVoid &other) const; INLINE bool operator != (const PointerToVoid &other) const; - INLINE void swap(PointerToVoid &other) NOEXCEPT; + INLINE void swap(PointerToVoid &other) noexcept; protected: // Within the PointerToVoid class, we only store a void pointer. This is diff --git a/panda/src/express/referenceCount.I b/panda/src/express/referenceCount.I index c1d54da5da..f18c60a02c 100644 --- a/panda/src/express/referenceCount.I +++ b/panda/src/express/referenceCount.I @@ -112,9 +112,9 @@ ReferenceCount:: nassertv(_ref_count == 0 || _ref_count == local_ref_count); // Tell our weak reference holders that we're going away now. - if (_weak_list != (WeakReferenceList *)NULL) { - delete (WeakReferenceList *)_weak_list; - _weak_list = (WeakReferenceList *)NULL; + if (_weak_list != nullptr) { + ((WeakReferenceList *)_weak_list)->mark_deleted(); + _weak_list = nullptr; } #ifndef NDEBUG @@ -253,6 +253,9 @@ has_weak_list() const { * Returns the WeakReferenceList associated with this ReferenceCount object. * If there has never been a WeakReferenceList associated with this object, * creates one now. + * + * The returned object will be deleted automatically when all weak and strong + * references to the object have gone. */ INLINE WeakReferenceList *ReferenceCount:: get_weak_list() const { @@ -264,14 +267,21 @@ get_weak_list() const { /** * Adds the indicated PointerToVoid as a weak reference to this object. + * Returns an object that will persist as long as any reference (strong or + * weak) exists, for calling unref() or checking whether the object still + * exists. */ -INLINE void ReferenceCount:: -weak_ref(WeakPointerToVoid *ptv) { +INLINE WeakReferenceList *ReferenceCount:: +weak_ref() { TAU_PROFILE("void ReferenceCount::weak_ref()", " ", TAU_USER); #ifdef _DEBUG - nassertv(test_ref_count_integrity()); + nassertr(test_ref_count_integrity(), nullptr); +#else + nassertr(_ref_count != deleted_ref_count, nullptr); #endif - get_weak_list()->add_reference(ptv); + WeakReferenceList *weak_ref = get_weak_list(); + weak_ref->ref(); + return weak_ref; } /** @@ -279,13 +289,36 @@ weak_ref(WeakPointerToVoid *ptv) { * must have previously been added via a call to weak_ref(). */ INLINE void ReferenceCount:: -weak_unref(WeakPointerToVoid *ptv) { +weak_unref() { TAU_PROFILE("void ReferenceCount::weak_unref()", " ", TAU_USER); #ifdef _DEBUG nassertv(test_ref_count_integrity()); #endif - nassertv(has_weak_list()); - ((WeakReferenceList *)_weak_list)->clear_reference(ptv); + WeakReferenceList *weak_list = (WeakReferenceList *)_weak_list; + nassertv(weak_list != nullptr); + bool nonzero = weak_list->unref(); + nassertv(nonzero); +} + +/** + * Atomically increases the reference count of this object if it is not zero. + * Do not use this. This exists only to implement a special case for weak + * pointers. + * @return true if the reference count was incremented, false if it was zero. + */ +INLINE bool ReferenceCount:: +ref_if_nonzero() const { +#ifdef _DEBUG + test_ref_count_integrity(); +#endif + AtomicAdjust::Integer ref_count; + do { + ref_count = AtomicAdjust::get(_ref_count); + if (ref_count <= 0) { + return false; + } + } while (ref_count != AtomicAdjust::compare_and_exchange(_ref_count, ref_count, ref_count + 1)); + return true; } /** diff --git a/panda/src/express/referenceCount.h b/panda/src/express/referenceCount.h index 72425dcd8d..ba27ac7db8 100644 --- a/panda/src/express/referenceCount.h +++ b/panda/src/express/referenceCount.h @@ -60,8 +60,10 @@ public: INLINE bool has_weak_list() const; INLINE WeakReferenceList *get_weak_list() const; - INLINE void weak_ref(WeakPointerToVoid *ptv); - INLINE void weak_unref(WeakPointerToVoid *ptv); + INLINE WeakReferenceList *weak_ref(); + INLINE void weak_unref(); + + INLINE bool ref_if_nonzero() const; protected: bool do_test_ref_count_integrity() const; diff --git a/panda/src/express/trueClock.I b/panda/src/express/trueClock.I index da51e8628f..e9bc56aed4 100644 --- a/panda/src/express/trueClock.I +++ b/panda/src/express/trueClock.I @@ -21,7 +21,7 @@ get_short_time() { bool is_paranoid_clock = get_paranoid_clock(); if (is_paranoid_clock) { - _lock.acquire(); + _lock.lock(); } double time = get_short_raw_time(); @@ -30,7 +30,7 @@ get_short_time() { // Check for rollforwards, rollbacks, and compensate for Speed Gear type // programs by verifying against the time of day clock. time = correct_time(time); - _lock.release(); + _lock.unlock(); } return time; diff --git a/panda/src/express/virtualFileMountRamdisk.cxx b/panda/src/express/virtualFileMountRamdisk.cxx index 244f5c79df..78652e9cc3 100644 --- a/panda/src/express/virtualFileMountRamdisk.cxx +++ b/panda/src/express/virtualFileMountRamdisk.cxx @@ -32,9 +32,9 @@ VirtualFileMountRamdisk() : _root("") { */ bool VirtualFileMountRamdisk:: has_file(const Filename &file) const { - _lock.acquire(); + _lock.lock(); PT(FileBase) f = _root.do_find_file(file); - _lock.release(); + _lock.unlock(); return (f != NULL); } @@ -45,9 +45,9 @@ has_file(const Filename &file) const { */ bool VirtualFileMountRamdisk:: create_file(const Filename &file) { - _lock.acquire(); + _lock.lock(); PT(File) f = _root.do_create_file(file); - _lock.release(); + _lock.unlock(); return (f != NULL); } @@ -58,9 +58,9 @@ create_file(const Filename &file) { */ bool VirtualFileMountRamdisk:: delete_file(const Filename &file) { - _lock.acquire(); + _lock.lock(); PT(FileBase) f = _root.do_delete_file(file); - _lock.release(); + _lock.unlock(); return (f != NULL); } @@ -72,10 +72,10 @@ delete_file(const Filename &file) { */ bool VirtualFileMountRamdisk:: rename_file(const Filename &orig_filename, const Filename &new_filename) { - _lock.acquire(); + _lock.lock(); PT(FileBase) orig_fb = _root.do_find_file(orig_filename); if (orig_fb == NULL) { - _lock.release(); + _lock.unlock(); return false; } @@ -84,7 +84,7 @@ rename_file(const Filename &orig_filename, const Filename &new_filename) { Directory *orig_d = DCAST(Directory, orig_fb); PT(Directory) new_d = _root.do_make_directory(new_filename); if (new_d == NULL || !new_d->_files.empty()) { - _lock.release(); + _lock.unlock(); return false; } @@ -95,7 +95,7 @@ rename_file(const Filename &orig_filename, const Filename &new_filename) { new_d->_files.swap(orig_d->_files); _root.do_delete_file(orig_filename); - _lock.release(); + _lock.unlock(); return true; } @@ -103,7 +103,7 @@ rename_file(const Filename &orig_filename, const Filename &new_filename) { File *orig_f = DCAST(File, orig_fb); PT(File) new_f = _root.do_create_file(new_filename); if (new_f == NULL) { - _lock.release(); + _lock.unlock(); return false; } @@ -115,7 +115,7 @@ rename_file(const Filename &orig_filename, const Filename &new_filename) { new_f->_data.str(orig_f->_data.str()); _root.do_delete_file(orig_filename); - _lock.release(); + _lock.unlock(); return true; } @@ -127,10 +127,10 @@ rename_file(const Filename &orig_filename, const Filename &new_filename) { */ bool VirtualFileMountRamdisk:: copy_file(const Filename &orig_filename, const Filename &new_filename) { - _lock.acquire(); + _lock.lock(); PT(FileBase) orig_fb = _root.do_find_file(orig_filename); if (orig_fb == NULL || orig_fb->is_directory()) { - _lock.release(); + _lock.unlock(); return false; } @@ -138,7 +138,7 @@ copy_file(const Filename &orig_filename, const Filename &new_filename) { File *orig_f = DCAST(File, orig_fb); PT(File) new_f = _root.do_create_file(new_filename); if (new_f == NULL) { - _lock.release(); + _lock.unlock(); return false; } @@ -149,7 +149,7 @@ copy_file(const Filename &orig_filename, const Filename &new_filename) { new_f->_data.str(orig_f->_data.str()); - _lock.release(); + _lock.unlock(); return true; } @@ -161,9 +161,9 @@ copy_file(const Filename &orig_filename, const Filename &new_filename) { */ bool VirtualFileMountRamdisk:: make_directory(const Filename &file) { - _lock.acquire(); + _lock.lock(); PT(Directory) f = _root.do_make_directory(file); - _lock.release(); + _lock.unlock(); return (f != NULL); } @@ -173,9 +173,9 @@ make_directory(const Filename &file) { */ bool VirtualFileMountRamdisk:: is_directory(const Filename &file) const { - _lock.acquire(); + _lock.lock(); PT(FileBase) f = _root.do_find_file(file); - _lock.release(); + _lock.unlock(); return (f != NULL && f->is_directory()); } @@ -185,9 +185,9 @@ is_directory(const Filename &file) const { */ bool VirtualFileMountRamdisk:: is_regular_file(const Filename &file) const { - _lock.acquire(); + _lock.lock(); PT(FileBase) f = _root.do_find_file(file); - _lock.release(); + _lock.unlock(); return (f != NULL && !f->is_directory()); } @@ -207,9 +207,9 @@ is_writable(const Filename &file) const { */ istream *VirtualFileMountRamdisk:: open_read_file(const Filename &file) const { - _lock.acquire(); + _lock.lock(); PT(FileBase) f = _root.do_find_file(file); - _lock.release(); + _lock.unlock(); if (f == (FileBase *)NULL || f->is_directory()) { return NULL; } @@ -225,9 +225,9 @@ open_read_file(const Filename &file) const { */ ostream *VirtualFileMountRamdisk:: open_write_file(const Filename &file, bool truncate) { - _lock.acquire(); + _lock.lock(); PT(File) f = _root.do_create_file(file); - _lock.release(); + _lock.unlock(); if (f == (File *)NULL) { return NULL; } @@ -254,9 +254,9 @@ open_write_file(const Filename &file, bool truncate) { */ ostream *VirtualFileMountRamdisk:: open_append_file(const Filename &file) { - _lock.acquire(); + _lock.lock(); PT(File) f = _root.do_create_file(file); - _lock.release(); + _lock.unlock(); if (f == (File *)NULL) { return NULL; } @@ -271,9 +271,9 @@ open_append_file(const Filename &file) { */ iostream *VirtualFileMountRamdisk:: open_read_write_file(const Filename &file, bool truncate) { - _lock.acquire(); + _lock.lock(); PT(File) f = _root.do_create_file(file); - _lock.release(); + _lock.unlock(); if (f == (File *)NULL) { return NULL; } @@ -296,9 +296,9 @@ open_read_write_file(const Filename &file, bool truncate) { */ iostream *VirtualFileMountRamdisk:: open_read_append_file(const Filename &file) { - _lock.acquire(); + _lock.lock(); PT(FileBase) f = _root.do_find_file(file); - _lock.release(); + _lock.unlock(); if (f == (FileBase *)NULL || f->is_directory()) { return NULL; } @@ -314,9 +314,9 @@ open_read_append_file(const Filename &file) { */ streamsize VirtualFileMountRamdisk:: get_file_size(const Filename &file, istream *stream) const { - _lock.acquire(); + _lock.lock(); PT(FileBase) f = _root.do_find_file(file); - _lock.release(); + _lock.unlock(); if (f == (FileBase *)NULL || f->is_directory()) { return 0; } @@ -331,9 +331,9 @@ get_file_size(const Filename &file, istream *stream) const { */ streamsize VirtualFileMountRamdisk:: get_file_size(const Filename &file) const { - _lock.acquire(); + _lock.lock(); PT(FileBase) f = _root.do_find_file(file); - _lock.release(); + _lock.unlock(); if (f == (FileBase *)NULL || f->is_directory()) { return 0; } @@ -354,14 +354,14 @@ get_file_size(const Filename &file) const { */ time_t VirtualFileMountRamdisk:: get_timestamp(const Filename &file) const { - _lock.acquire(); + _lock.lock(); PT(FileBase) f = _root.do_find_file(file); if (f.is_null()) { - _lock.release(); + _lock.unlock(); return 0; } time_t timestamp = f->_timestamp; - _lock.release(); + _lock.unlock(); return timestamp; } @@ -372,17 +372,17 @@ get_timestamp(const Filename &file) const { */ bool VirtualFileMountRamdisk:: scan_directory(vector_string &contents, const Filename &dir) const { - _lock.acquire(); + _lock.lock(); PT(FileBase) f = _root.do_find_file(dir); if (f == (FileBase *)NULL || !f->is_directory()) { - _lock.release(); + _lock.unlock(); return false; } Directory *f2 = DCAST(Directory, f); bool result = f2->do_scan_directory(contents); - _lock.release(); + _lock.unlock(); return result; } @@ -393,10 +393,10 @@ bool VirtualFileMountRamdisk:: atomic_compare_and_exchange_contents(const Filename &file, string &orig_contents, const string &old_contents, const string &new_contents) { - _lock.acquire(); + _lock.lock(); PT(FileBase) f = _root.do_find_file(file); if (f == (FileBase *)NULL || f->is_directory()) { - _lock.release(); + _lock.unlock(); return false; } @@ -409,7 +409,7 @@ atomic_compare_and_exchange_contents(const Filename &file, string &orig_contents retval = true; } - _lock.release(); + _lock.unlock(); return retval; } @@ -418,17 +418,17 @@ atomic_compare_and_exchange_contents(const Filename &file, string &orig_contents */ bool VirtualFileMountRamdisk:: atomic_read_contents(const Filename &file, string &contents) const { - _lock.acquire(); + _lock.lock(); PT(FileBase) f = _root.do_find_file(file); if (f == (FileBase *)NULL || f->is_directory()) { - _lock.release(); + _lock.unlock(); return false; } File *f2 = DCAST(File, f); contents = f2->_data.str(); - _lock.release(); + _lock.unlock(); return true; } diff --git a/panda/src/express/virtualFileSystem.cxx b/panda/src/express/virtualFileSystem.cxx index da7797ec9d..d69f518bc1 100644 --- a/panda/src/express/virtualFileSystem.cxx +++ b/panda/src/express/virtualFileSystem.cxx @@ -190,9 +190,9 @@ mount(VirtualFileMount *mount, const Filename &mount_point, int flags) { << "mount " << *mount << " under " << mount_point << "\n"; } - _lock.acquire(); + _lock.lock(); bool result = do_mount(mount, mount_point, flags); - _lock.release(); + _lock.unlock(); return result; } @@ -202,7 +202,7 @@ mount(VirtualFileMount *mount, const Filename &mount_point, int flags) { */ int VirtualFileSystem:: unmount(Multifile *multifile) { - _lock.acquire(); + _lock.lock(); Mounts::iterator ri, wi; wi = ri = _mounts.begin(); while (ri != _mounts.end()) { @@ -234,7 +234,7 @@ unmount(Multifile *multifile) { int num_removed = _mounts.end() - wi; _mounts.erase(wi, _mounts.end()); ++_mount_seq; - _lock.release(); + _lock.unlock(); return num_removed; } @@ -244,7 +244,7 @@ unmount(Multifile *multifile) { */ int VirtualFileSystem:: unmount(const Filename &physical_filename) { - _lock.acquire(); + _lock.lock(); Mounts::iterator ri, wi; wi = ri = _mounts.begin(); while (ri != _mounts.end()) { @@ -293,7 +293,7 @@ unmount(const Filename &physical_filename) { int num_removed = _mounts.end() - wi; _mounts.erase(wi, _mounts.end()); ++_mount_seq; - _lock.release(); + _lock.unlock(); return num_removed; } @@ -303,7 +303,7 @@ unmount(const Filename &physical_filename) { */ int VirtualFileSystem:: unmount(VirtualFileMount *mount) { - _lock.acquire(); + _lock.lock(); Mounts::iterator ri, wi; wi = ri = _mounts.begin(); while (ri != _mounts.end()) { @@ -326,7 +326,7 @@ unmount(VirtualFileMount *mount) { int num_removed = _mounts.end() - wi; _mounts.erase(wi, _mounts.end()); ++_mount_seq; - _lock.release(); + _lock.unlock(); return num_removed; } @@ -336,7 +336,7 @@ unmount(VirtualFileMount *mount) { */ int VirtualFileSystem:: unmount_point(const Filename &mount_point) { - _lock.acquire(); + _lock.lock(); Filename nmp = normalize_mount_point(mount_point); Mounts::iterator ri, wi; wi = ri = _mounts.begin(); @@ -362,7 +362,7 @@ unmount_point(const Filename &mount_point) { int num_removed = _mounts.end() - wi; _mounts.erase(wi, _mounts.end()); ++_mount_seq; - _lock.release(); + _lock.unlock(); return num_removed; } @@ -372,7 +372,7 @@ unmount_point(const Filename &mount_point) { */ int VirtualFileSystem:: unmount_all() { - _lock.acquire(); + _lock.lock(); Mounts::iterator ri; for (ri = _mounts.begin(); ri != _mounts.end(); ++ri) { VirtualFileMount *mount = (*ri); @@ -386,7 +386,7 @@ unmount_all() { int num_removed = _mounts.size(); _mounts.clear(); ++_mount_seq; - _lock.release(); + _lock.unlock(); return num_removed; } @@ -395,9 +395,9 @@ unmount_all() { */ int VirtualFileSystem:: get_num_mounts() const { - ((VirtualFileSystem *)this)->_lock.acquire(); + _lock.lock(); int result = _mounts.size(); - ((VirtualFileSystem *)this)->_lock.release(); + _lock.unlock(); return result; } @@ -406,13 +406,13 @@ get_num_mounts() const { */ PT(VirtualFileMount) VirtualFileSystem:: get_mount(int n) const { - ((VirtualFileSystem *)this)->_lock.acquire(); + _lock.lock(); nassertd(n >= 0 && n < (int)_mounts.size()) { - ((VirtualFileSystem *)this)->_lock.release(); + _lock.unlock(); return NULL; } PT(VirtualFileMount) result = _mounts[n]; - ((VirtualFileSystem *)this)->_lock.release(); + _lock.unlock(); return result; } @@ -423,21 +423,21 @@ get_mount(int n) const { */ bool VirtualFileSystem:: chdir(const Filename &new_directory) { - _lock.acquire(); + _lock.lock(); if (new_directory == "/") { // We can always return to the root. _cwd = new_directory; - _lock.release(); + _lock.unlock(); return true; } PT(VirtualFile) file = do_get_file(new_directory, OF_status_only); if (file != (VirtualFile *)NULL && file->is_directory()) { _cwd = file->get_filename(); - _lock.release(); + _lock.unlock(); return true; } - _lock.release(); + _lock.unlock(); return false; } @@ -446,9 +446,9 @@ chdir(const Filename &new_directory) { */ Filename VirtualFileSystem:: get_cwd() const { - ((VirtualFileSystem *)this)->_lock.acquire(); + _lock.lock(); Filename result = _cwd; - ((VirtualFileSystem *)this)->_lock.release(); + _lock.unlock(); return result; } @@ -460,9 +460,9 @@ get_cwd() const { */ bool VirtualFileSystem:: make_directory(const Filename &filename) { - _lock.acquire(); + _lock.lock(); PT(VirtualFile) result = do_get_file(filename, OF_make_directory); - _lock.release(); + _lock.unlock(); nassertr_always(result != NULL, false); return result->is_directory(); } @@ -474,7 +474,7 @@ make_directory(const Filename &filename) { */ bool VirtualFileSystem:: make_directory_full(const Filename &filename) { - _lock.acquire(); + _lock.lock(); // First, make sure everything up to the last path is known. We don't care // too much if any of these fail; maybe they failed because the directory @@ -489,7 +489,7 @@ make_directory_full(const Filename &filename) { // Now make the last one, and check the return value. PT(VirtualFile) result = do_get_file(filename, OF_make_directory); - _lock.release(); + _lock.unlock(); nassertr_always(result != NULL, false); return result->is_directory(); } @@ -508,9 +508,9 @@ make_directory_full(const Filename &filename) { PT(VirtualFile) VirtualFileSystem:: get_file(const Filename &filename, bool status_only) const { int open_flags = status_only ? OF_status_only : 0; - ((VirtualFileSystem *)this)->_lock.acquire(); + _lock.lock(); PT(VirtualFile) result = do_get_file(filename, open_flags); - ((VirtualFileSystem *)this)->_lock.release(); + _lock.unlock(); return result; } @@ -522,9 +522,9 @@ get_file(const Filename &filename, bool status_only) const { */ PT(VirtualFile) VirtualFileSystem:: create_file(const Filename &filename) { - ((VirtualFileSystem *)this)->_lock.acquire(); + _lock.lock(); PT(VirtualFile) result = do_get_file(filename, OF_create_file); - ((VirtualFileSystem *)this)->_lock.release(); + _lock.unlock(); return result; } @@ -588,20 +588,20 @@ delete_file(const Filename &filename) { */ bool VirtualFileSystem:: rename_file(const Filename &orig_filename, const Filename &new_filename) { - _lock.acquire(); + _lock.lock(); PT(VirtualFile) orig_file = do_get_file(orig_filename, OF_status_only); if (orig_file == (VirtualFile *)NULL) { - _lock.release(); + _lock.unlock(); return false; } PT(VirtualFile) new_file = do_get_file(new_filename, OF_status_only | OF_allow_nonexist); if (new_file == (VirtualFile *)NULL) { - _lock.release(); + _lock.unlock(); return false; } - _lock.release(); + _lock.unlock(); return orig_file->rename_file(new_file); } @@ -712,13 +712,13 @@ find_all_files(const Filename &filename, const DSearchPath &searchpath, */ void VirtualFileSystem:: write(ostream &out) const { - ((VirtualFileSystem *)this)->_lock.acquire(); + _lock.lock(); Mounts::const_iterator mi; for (mi = _mounts.begin(); mi != _mounts.end(); ++mi) { VirtualFileMount *mount = (*mi); mount->write(out); } - ((VirtualFileSystem *)this)->_lock.release(); + _lock.unlock(); } diff --git a/panda/src/express/virtualFileSystem.h b/panda/src/express/virtualFileSystem.h index 2ff1fa4e95..e1d7e6fd37 100644 --- a/panda/src/express/virtualFileSystem.h +++ b/panda/src/express/virtualFileSystem.h @@ -157,7 +157,7 @@ private: int open_flags) const; bool consider_mount_mf(const Filename &filename); - MutexImpl _lock; + mutable MutexImpl _lock; typedef pvector Mounts; Mounts _mounts; unsigned int _mount_seq; diff --git a/panda/src/express/weakPointerTo.I b/panda/src/express/weakPointerTo.I index aec710288f..60ac8a1917 100644 --- a/panda/src/express/weakPointerTo.I +++ b/panda/src/express/weakPointerTo.I @@ -72,6 +72,35 @@ operator T * () const { return (To *)WeakPointerToBase::_void_ptr; } +/** + * A thread-safe way to access the underlying pointer; will silently return + * null if the underlying pointer was deleted or null. + * Note that this may return null even if was_deleted() still returns true, + * which can occur if the object has reached reference count 0 and is about to + * be destroyed. + */ +template +INLINE PointerTo WeakPointerTo:: +lock() const { + WeakReferenceList *weak_ref = this->_weak_ref; + if (weak_ref != nullptr) { + PointerTo ptr; + weak_ref->_lock.lock(); + if (!weak_ref->was_deleted()) { + // We also need to check that the reference count is not zero (which can + // happen if the object is currently being destructed), since that could + // cause double deletion. + To *plain_ptr = (To *)WeakPointerToBase::_void_ptr; + if (plain_ptr != nullptr && plain_ptr->ref_if_nonzero()) { + ptr.cheat() = plain_ptr; + } + } + weak_ref->_lock.unlock(); + return ptr; + } + return nullptr; +} + /** * Returns an ordinary pointer instead of a WeakPointerTo. Useful to work * around compiler problems, particularly for implicit upcasts. @@ -207,6 +236,32 @@ operator const T * () const { return (To *)WeakPointerToBase::_void_ptr; } +/** + * A thread-safe way to access the underlying pointer; will silently return + * null if the underlying pointer was deleted or null. + */ +template +INLINE ConstPointerTo WeakConstPointerTo:: +lock() const { + WeakReferenceList *weak_ref = this->_weak_ref; + if (weak_ref != nullptr) { + ConstPointerTo ptr; + weak_ref->_lock.lock(); + if (!weak_ref->was_deleted()) { + // We also need to check that the reference count is not zero (which can + // happen if the object is currently being destructed), since that could + // cause double deletion. + const To *plain_ptr = (const To *)WeakPointerToBase::_void_ptr; + if (plain_ptr != nullptr && plain_ptr->ref_if_nonzero()) { + ptr.cheat() = plain_ptr; + } + } + weak_ref->_lock.unlock(); + return ptr; + } + return nullptr; +} + /** * Returns an ordinary pointer instead of a WeakConstPointerTo. Useful to * work around compiler problems, particularly for implicit upcasts. diff --git a/panda/src/express/weakPointerTo.h b/panda/src/express/weakPointerTo.h index 44d9561eb3..897c46a210 100644 --- a/panda/src/express/weakPointerTo.h +++ b/panda/src/express/weakPointerTo.h @@ -41,6 +41,7 @@ public: INLINE operator T *() const; PUBLISHED: + INLINE PointerTo lock() const; INLINE To *p() const; INLINE To *get_orig() const; @@ -77,6 +78,7 @@ public: INLINE operator const T *() const; PUBLISHED: + INLINE ConstPointerTo lock() const; INLINE const To *p() const; INLINE const To *get_orig() const; diff --git a/panda/src/express/weakPointerToBase.I b/panda/src/express/weakPointerToBase.I index cb60c43fc2..1c831529a1 100644 --- a/panda/src/express/weakPointerToBase.I +++ b/panda/src/express/weakPointerToBase.I @@ -17,7 +17,13 @@ template INLINE WeakPointerToBase:: WeakPointerToBase(To *ptr) { - reassign(ptr); + _void_ptr = (To *)ptr; + if (ptr != nullptr) { + _weak_ref = ptr->weak_ref(); +#ifdef DO_MEMORY_USAGE + update_type(ptr); +#endif + } } /** @@ -26,7 +32,13 @@ WeakPointerToBase(To *ptr) { template INLINE WeakPointerToBase:: WeakPointerToBase(const PointerToBase ©) { - reassign(copy); + // This double-casting is a bit of a cheat to get around the inheritance + // issue--it's difficult to declare a template class to be a friend. + To *ptr = (To *)((const WeakPointerToBase *)©)->_void_ptr; + _void_ptr = ptr; + if (ptr != nullptr) { + _weak_ref = ptr->weak_ref(); + } } /** @@ -36,11 +48,35 @@ template INLINE WeakPointerToBase:: WeakPointerToBase(const WeakPointerToBase ©) { _void_ptr = copy._void_ptr; - _ptr_was_deleted = copy._ptr_was_deleted; - if (is_valid_pointer()) { - To *ptr = (To *)_void_ptr; - ptr->weak_ref(this); + // Don't bother increasing the weak reference count if the object was + // already deleted. + WeakReferenceList *weak_ref = copy._weak_ref; + if (weak_ref != nullptr && !weak_ref->was_deleted()) { + _weak_ref = copy._weak_ref; + _weak_ref->ref(); + } +} + +/** + * + */ +template +INLINE WeakPointerToBase:: +WeakPointerToBase(WeakPointerToBase &&from) noexcept { + // Protect against self-move-assignment. + if (from._void_ptr != this->_void_ptr) { + WeakReferenceList *old_ref = (To *)this->_weak_ref; + + this->_void_ptr = from._void_ptr; + this->_weak_ref = from._weak_ref; + from._void_ptr = nullptr; + from._weak_ref = nullptr; + + // Now delete the old pointer. + if (old_ref != nullptr && !old_ref->unref()) { + delete old_ref; + } } } @@ -50,7 +86,10 @@ WeakPointerToBase(const WeakPointerToBase ©) { template INLINE WeakPointerToBase:: ~WeakPointerToBase() { - reassign((To *)NULL); + WeakReferenceList *old_ref = (WeakReferenceList *)_weak_ref; + if (old_ref != nullptr && !old_ref->unref()) { + delete old_ref; + } } /** @@ -60,34 +99,23 @@ INLINE WeakPointerToBase:: template void WeakPointerToBase:: reassign(To *ptr) { - if (ptr != (To *)_void_ptr || _ptr_was_deleted) { - To *old_ptr = (To *)_void_ptr; + if (ptr != (To *)_void_ptr) { + WeakReferenceList *old_ref = (WeakReferenceList *)_weak_ref; _void_ptr = (void *)ptr; - if (ptr != (To *)NULL) { - ptr->weak_ref(this); + if (ptr != nullptr) { + _weak_ref = ptr->weak_ref(); #ifdef DO_MEMORY_USAGE - if (MemoryUsage::get_track_memory_usage()) { - // Make sure the MemoryUsage record knows what the TypeHandle is, if - // we know it ourselves. - TypeHandle type = get_type_handle(To); - if (type == TypeHandle::none()) { - do_init_type(To); - type = get_type_handle(To); - } - if (type != TypeHandle::none()) { - MemoryUsage::update_type(ptr, type); - } - } + update_type(ptr); #endif + } else { + _weak_ref = nullptr; } // Now remove the old reference. - if (old_ptr != (To *)NULL && !_ptr_was_deleted) { - old_ptr->weak_unref(this); + if (old_ref != nullptr && !old_ref->unref()) { + delete old_ref; } - - _ptr_was_deleted = false; } } @@ -108,8 +136,69 @@ reassign(const PointerToBase ©) { template INLINE void WeakPointerToBase:: reassign(const WeakPointerToBase ©) { - nassertv(!copy.was_deleted()); - reassign((To *)copy._void_ptr); + void *new_ptr = copy._void_ptr; + if (new_ptr != _void_ptr) { + WeakReferenceList *old_ref = (WeakReferenceList *)_weak_ref; + _void_ptr = new_ptr; + + // Don't bother increasing the weak reference count if the object was + // already deleted. + WeakReferenceList *weak_ref = copy._weak_ref; + if (weak_ref != nullptr && !weak_ref->was_deleted()) { + weak_ref->ref(); + _weak_ref = weak_ref; + } else { + _weak_ref = nullptr; + } + + // Now remove the old reference. + if (old_ref != nullptr && !old_ref->unref()) { + delete old_ref; + } + } +} + +/** + * + */ +template +INLINE void WeakPointerToBase:: +reassign(WeakPointerToBase &&from) noexcept { + // Protect against self-move-assignment. + if (from._void_ptr != this->_void_ptr) { + WeakReferenceList *old_ref = (WeakReferenceList *)this->_weak_ref; + + this->_void_ptr = from._void_ptr; + this->_weak_ref = from._weak_ref; + from._void_ptr = nullptr; + from._weak_ref = nullptr; + + // Now delete the old pointer. + if (old_ref != nullptr && !old_ref->unref()) { + delete old_ref; + } + } +} + +/** + * Ensures that the MemoryUsage record for the pointer has the right type of + * object, if we know the type ourselves. + */ +template +INLINE void WeakPointerToBase:: +update_type(To *ptr) { +#ifdef DO_MEMORY_USAGE + if (MemoryUsage::get_track_memory_usage()) { + TypeHandle type = get_type_handle(To); + if (type == TypeHandle::none()) { + do_init_type(To); + type = get_type_handle(To); + } + if (type != TypeHandle::none()) { + MemoryUsage::update_type(ptr, type); + } + } +#endif // DO_MEMORY_USAGE } #ifndef CPPPARSER @@ -323,8 +412,6 @@ operator < (const PointerToBase &other) const { #endif // CPPPARSER - - /** * A convenient way to set the PointerTo object to NULL. (Assignment to a NULL * pointer also works, of course.) @@ -332,7 +419,14 @@ operator < (const PointerToBase &other) const { template INLINE void WeakPointerToBase:: clear() { - reassign((To *)NULL); + WeakReferenceList *old_ref = (WeakReferenceList *)_weak_ref; + _void_ptr = nullptr; + _weak_ref = nullptr; + + // Now remove the old reference. + if (old_ref != nullptr && !old_ref->unref()) { + delete old_ref; + } } /** @@ -346,7 +440,9 @@ clear() { template INLINE void WeakPointerToBase:: refresh() const { - ((WeakPointerToBase *)this)->reassign((To *)_void_ptr); + if (_void_ptr != nullptr) { + ((WeakPointerToBase *)this)->reassign((To *)_void_ptr); + } } /** diff --git a/panda/src/express/weakPointerToBase.h b/panda/src/express/weakPointerToBase.h index 04d55b8b1d..4870ef21d8 100644 --- a/panda/src/express/weakPointerToBase.h +++ b/panda/src/express/weakPointerToBase.h @@ -31,11 +31,15 @@ protected: INLINE WeakPointerToBase(To *ptr); INLINE WeakPointerToBase(const PointerToBase ©); INLINE WeakPointerToBase(const WeakPointerToBase ©); + INLINE WeakPointerToBase(WeakPointerToBase &&from) noexcept; INLINE ~WeakPointerToBase(); void reassign(To *ptr); INLINE void reassign(const PointerToBase ©); INLINE void reassign(const WeakPointerToBase ©); + INLINE void reassign(WeakPointerToBase &&from) noexcept; + + INLINE void update_type(To *ptr); // No assignment or retrieval functions are declared in WeakPointerToBase, // because we will have to specialize on const vs. non-const later. diff --git a/panda/src/express/weakPointerToVoid.I b/panda/src/express/weakPointerToVoid.I index bc778630b7..120836510d 100644 --- a/panda/src/express/weakPointerToVoid.I +++ b/panda/src/express/weakPointerToVoid.I @@ -15,46 +15,34 @@ * */ INLINE WeakPointerToVoid:: -WeakPointerToVoid() : - _ptr_was_deleted(false), - _callback(NULL) { +WeakPointerToVoid() : _weak_ref(nullptr) { } /** - * This is intended only to be called by the WeakPointerList destructor. It - * indicates that the object that we were pointing to has just been deleted. - */ -INLINE void WeakPointerToVoid:: -mark_deleted() { - nassertv(!_ptr_was_deleted); - _ptr_was_deleted = true; - if (_callback != (WeakPointerCallback *)NULL) { - _callback->wp_callback(_void_ptr); - } -} - -/** - * Sets a callback that will be made when the pointer is deleted. If a - * previous callback has already been set, it will be replaced. + * Sets a callback that will be made when the pointer is deleted. Does + * nothing if this is a null pointer. * * If the pointer has already been deleted, the callback will be made * immediately. */ INLINE void WeakPointerToVoid:: -set_callback(WeakPointerCallback *callback) { - _callback = callback; - if (_ptr_was_deleted && _callback != (WeakPointerCallback *)NULL) { - _callback->wp_callback(_void_ptr); +add_callback(WeakPointerCallback *callback) const { + if (_weak_ref != nullptr && !_weak_ref->was_deleted()) { + _weak_ref->add_callback(callback, _void_ptr); + } else if (_void_ptr != nullptr) { + callback->wp_callback(_void_ptr); + _weak_ref = nullptr; } } /** - * Returns the callback that will be made when the pointer is deleted, or NULL - * if no callback has been set. + * Removes a previously added callback. */ -INLINE WeakPointerCallback *WeakPointerToVoid:: -get_callback() const { - return _callback; +INLINE void WeakPointerToVoid:: +remove_callback(WeakPointerCallback *callback) const { + if (_weak_ref != nullptr) { + _weak_ref->remove_callback(callback); + } } /** @@ -63,7 +51,7 @@ get_callback() const { */ INLINE bool WeakPointerToVoid:: was_deleted() const { - return _ptr_was_deleted; + return _void_ptr != nullptr && (_weak_ref == nullptr || _weak_ref->was_deleted()); } /** @@ -72,5 +60,5 @@ was_deleted() const { */ INLINE bool WeakPointerToVoid:: is_valid_pointer() const { - return (_void_ptr != (void *)NULL) && !_ptr_was_deleted; + return _weak_ref != nullptr && !_weak_ref->was_deleted(); } diff --git a/panda/src/express/weakPointerToVoid.h b/panda/src/express/weakPointerToVoid.h index 98a481e49e..5b130463e6 100644 --- a/panda/src/express/weakPointerToVoid.h +++ b/panda/src/express/weakPointerToVoid.h @@ -17,6 +17,7 @@ #include "pandabase.h" #include "pointerToVoid.h" #include "weakPointerCallback.h" +#include "weakReferenceList.h" /** * This is the specialization of PointerToVoid for weak pointers. It needs an @@ -27,18 +28,15 @@ protected: INLINE WeakPointerToVoid(); public: - INLINE void mark_deleted(); - - INLINE void set_callback(WeakPointerCallback *callback); - INLINE WeakPointerCallback *get_callback() const; + INLINE void add_callback(WeakPointerCallback *callback) const; + INLINE void remove_callback(WeakPointerCallback *callback) const; PUBLISHED: INLINE bool was_deleted() const; INLINE bool is_valid_pointer() const; protected: - bool _ptr_was_deleted; - WeakPointerCallback *_callback; + mutable WeakReferenceList *_weak_ref; }; #include "weakPointerToVoid.I" diff --git a/panda/src/express/weakReferenceList.I b/panda/src/express/weakReferenceList.I index 661c4c268f..0e4efc8c52 100644 --- a/panda/src/express/weakReferenceList.I +++ b/panda/src/express/weakReferenceList.I @@ -10,3 +10,30 @@ * @author drose * @date 2004-09-27 */ + +/** + * Increases the number of weak references. + */ +INLINE void WeakReferenceList:: +ref() const { + AtomicAdjust::inc(_count); +} + +/** + * Decreases the number of weak references. Returns true if, after this, + * there are still any weak or strong references remaining, or false if this + * structure should be deleted right away. + */ +INLINE bool WeakReferenceList:: +unref() const { + return AtomicAdjust::dec(_count); +} + +/** + * Returns true if the object represented has been deleted, ie. there are only + * weak references left pointing to the object. + */ +INLINE bool WeakReferenceList:: +was_deleted() const { + return AtomicAdjust::get(_count) < _alive_offset; +} diff --git a/panda/src/express/weakReferenceList.cxx b/panda/src/express/weakReferenceList.cxx index cd940b2ecf..f9e92d6009 100644 --- a/panda/src/express/weakReferenceList.cxx +++ b/panda/src/express/weakReferenceList.cxx @@ -19,7 +19,7 @@ * */ WeakReferenceList:: -WeakReferenceList() { +WeakReferenceList() : _count(_alive_offset) { } /** @@ -27,30 +27,33 @@ WeakReferenceList() { */ WeakReferenceList:: ~WeakReferenceList() { - _lock.acquire(); - Pointers::iterator pi; - for (pi = _pointers.begin(); pi != _pointers.end(); ++pi) { - (*pi)->mark_deleted(); - } - _lock.release(); + nassertv(_count == 0); } /** - * Intended to be called only by WeakPointerTo (or by any class implementing a - * weak reference-counting pointer), this adds the indicated PointerToVoid - * structure to the list of such structures that are maintaining a weak - * pointer to this object. + * Adds the callback to the list of callbacks that will be called when the + * underlying pointer is deleted. If it has already been deleted, it will + * be called immediately. * - * When the WeakReferenceList destructs (presumably because its owning object - * destructs), the pointer within the PointerToVoid object will be set to - * NULL. + * The data pointer can be an arbitrary pointer and is passed as only argument + * to the callback. */ void WeakReferenceList:: -add_reference(WeakPointerToVoid *ptv) { - _lock.acquire(); - bool inserted = _pointers.insert(ptv).second; - _lock.release(); - nassertv(inserted); +add_callback(WeakPointerCallback *callback, void *data) { + nassertv(callback != nullptr); + _lock.lock(); + // We need to check again whether the object is deleted after grabbing the + // lock, despite having already done this in weakPointerTo.I, since it may + // have been deleted in the meantime. + bool deleted = was_deleted(); + if (!deleted) { + _callbacks.insert(make_pair(callback, data)); + } + _lock.unlock(); + + if (deleted) { + callback->wp_callback(data); + } } /** @@ -60,13 +63,33 @@ add_reference(WeakPointerToVoid *ptv) { * pointer to this object. */ void WeakReferenceList:: -clear_reference(WeakPointerToVoid *ptv) { - _lock.acquire(); - Pointers::iterator pi = _pointers.find(ptv); - bool valid = (pi != _pointers.end()); - if (valid) { - _pointers.erase(pi); - } - _lock.release(); - nassertv(valid); +remove_callback(WeakPointerCallback *callback) { + nassertv(callback != nullptr); + _lock.lock(); + _callbacks.erase(callback); + _lock.unlock(); +} + +/** + * Called only by the ReferenceCount pointer to indicate that it has been + * deleted. + */ +void WeakReferenceList:: +mark_deleted() { + _lock.lock(); + Callbacks::iterator ci; + for (ci = _callbacks.begin(); ci != _callbacks.end(); ++ci) { + (*ci).first->wp_callback((*ci).second); + } + _callbacks.clear(); + + // Decrement the special offset added to the weak pointer count to indicate + // that it can be deleted when all the weak references have gone. + AtomicAdjust::Integer result = AtomicAdjust::add(_count, -_alive_offset); + _lock.unlock(); + if (result == 0) { + // There are no weak references remaining either, so delete this. + delete this; + } + nassertv(result >= 0); } diff --git a/panda/src/express/weakReferenceList.h b/panda/src/express/weakReferenceList.h index 16651b7364..49f352c103 100644 --- a/panda/src/express/weakReferenceList.h +++ b/panda/src/express/weakReferenceList.h @@ -15,30 +15,48 @@ #define WEAKREFERENCELIST_H #include "pandabase.h" -#include "pset.h" +#include "pmap.h" #include "mutexImpl.h" -class WeakPointerToVoid; +class WeakPointerCallback; /** - * This is a list of WeakPointerTo's that share a reference to a given - * ReferenceCount object. It is stored in a separate class since it is - * assumed that most ReferenceCount objects do not need to store this list at - * all; this avoids bloating every ReferenceCount object in the world with the - * size of this object. + * This is an object shared by all the weak pointers that point to the same + * ReferenceCount object. It is created whenever a weak reference to an + * object is created, and can outlive the object until all weak references + * have disappeared. */ class EXPCL_PANDAEXPRESS WeakReferenceList { public: WeakReferenceList(); ~WeakReferenceList(); - void add_reference(WeakPointerToVoid *ptv); - void clear_reference(WeakPointerToVoid *ptv); + INLINE void ref() const; + INLINE bool unref() const; + INLINE bool was_deleted() const; + + void add_callback(WeakPointerCallback *callback, void *data); + void remove_callback(WeakPointerCallback *callback); private: - typedef pset Pointers; - Pointers _pointers; + void mark_deleted(); + +public: + // This lock protects the callbacks below, but it also protects the object + // from being deleted during a call to WeakPointerTo::lock(). MutexImpl _lock; + +private: + typedef pmap Callbacks; + Callbacks _callbacks; + + // This has a very large number added to it if the object is still alive. + // It could be 1, but having it be a large number makes it easy to check + // whether the object has been deleted or not. + static const AtomicAdjust::Integer _alive_offset = (1 << 30); + mutable AtomicAdjust::Integer _count; + + friend class ReferenceCount; }; #include "weakReferenceList.I" diff --git a/panda/src/ffmpeg/ffmpegVirtualFile.cxx b/panda/src/ffmpeg/ffmpegVirtualFile.cxx index 8819db74bc..b671ce0ba6 100644 --- a/panda/src/ffmpeg/ffmpegVirtualFile.cxx +++ b/panda/src/ffmpeg/ffmpegVirtualFile.cxx @@ -47,22 +47,6 @@ FfmpegVirtualFile:: close(); } -/** - * These objects are not meant to be copied. - */ -FfmpegVirtualFile:: -FfmpegVirtualFile(const FfmpegVirtualFile ©) { - nassertv(false); -} - -/** - * These objects are not meant to be copied. - */ -void FfmpegVirtualFile:: -operator = (const FfmpegVirtualFile ©) { - nassertv(false); -} - /** * Opens the movie file via Panda's VFS. Returns true on success, false on * failure. If successful, use get_format_context() to get the open file @@ -225,7 +209,7 @@ read_packet(void *opaque, uint8_t *buf, int size) { streampos remaining = self->_start + (streampos)self->_size - in->tellg(); if (remaining < ssize) { if (remaining <= 0) { - return 0; + return AVERROR_EOF; } ssize = remaining; diff --git a/panda/src/ffmpeg/ffmpegVirtualFile.h b/panda/src/ffmpeg/ffmpegVirtualFile.h index 746fec67a0..197320d4dc 100644 --- a/panda/src/ffmpeg/ffmpegVirtualFile.h +++ b/panda/src/ffmpeg/ffmpegVirtualFile.h @@ -34,12 +34,11 @@ struct AVFormatContext; class EXPCL_FFMPEG FfmpegVirtualFile { public: FfmpegVirtualFile(); + FfmpegVirtualFile(const FfmpegVirtualFile ©) = delete; ~FfmpegVirtualFile(); -private: - FfmpegVirtualFile(const FfmpegVirtualFile ©); - void operator = (const FfmpegVirtualFile ©); -public: + FfmpegVirtualFile &operator = (const FfmpegVirtualFile ©) = delete; + bool open_vfs(const Filename &filename); bool open_subfile(const SubfileInfo &info); void close(); diff --git a/panda/src/framework/config_framework.cxx b/panda/src/framework/config_framework.cxx index 8746d5bff0..4ddc4b553a 100644 --- a/panda/src/framework/config_framework.cxx +++ b/panda/src/framework/config_framework.cxx @@ -16,12 +16,6 @@ #include "dconfig.h" #include "windowFramework.h" -// By including checkPandaVersion.h, we guarantee that runtime attempts to -// load libframework.so.dll will fail if they inadvertently link with the -// wrong version of libdtool.so.dll. - -#include "checkPandaVersion.h" - #if !defined(CPPPARSER) && !defined(BUILDING_FRAMEWORK) #error Buildsystem error: BUILDING_FRAMEWORK not defined #endif diff --git a/panda/src/glstuff/glCgShaderContext_src.cxx b/panda/src/glstuff/glCgShaderContext_src.cxx index 9f6e242968..23efd27d9a 100644 --- a/panda/src/glstuff/glCgShaderContext_src.cxx +++ b/panda/src/glstuff/glCgShaderContext_src.cxx @@ -436,42 +436,43 @@ set_state_and_transform(const RenderState *target_rs, altered |= Shader::SSD_projection; } - if (_state_rs.was_deleted() || _state_rs == (const RenderState *)NULL) { + CPT(RenderState) state_rs = _state_rs.lock(); + if (state_rs == nullptr) { // Reset all of the state. altered |= Shader::SSD_general; _state_rs = target_rs; - } else if (_state_rs != target_rs) { + } else if (state_rs != target_rs) { // The state has changed since last time. - if (_state_rs->get_attrib(ColorAttrib::get_class_slot()) != + if (state_rs->get_attrib(ColorAttrib::get_class_slot()) != target_rs->get_attrib(ColorAttrib::get_class_slot())) { altered |= Shader::SSD_color; } - if (_state_rs->get_attrib(ColorScaleAttrib::get_class_slot()) != + if (state_rs->get_attrib(ColorScaleAttrib::get_class_slot()) != target_rs->get_attrib(ColorScaleAttrib::get_class_slot())) { altered |= Shader::SSD_colorscale; } - if (_state_rs->get_attrib(MaterialAttrib::get_class_slot()) != + if (state_rs->get_attrib(MaterialAttrib::get_class_slot()) != target_rs->get_attrib(MaterialAttrib::get_class_slot())) { altered |= Shader::SSD_material; } - if (_state_rs->get_attrib(ShaderAttrib::get_class_slot()) != + if (state_rs->get_attrib(ShaderAttrib::get_class_slot()) != target_rs->get_attrib(ShaderAttrib::get_class_slot())) { altered |= Shader::SSD_shaderinputs; } - if (_state_rs->get_attrib(FogAttrib::get_class_slot()) != + if (state_rs->get_attrib(FogAttrib::get_class_slot()) != target_rs->get_attrib(FogAttrib::get_class_slot())) { altered |= Shader::SSD_fog; } - if (_state_rs->get_attrib(LightAttrib::get_class_slot()) != + if (state_rs->get_attrib(LightAttrib::get_class_slot()) != target_rs->get_attrib(LightAttrib::get_class_slot())) { altered |= Shader::SSD_light; } - if (_state_rs->get_attrib(ClipPlaneAttrib::get_class_slot()) != + if (state_rs->get_attrib(ClipPlaneAttrib::get_class_slot()) != target_rs->get_attrib(ClipPlaneAttrib::get_class_slot())) { altered |= Shader::SSD_clip_planes; } - if (_state_rs->get_attrib(TexMatrixAttrib::get_class_slot()) != + if (state_rs->get_attrib(TexMatrixAttrib::get_class_slot()) != target_rs->get_attrib(TexMatrixAttrib::get_class_slot())) { altered |= Shader::SSD_tex_matrix; } diff --git a/panda/src/glstuff/glCgShaderContext_src.h b/panda/src/glstuff/glCgShaderContext_src.h index d5bc721e61..63338b3520 100644 --- a/panda/src/glstuff/glCgShaderContext_src.h +++ b/panda/src/glstuff/glCgShaderContext_src.h @@ -25,7 +25,7 @@ class CLP(GraphicsStateGuardian); /** * xyz */ -class EXPCL_GL CLP(CgShaderContext) FINAL : public ShaderContext { +class EXPCL_GL CLP(CgShaderContext) final : public ShaderContext { public: friend class CLP(GraphicsStateGuardian); diff --git a/panda/src/glstuff/glGeomMunger_src.cxx b/panda/src/glstuff/glGeomMunger_src.cxx index 5a1649f832..eea42762ce 100644 --- a/panda/src/glstuff/glGeomMunger_src.cxx +++ b/panda/src/glstuff/glGeomMunger_src.cxx @@ -39,8 +39,8 @@ CLP(GeomMunger)(GraphicsStateGuardian *gsg, const RenderState *state) : // TexGen object gets deleted. _texture = (const TextureAttrib *)state->get_attrib(TextureAttrib::get_class_slot()); _tex_gen = (const TexGenAttrib *)state->get_attrib(TexGenAttrib::get_class_slot()); - _texture.set_callback(this); - _tex_gen.set_callback(this); + _texture.add_callback(this); + _tex_gen.add_callback(this); } } @@ -56,6 +56,11 @@ CLP(GeomMunger):: (*gci)->remove_munger(this); } _geom_contexts.clear(); + + if ((_flags & F_parallel_arrays) == 0) { + _texture.remove_callback(this); + _tex_gen.remove_callback(this); + } } /** @@ -220,15 +225,15 @@ munge_format_impl(const GeomVertexFormat *orig, } // Put only the used texture coordinates into the interleaved array. - if (_texture != (TextureAttrib *)NULL) { + if (auto texture = _texture.lock()) { typedef pset UsedStages; UsedStages used_stages; - int num_stages = _texture->get_num_on_stages(); + int num_stages = texture->get_num_on_stages(); for (int i = 0; i < num_stages; ++i) { - TextureStage *stage = _texture->get_on_stage(i); - if (_tex_gen == (TexGenAttrib *)NULL || - !_tex_gen->has_stage(stage)) { + TextureStage *stage = texture->get_on_stage(i); + CPT(TexGenAttrib) tex_gen = _tex_gen.lock(); + if (tex_gen == nullptr || !tex_gen->has_stage(stage)) { InternalName *name = stage->get_texcoord_name(); if (used_stages.insert(name).second) { // This is the first time we've encountered this texcoord name. @@ -360,15 +365,15 @@ premunge_format_impl(const GeomVertexFormat *orig) { // Put only the used texture coordinates into the interleaved array. The // others will be kept around, but in a parallel array. - if (_texture != (TextureAttrib *)NULL) { + if (auto texture = _texture.lock()) { typedef pset UsedStages; UsedStages used_stages; - int num_stages = _texture->get_num_on_stages(); + int num_stages = texture->get_num_on_stages(); for (int i = 0; i < num_stages; ++i) { - TextureStage *stage = _texture->get_on_stage(i); - if (_tex_gen == (TexGenAttrib *)NULL || - !_tex_gen->has_stage(stage)) { + TextureStage *stage = texture->get_on_stage(i); + CPT(TexGenAttrib) tex_gen = _tex_gen.lock(); + if (tex_gen == nullptr || !tex_gen->has_stage(stage)) { InternalName *name = stage->get_texcoord_name(); if (used_stages.insert(name).second) { // This is the first time we've encountered this texcoord name. diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index f2c3b30a9b..b5fd39350d 100644 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -1899,46 +1899,47 @@ set_state_and_transform(const RenderState *target_rs, altered |= Shader::SSD_projection; } - if (_state_rs.was_deleted() || _state_rs == (const RenderState *)NULL) { + CPT(RenderState) state_rs = _state_rs.lock(); + if (state_rs == nullptr) { // Reset all of the state. altered |= Shader::SSD_general; _state_rs = target_rs; - } else if (_state_rs != target_rs) { + } else if (state_rs != target_rs) { // The state has changed since last time. - if (_state_rs->get_attrib(ColorAttrib::get_class_slot()) != + if (state_rs->get_attrib(ColorAttrib::get_class_slot()) != target_rs->get_attrib(ColorAttrib::get_class_slot())) { altered |= Shader::SSD_color; } - if (_state_rs->get_attrib(ColorScaleAttrib::get_class_slot()) != + if (state_rs->get_attrib(ColorScaleAttrib::get_class_slot()) != target_rs->get_attrib(ColorScaleAttrib::get_class_slot())) { altered |= Shader::SSD_colorscale; } - if (_state_rs->get_attrib(MaterialAttrib::get_class_slot()) != + if (state_rs->get_attrib(MaterialAttrib::get_class_slot()) != target_rs->get_attrib(MaterialAttrib::get_class_slot())) { altered |= Shader::SSD_material; } - if (_state_rs->get_attrib(ShaderAttrib::get_class_slot()) != + if (state_rs->get_attrib(ShaderAttrib::get_class_slot()) != target_rs->get_attrib(ShaderAttrib::get_class_slot())) { altered |= Shader::SSD_shaderinputs; } - if (_state_rs->get_attrib(FogAttrib::get_class_slot()) != + if (state_rs->get_attrib(FogAttrib::get_class_slot()) != target_rs->get_attrib(FogAttrib::get_class_slot())) { altered |= Shader::SSD_fog; } - if (_state_rs->get_attrib(LightAttrib::get_class_slot()) != + if (state_rs->get_attrib(LightAttrib::get_class_slot()) != target_rs->get_attrib(LightAttrib::get_class_slot())) { altered |= Shader::SSD_light; } - if (_state_rs->get_attrib(ClipPlaneAttrib::get_class_slot()) != + if (state_rs->get_attrib(ClipPlaneAttrib::get_class_slot()) != target_rs->get_attrib(ClipPlaneAttrib::get_class_slot())) { altered |= Shader::SSD_clip_planes; } - if (_state_rs->get_attrib(TexMatrixAttrib::get_class_slot()) != + if (state_rs->get_attrib(TexMatrixAttrib::get_class_slot()) != target_rs->get_attrib(TexMatrixAttrib::get_class_slot())) { altered |= Shader::SSD_tex_matrix; } - if (_state_rs->get_attrib(TextureAttrib::get_class_slot()) != + if (state_rs->get_attrib(TextureAttrib::get_class_slot()) != target_rs->get_attrib(TextureAttrib::get_class_slot())) { altered |= Shader::SSD_texture; } diff --git a/panda/src/glstuff/glShaderContext_src.h b/panda/src/glstuff/glShaderContext_src.h index 9ecfe9ed39..79ceeb713d 100644 --- a/panda/src/glstuff/glShaderContext_src.h +++ b/panda/src/glstuff/glShaderContext_src.h @@ -26,7 +26,7 @@ class CLP(GraphicsStateGuardian); /** * xyz */ -class EXPCL_GL CLP(ShaderContext) FINAL : public ShaderContext { +class EXPCL_GL CLP(ShaderContext) final : public ShaderContext { public: friend class CLP(GraphicsStateGuardian); diff --git a/panda/src/glstuff/glTextureContext_src.h b/panda/src/glstuff/glTextureContext_src.h index 9a345b397d..667e356d60 100644 --- a/panda/src/glstuff/glTextureContext_src.h +++ b/panda/src/glstuff/glTextureContext_src.h @@ -42,7 +42,7 @@ public: #endif #ifdef OPENGLES_1 - static CONSTEXPR bool needs_barrier(GLbitfield barrier) { return false; }; + static constexpr bool needs_barrier(GLbitfield barrier) { return false; }; #else bool needs_barrier(GLbitfield barrier); void mark_incoherent(bool wrote); diff --git a/panda/src/glstuff/glTimerQueryContext_src.cxx b/panda/src/glstuff/glTimerQueryContext_src.cxx index 36cfefb91e..a7b4ecb612 100644 --- a/panda/src/glstuff/glTimerQueryContext_src.cxx +++ b/panda/src/glstuff/glTimerQueryContext_src.cxx @@ -30,9 +30,9 @@ CLP(TimerQueryContext):: // has already shut down, though, too bad. This means we never get to // free this index, but presumably the app is already shutting down // anyway. - if (!_glgsg.was_deleted()) { - LightMutexHolder holder(_glgsg->_lock); - _glgsg->_deleted_queries.push_back(_index); + if (auto glgsg = _glgsg.lock()) { + LightMutexHolder holder(glgsg->_lock); + glgsg->_deleted_queries.push_back(_index); _index = 0; } } diff --git a/panda/src/gobj/adaptiveLru.cxx b/panda/src/gobj/adaptiveLru.cxx index a74fcfcb0d..eb2d945177 100644 --- a/panda/src/gobj/adaptiveLru.cxx +++ b/panda/src/gobj/adaptiveLru.cxx @@ -360,9 +360,9 @@ do_evict_to(size_t target_size, bool hard_evict) { } else { // We must release the lock while we call evict_lru(). - _lock.release(); + _lock.unlock(); page->evict_lru(); - _lock.acquire(); + _lock.lock(); if (_total_size <= target_size) { // We've evicted enough to satisfy our target. diff --git a/panda/src/gobj/geom.I b/panda/src/gobj/geom.I index 413e2de055..0f504f4dac 100644 --- a/panda/src/gobj/geom.I +++ b/panda/src/gobj/geom.I @@ -443,17 +443,15 @@ CacheKey(const CacheKey ©) : { } -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE Geom::CacheKey:: -CacheKey(CacheKey &&from) NOEXCEPT : +CacheKey(CacheKey &&from) noexcept : _source_data(move(from._source_data)), _modifier(move(from._modifier)) { } -#endif // USE_MOVE_SEMANTICS /** * Provides a unique ordering within the map. @@ -493,17 +491,15 @@ CacheEntry(Geom *source, const Geom::CacheKey &key) : { } -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE Geom::CacheEntry:: -CacheEntry(Geom *source, Geom::CacheKey &&key) NOEXCEPT : +CacheEntry(Geom *source, Geom::CacheKey &&key) noexcept : _source(source), _key(move(key)) { } -#endif // USE_MOVE_SEMANTICS /** * diff --git a/panda/src/gobj/geom.h b/panda/src/gobj/geom.h index 50b050e578..41ac95adea 100644 --- a/panda/src/gobj/geom.h +++ b/panda/src/gobj/geom.h @@ -256,9 +256,8 @@ public: INLINE CacheKey(const GeomVertexData *source_data, const GeomMunger *modifier); INLINE CacheKey(const CacheKey ©); -#ifdef USE_MOVE_SEMANTICS - INLINE CacheKey(CacheKey &&from) NOEXCEPT; -#endif + INLINE CacheKey(CacheKey &&from) noexcept; + INLINE bool operator < (const CacheKey &other) const; CPT(GeomVertexData) _source_data; @@ -271,9 +270,8 @@ public: const GeomVertexData *source_data, const GeomMunger *modifier); INLINE CacheEntry(Geom *source, const CacheKey &key); -#ifdef USE_MOVE_SEMANTICS - INLINE CacheEntry(Geom *source, CacheKey &&key) NOEXCEPT; -#endif + INLINE CacheEntry(Geom *source, CacheKey &&key) noexcept; + ALLOC_DELETED_CHAIN(CacheEntry); virtual void evict_callback(); @@ -406,14 +404,13 @@ class EXPCL_PANDA_GOBJ GeomPipelineReader : public GeomEnums { public: INLINE GeomPipelineReader(Thread *current_thread); INLINE GeomPipelineReader(const Geom *object, Thread *current_thread); -private: - GeomPipelineReader(const GeomPipelineReader ©) DELETED; - GeomPipelineReader &operator = (const GeomPipelineReader ©) DELETED_ASSIGN; - -public: + GeomPipelineReader(const GeomPipelineReader ©) = delete; INLINE ~GeomPipelineReader(); + ALLOC_DELETED_CHAIN(GeomPipelineReader); + GeomPipelineReader &operator = (const GeomPipelineReader ©) = delete; + INLINE void set_object(const Geom *object); INLINE const Geom *get_object() const; INLINE Thread *get_current_thread() const; diff --git a/panda/src/gobj/geomMunger.cxx b/panda/src/gobj/geomMunger.cxx index fccbdab0b6..bbbc9e3522 100644 --- a/panda/src/gobj/geomMunger.cxx +++ b/panda/src/gobj/geomMunger.cxx @@ -147,12 +147,9 @@ munge_geom(CPT(Geom) &geom, CPT(GeomVertexData) &data, // Record the new result in the cache. if (entry == (Geom::CacheEntry *)NULL) { // Create a new entry for the result. -#ifdef USE_MOVE_SEMANTICS // We don't need the key anymore, move the pointers into the CacheEntry. entry = new Geom::CacheEntry(orig_geom, move(key)); -#else - entry = new Geom::CacheEntry(orig_geom, key); -#endif + { LightMutexHolder holder(orig_geom->_cache_lock); bool inserted = orig_geom->_cache.insert(Geom::Cache::value_type(&entry->_key, entry)).second; diff --git a/panda/src/gobj/geomPrimitive.h b/panda/src/gobj/geomPrimitive.h index 8748c86799..50cb5695aa 100644 --- a/panda/src/gobj/geomPrimitive.h +++ b/panda/src/gobj/geomPrimitive.h @@ -351,14 +351,13 @@ private: class EXPCL_PANDA_GOBJ GeomPrimitivePipelineReader : public GeomEnums { public: INLINE GeomPrimitivePipelineReader(CPT(GeomPrimitive) object, Thread *current_thread); -private: - GeomPrimitivePipelineReader(const GeomPrimitivePipelineReader ©) DELETED; - GeomPrimitivePipelineReader &operator = (const GeomPrimitivePipelineReader ©) DELETED_ASSIGN; - -public: + GeomPrimitivePipelineReader(const GeomPrimitivePipelineReader ©) = delete; INLINE ~GeomPrimitivePipelineReader(); + ALLOC_DELETED_CHAIN(GeomPrimitivePipelineReader); + GeomPrimitivePipelineReader &operator = (const GeomPrimitivePipelineReader ©) = delete; + INLINE const GeomPrimitive *get_object() const; INLINE Thread *get_current_thread() const; diff --git a/panda/src/gobj/geomVertexArrayData.I b/panda/src/gobj/geomVertexArrayData.I index 624525360d..a9005fde12 100644 --- a/panda/src/gobj/geomVertexArrayData.I +++ b/panda/src/gobj/geomVertexArrayData.I @@ -239,7 +239,7 @@ CData(UsageHint usage_hint) : * */ INLINE GeomVertexArrayData::CData:: -CData(GeomVertexArrayData::CData &&from) NOEXCEPT : +CData(GeomVertexArrayData::CData &&from) noexcept : _usage_hint(move(from._usage_hint)), _buffer(move(from._buffer)), _modified(move(from._modified)), @@ -371,23 +371,6 @@ GeomVertexArrayDataHandle(GeomVertexArrayData *object, #endif } -/** - * Don't attempt to copy these objects. - */ -INLINE GeomVertexArrayDataHandle:: -GeomVertexArrayDataHandle(const GeomVertexArrayDataHandle ©) - : _current_thread(copy._current_thread) { - nassertv(false); -} - -/** - * Don't attempt to copy these objects. - */ -INLINE void GeomVertexArrayDataHandle:: -operator = (const GeomVertexArrayDataHandle &) { - nassertv(false); -} - /** * */ diff --git a/panda/src/gobj/geomVertexArrayData.h b/panda/src/gobj/geomVertexArrayData.h index 4a49d26881..264c9a1971 100644 --- a/panda/src/gobj/geomVertexArrayData.h +++ b/panda/src/gobj/geomVertexArrayData.h @@ -151,7 +151,7 @@ private: class EXPCL_PANDA_GOBJ CData : public CycleData { public: INLINE CData(UsageHint usage_hint = UH_unspecified); - INLINE CData(CData &&from) NOEXCEPT; + INLINE CData(CData &&from) noexcept; INLINE CData(const CData ©); INLINE void operator = (const CData ©); @@ -257,15 +257,17 @@ private: Thread *current_thread); INLINE GeomVertexArrayDataHandle(GeomVertexArrayData *object, Thread *current_thread); - INLINE GeomVertexArrayDataHandle(const GeomVertexArrayDataHandle &); - INLINE void operator = (const GeomVertexArrayDataHandle &); PUBLISHED: INLINE ~GeomVertexArrayDataHandle(); public: + GeomVertexArrayDataHandle(const GeomVertexArrayDataHandle &) = delete; + ALLOC_DELETED_CHAIN_DECL(GeomVertexArrayDataHandle); + GeomVertexArrayDataHandle &operator = (const GeomVertexArrayDataHandle &) = delete; + INLINE Thread *get_current_thread() const; INLINE const unsigned char *get_read_pointer(bool force) const RETURNS_ALIGNED(MEMORY_HOOK_ALIGNMENT); diff --git a/panda/src/gobj/geomVertexArrayFormat.cxx b/panda/src/gobj/geomVertexArrayFormat.cxx index 20568fa1a3..c8adfa81eb 100644 --- a/panda/src/gobj/geomVertexArrayFormat.cxx +++ b/panda/src/gobj/geomVertexArrayFormat.cxx @@ -52,7 +52,7 @@ GeomVertexArrayFormat(CPT_InternalName name0, int num_components0, _divisor(0), _columns_unsorted(false) { - add_column(MOVE(name0), num_components0, numeric_type0, contents0); + add_column(move(name0), num_components0, numeric_type0, contents0); } /** @@ -72,8 +72,8 @@ GeomVertexArrayFormat(CPT_InternalName name0, int num_components0, _divisor(0), _columns_unsorted(false) { - add_column(MOVE(name0), num_components0, numeric_type0, contents0); - add_column(MOVE(name1), num_components1, numeric_type1, contents1); + add_column(move(name0), num_components0, numeric_type0, contents0); + add_column(move(name1), num_components1, numeric_type1, contents1); } /** @@ -96,9 +96,9 @@ GeomVertexArrayFormat(CPT_InternalName name0, int num_components0, _divisor(0), _columns_unsorted(false) { - add_column(MOVE(name0), num_components0, numeric_type0, contents0); - add_column(MOVE(name1), num_components1, numeric_type1, contents1); - add_column(MOVE(name2), num_components2, numeric_type2, contents2); + add_column(move(name0), num_components0, numeric_type0, contents0); + add_column(move(name1), num_components1, numeric_type1, contents1); + add_column(move(name2), num_components2, numeric_type2, contents2); } /** @@ -124,10 +124,10 @@ GeomVertexArrayFormat(CPT_InternalName name0, int num_components0, _divisor(0), _columns_unsorted(false) { - add_column(MOVE(name0), num_components0, numeric_type0, contents0); - add_column(MOVE(name1), num_components1, numeric_type1, contents1); - add_column(MOVE(name2), num_components2, numeric_type2, contents2); - add_column(MOVE(name3), num_components3, numeric_type3, contents3); + add_column(move(name0), num_components0, numeric_type0, contents0); + add_column(move(name1), num_components1, numeric_type1, contents1); + add_column(move(name2), num_components2, numeric_type2, contents2); + add_column(move(name3), num_components3, numeric_type3, contents3); } /** @@ -219,7 +219,7 @@ add_column(CPT_InternalName name, int num_components, start = _total_bytes; } - return add_column(GeomVertexColumn(MOVE(name), num_components, numeric_type, contents, + return add_column(GeomVertexColumn(move(name), num_components, numeric_type, contents, start, column_alignment)); } diff --git a/panda/src/gobj/geomVertexArrayFormat.h b/panda/src/gobj/geomVertexArrayFormat.h index 3b8ca3a221..fbd697fe3a 100644 --- a/panda/src/gobj/geomVertexArrayFormat.h +++ b/panda/src/gobj/geomVertexArrayFormat.h @@ -44,7 +44,7 @@ class BamReader; * "normal", "texcoord", and "color"; other kinds of data may be piggybacked * into the data record simply by choosing a unique name. */ -class EXPCL_PANDA_GOBJ GeomVertexArrayFormat FINAL : public TypedWritableReferenceCount, public GeomEnums { +class EXPCL_PANDA_GOBJ GeomVertexArrayFormat final : public TypedWritableReferenceCount, public GeomEnums { PUBLISHED: GeomVertexArrayFormat(); GeomVertexArrayFormat(const GeomVertexArrayFormat ©); diff --git a/panda/src/gobj/geomVertexColumn.I b/panda/src/gobj/geomVertexColumn.I index 4d6c5c3b68..262c19c3a2 100644 --- a/panda/src/gobj/geomVertexColumn.I +++ b/panda/src/gobj/geomVertexColumn.I @@ -28,7 +28,7 @@ GeomVertexColumn(CPT_InternalName name, int num_components, NumericType numeric_type, Contents contents, int start, int column_alignment, int num_elements, int element_stride) : - _name(MOVE(name)), + _name(std::move(name)), _num_components(num_components), _numeric_type(numeric_type), _contents(contents), diff --git a/panda/src/gobj/geomVertexColumn.h b/panda/src/gobj/geomVertexColumn.h index 5e8df9821e..6e31233946 100644 --- a/panda/src/gobj/geomVertexColumn.h +++ b/panda/src/gobj/geomVertexColumn.h @@ -342,7 +342,7 @@ private: } }; - class Packer_nativedouble_3 FINAL : public Packer_float64_3 { + class Packer_nativedouble_3 final : public Packer_float64_3 { public: virtual const LVecBase3d &get_data3d(const unsigned char *pointer); @@ -351,7 +351,7 @@ private: } }; - class Packer_point_nativedouble_2 FINAL : public Packer_point_float64_2 { + class Packer_point_nativedouble_2 final : public Packer_point_float64_2 { public: virtual const LVecBase2d &get_data2d(const unsigned char *pointer); @@ -360,7 +360,7 @@ private: } }; - class Packer_point_nativedouble_3 FINAL : public Packer_point_float64_3 { + class Packer_point_nativedouble_3 final : public Packer_point_float64_3 { public: virtual const LVecBase3d &get_data3d(const unsigned char *pointer); @@ -378,7 +378,7 @@ private: } }; - class Packer_argb_packed FINAL : public Packer_color { + class Packer_argb_packed final : public Packer_color { public: virtual const LVecBase4f &get_data4f(const unsigned char *pointer); virtual void set_data4f(unsigned char *pointer, const LVecBase4f &value); @@ -388,7 +388,7 @@ private: } }; - class Packer_rgba_uint8_4 FINAL : public Packer_color { + class Packer_rgba_uint8_4 final : public Packer_color { public: virtual const LVecBase4f &get_data4f(const unsigned char *pointer); virtual void set_data4f(unsigned char *pointer, const LVecBase4f &value); @@ -408,7 +408,7 @@ private: } }; - class Packer_rgba_nativefloat_4 FINAL : public Packer_rgba_float32_4 { + class Packer_rgba_nativefloat_4 final : public Packer_rgba_float32_4 { public: virtual const LVecBase4f &get_data4f(const unsigned char *pointer); @@ -417,7 +417,7 @@ private: } }; - class Packer_uint16_1 FINAL : public Packer { + class Packer_uint16_1 final : public Packer { public: virtual int get_data1i(const unsigned char *pointer); virtual void set_data1i(unsigned char *pointer, int value); diff --git a/panda/src/gobj/geomVertexData.I b/panda/src/gobj/geomVertexData.I index 5a24b166a5..849a3548f3 100644 --- a/panda/src/gobj/geomVertexData.I +++ b/panda/src/gobj/geomVertexData.I @@ -519,16 +519,14 @@ CacheKey(const CacheKey ©) : { } -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE GeomVertexData::CacheKey:: -CacheKey(CacheKey &&from) NOEXCEPT : - _modifier(move(from._modifier)) +CacheKey(CacheKey &&from) noexcept : + _modifier(std::move(from._modifier)) { } -#endif // USE_MOVE_SEMANTICS /** * Provides a unique ordering within the set. @@ -558,17 +556,15 @@ CacheEntry(GeomVertexData *source, const CacheKey &key) : { } -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE GeomVertexData::CacheEntry:: -CacheEntry(GeomVertexData *source, CacheKey &&key) NOEXCEPT : +CacheEntry(GeomVertexData *source, CacheKey &&key) noexcept : _source(source), - _key(move(key)) + _key(std::move(key)) { } -#endif // USE_MOVE_SEMANTICS /** * diff --git a/panda/src/gobj/geomVertexData.cxx b/panda/src/gobj/geomVertexData.cxx index 7d8e0e63f3..05992e5378 100644 --- a/panda/src/gobj/geomVertexData.cxx +++ b/panda/src/gobj/geomVertexData.cxx @@ -760,12 +760,9 @@ convert_to(const GeomVertexFormat *new_format) const { // Record the new result in the cache. if (entry == (CacheEntry *)NULL) { // Create a new entry for the result. -#ifdef USE_MOVE_SEMANTICS // We don't need the key anymore, move the pointers into the CacheEntry. entry = new CacheEntry((GeomVertexData *)this, move(key)); -#else - entry = new CacheEntry((GeomVertexData *)this, key); -#endif + { LightMutexHolder holder(_cache_lock); bool inserted = ((GeomVertexData *)this)->_cache.insert(Cache::value_type(&entry->_key, entry)).second; diff --git a/panda/src/gobj/geomVertexData.h b/panda/src/gobj/geomVertexData.h index d86dd36fc4..2a7db8115b 100644 --- a/panda/src/gobj/geomVertexData.h +++ b/panda/src/gobj/geomVertexData.h @@ -246,9 +246,7 @@ public: public: INLINE CacheKey(const GeomVertexFormat *modifier); INLINE CacheKey(const CacheKey ©); -#ifdef USE_MOVE_SEMANTICS - INLINE CacheKey(CacheKey &&from) NOEXCEPT; -#endif + INLINE CacheKey(CacheKey &&from) noexcept; INLINE bool operator < (const CacheKey &other) const; @@ -260,9 +258,8 @@ public: INLINE CacheEntry(GeomVertexData *source, const GeomVertexFormat *modifier); INLINE CacheEntry(GeomVertexData *source, const CacheKey &key); -#ifdef USE_MOVE_SEMANTICS - INLINE CacheEntry(GeomVertexData *source, CacheKey &&key) NOEXCEPT; -#endif + INLINE CacheEntry(GeomVertexData *source, CacheKey &&key) noexcept; + ALLOC_DELETED_CHAIN(CacheEntry); virtual void evict_callback(); @@ -410,14 +407,12 @@ protected: Thread *current_thread, GeomVertexData::CData *cdata); -private: - GeomVertexDataPipelineBase(const GeomVertexDataPipelineBase ©) DELETED; - GeomVertexDataPipelineBase &operator = (const GeomVertexDataPipelineBase ©) DELETED_ASSIGN; - public: + GeomVertexDataPipelineBase(const GeomVertexDataPipelineBase ©) = delete; INLINE ~GeomVertexDataPipelineBase(); -public: + GeomVertexDataPipelineBase &operator = (const GeomVertexDataPipelineBase ©) = delete; + INLINE Thread *get_current_thread() const; INLINE const GeomVertexFormat *get_format() const; diff --git a/panda/src/gobj/geomVertexFormat.h b/panda/src/gobj/geomVertexFormat.h index aa2ef4606a..6e4f668436 100644 --- a/panda/src/gobj/geomVertexFormat.h +++ b/panda/src/gobj/geomVertexFormat.h @@ -52,7 +52,7 @@ class GeomMunger; * standard and/or user-defined columns in your custom GeomVertexFormat * constructions. */ -class EXPCL_PANDA_GOBJ GeomVertexFormat FINAL : public TypedWritableReferenceCount, public GeomEnums { +class EXPCL_PANDA_GOBJ GeomVertexFormat final : public TypedWritableReferenceCount, public GeomEnums { PUBLISHED: GeomVertexFormat(); GeomVertexFormat(const GeomVertexArrayFormat *array_format); diff --git a/panda/src/gobj/geomVertexReader.I b/panda/src/gobj/geomVertexReader.I index 810f7e8f33..412bfa611d 100644 --- a/panda/src/gobj/geomVertexReader.I +++ b/panda/src/gobj/geomVertexReader.I @@ -50,7 +50,7 @@ GeomVertexReader(const GeomVertexData *vertex_data, _current_thread(current_thread) { initialize(); - set_column(MOVE(name)); + set_column(std::move(name)); } /** diff --git a/panda/src/gobj/geomVertexRewriter.I b/panda/src/gobj/geomVertexRewriter.I index 933c545885..ac092d6979 100644 --- a/panda/src/gobj/geomVertexRewriter.I +++ b/panda/src/gobj/geomVertexRewriter.I @@ -45,7 +45,7 @@ GeomVertexRewriter(GeomVertexData *vertex_data, CPT_InternalName name, GeomVertexWriter(vertex_data, current_thread), GeomVertexReader(vertex_data, current_thread) { - set_column(MOVE(name)); + set_column(std::move(name)); } /** @@ -184,7 +184,7 @@ set_column(CPT_InternalName name) { // It's important to invoke the writer first, then the reader. See // set_row(). GeomVertexWriter::set_column(name); - return GeomVertexReader::set_column(MOVE(name)); + return GeomVertexReader::set_column(std::move(name)); } /** diff --git a/panda/src/gobj/geomVertexWriter.I b/panda/src/gobj/geomVertexWriter.I index d3e1da87a3..f21280c3ad 100644 --- a/panda/src/gobj/geomVertexWriter.I +++ b/panda/src/gobj/geomVertexWriter.I @@ -48,7 +48,7 @@ GeomVertexWriter(GeomVertexData *vertex_data, CPT_InternalName name, _current_thread(current_thread) { initialize(); - set_column(MOVE(name)); + set_column(std::move(name)); } /** diff --git a/panda/src/gobj/internalName.I b/panda/src/gobj/internalName.I index 69e88c4563..d7475550e9 100644 --- a/panda/src/gobj/internalName.I +++ b/panda/src/gobj/internalName.I @@ -422,13 +422,12 @@ CPT_InternalName(const char (&literal)[N]) : { } -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE CPT_InternalName:: -CPT_InternalName(PointerTo &&from) NOEXCEPT : - ConstPointerTo(move(from)) +CPT_InternalName(PointerTo &&from) noexcept : + ConstPointerTo(std::move(from)) { } @@ -436,8 +435,8 @@ CPT_InternalName(PointerTo &&from) NOEXCEPT : * */ INLINE CPT_InternalName:: -CPT_InternalName(ConstPointerTo &&from) NOEXCEPT : - ConstPointerTo(move(from)) +CPT_InternalName(ConstPointerTo &&from) noexcept : + ConstPointerTo(std::move(from)) { } @@ -445,8 +444,8 @@ CPT_InternalName(ConstPointerTo &&from) NOEXCEPT : * */ INLINE CPT_InternalName &CPT_InternalName:: -operator = (PointerTo &&from) NOEXCEPT { - this->reassign(move(from)); +operator = (PointerTo &&from) noexcept { + this->reassign(std::move(from)); return *this; } @@ -454,11 +453,10 @@ operator = (PointerTo &&from) NOEXCEPT { * */ INLINE CPT_InternalName &CPT_InternalName:: -operator = (ConstPointerTo &&from) NOEXCEPT { - this->reassign(move(from)); +operator = (ConstPointerTo &&from) noexcept { + this->reassign(std::move(from)); return *this; } -#endif // USE_MOVE_SEMANTICS /** * diff --git a/panda/src/gobj/internalName.h b/panda/src/gobj/internalName.h index eff928b668..7706723021 100644 --- a/panda/src/gobj/internalName.h +++ b/panda/src/gobj/internalName.h @@ -35,7 +35,7 @@ class FactoryParams; * composition of one or more other names, or by giving it a source string * directly. */ -class EXPCL_PANDA_GOBJ InternalName FINAL : public TypedWritableReferenceCount { +class EXPCL_PANDA_GOBJ InternalName final : public TypedWritableReferenceCount { private: InternalName(InternalName *parent, const string &basename); @@ -198,25 +198,22 @@ class CPT_InternalName : public ConstPointerTo { public: INLINE CPT_InternalName(const To *ptr = (const To *)NULL); INLINE CPT_InternalName(const PointerTo ©); + INLINE CPT_InternalName(PointerTo &&from) noexcept; INLINE CPT_InternalName(const ConstPointerTo ©); + INLINE CPT_InternalName(ConstPointerTo &&from) noexcept; INLINE CPT_InternalName(const string &name); template INLINE CPT_InternalName(const char (&literal)[N]); -#ifdef USE_MOVE_SEMANTICS - INLINE CPT_InternalName(PointerTo &&from) NOEXCEPT; - INLINE CPT_InternalName(ConstPointerTo &&from) NOEXCEPT; - INLINE CPT_InternalName &operator = (PointerTo &&from) NOEXCEPT; - INLINE CPT_InternalName &operator = (ConstPointerTo &&from) NOEXCEPT; -#endif // USE_MOVE_SEMANTICS - INLINE CPT_InternalName &operator = (const To *ptr); INLINE CPT_InternalName &operator = (const PointerTo ©); INLINE CPT_InternalName &operator = (const ConstPointerTo ©); + INLINE CPT_InternalName &operator = (PointerTo &&from) noexcept; + INLINE CPT_InternalName &operator = (ConstPointerTo &&from) noexcept; }; -INLINE void swap(CPT_InternalName &one, CPT_InternalName &two) NOEXCEPT { +INLINE void swap(CPT_InternalName &one, CPT_InternalName &two) noexcept { one.swap(two); } #endif // CPPPARSER diff --git a/panda/src/gobj/preparedGraphicsObjects.h b/panda/src/gobj/preparedGraphicsObjects.h index 3eaed37167..3d673b615b 100644 --- a/panda/src/gobj/preparedGraphicsObjects.h +++ b/panda/src/gobj/preparedGraphicsObjects.h @@ -164,7 +164,7 @@ public: * This is a handle to an enqueued object, from which the result can be * obtained upon completion. */ - class EXPCL_PANDA_GOBJ EnqueuedObject FINAL : public AsyncFuture { + class EXPCL_PANDA_GOBJ EnqueuedObject final : public AsyncFuture { public: EnqueuedObject(PreparedGraphicsObjects *pgo, TypedWritableReferenceCount *object); @@ -173,7 +173,7 @@ public: void set_result(SavedContext *result); void notify_removed(); - virtual bool cancel() FINAL; + virtual bool cancel() final; PUBLISHED: MAKE_PROPERTY(object, get_object); diff --git a/panda/src/gobj/shaderBuffer.h b/panda/src/gobj/shaderBuffer.h index 8d48fed425..53c110048b 100644 --- a/panda/src/gobj/shaderBuffer.h +++ b/panda/src/gobj/shaderBuffer.h @@ -29,7 +29,7 @@ class PreparedGraphicsObjects; */ class EXPCL_PANDA_GOBJ ShaderBuffer : public TypedWritableReferenceCount, public Namable, public GeomEnums { private: - INLINE ShaderBuffer() DEFAULT_CTOR; + INLINE ShaderBuffer() = default; PUBLISHED: ~ShaderBuffer(); diff --git a/panda/src/gobj/simpleLru.cxx b/panda/src/gobj/simpleLru.cxx index 97e979df63..8531c321bc 100644 --- a/panda/src/gobj/simpleLru.cxx +++ b/panda/src/gobj/simpleLru.cxx @@ -169,9 +169,9 @@ do_evict_to(size_t target_size, bool hard_evict) { SimpleLruPage *next = (SimpleLruPage *)node->_next; // We must release the lock while we call evict_lru(). - _global_lock.release(); + _global_lock.unlock(); node->evict_lru(); - _global_lock.acquire(); + _global_lock.lock(); if (node == end || node == _prev) { // If we reach the original tail of the list, stop. diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index fa85fd44f0..d48c6a7c73 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -4895,14 +4895,14 @@ do_read_ktx(CData *cdata, istream &in, const string &filename, bool header_only) } } - do_set_ram_mipmap_image(cdata, (int)n, MOVE(image), + do_set_ram_mipmap_image(cdata, (int)n, move(image), row_size * do_get_expected_mipmap_y_size(cdata, (int)n)); } else { // Compressed image. We'll trust that the file has the right size. image = PTA_uchar::empty_array(image_size); ktx.extract_bytes(image.p(), image_size); - do_set_ram_mipmap_image(cdata, (int)n, MOVE(image), image_size / depth); + do_set_ram_mipmap_image(cdata, (int)n, move(image), image_size / depth); } ktx.skip_bytes(3 - ((image_size + 3) & 3)); @@ -5239,14 +5239,14 @@ unlocked_ensure_ram_image(bool allow_compression) { PT(Texture) tex = do_make_copy(cdata); _cycler.release_read(cdata); - _lock.release(); + _lock.unlock(); // Perform the actual reload in a copy of the texture, while our own mutex // is left unlocked. CDWriter cdata_tex(tex->_cycler, true); tex->do_reload_ram_image(cdata_tex, allow_compression); - _lock.acquire(); + _lock.lock(); CData *cdataw = _cycler.write_upstream(false, current_thread); diff --git a/panda/src/gobj/texture_ext.cxx b/panda/src/gobj/texture_ext.cxx index e81d40c15f..3cd291843f 100644 --- a/panda/src/gobj/texture_ext.cxx +++ b/panda/src/gobj/texture_ext.cxx @@ -77,7 +77,7 @@ set_ram_image(PyObject *image, Texture::CompressionMode compression, PTA_uchar data = PTA_uchar::empty_array(view.len, Texture::get_class_type()); memcpy(data.p(), view.buf, view.len); - _this->set_ram_image(MOVE(data), compression, page_size); + _this->set_ram_image(move(data), compression, page_size); PyBuffer_Release(&view); return; @@ -102,7 +102,7 @@ set_ram_image(PyObject *image, Texture::CompressionMode compression, PTA_uchar data = PTA_uchar::empty_array(buffer_len, Texture::get_class_type()); memcpy(data.p(), buffer, buffer_len); - _this->set_ram_image(MOVE(data), compression, page_size); + _this->set_ram_image(move(data), compression, page_size); return; } #endif @@ -155,7 +155,7 @@ set_ram_image_as(PyObject *image, const string &provided_format) { PTA_uchar data = PTA_uchar::empty_array(view.len, Texture::get_class_type()); memcpy(data.p(), view.buf, view.len); - _this->set_ram_image_as(MOVE(data), provided_format); + _this->set_ram_image_as(move(data), provided_format); PyBuffer_Release(&view); return; diff --git a/panda/src/gobj/vertexDataSaveFile.cxx b/panda/src/gobj/vertexDataSaveFile.cxx index fd7087ba5d..e602b51129 100644 --- a/panda/src/gobj/vertexDataSaveFile.cxx +++ b/panda/src/gobj/vertexDataSaveFile.cxx @@ -23,7 +23,7 @@ #include #endif // _WIN32 -#if defined(__ANDROID__) && !defined(HAVE_LOCKF) +#if defined(__ANDROID__) && !defined(PHAVE_LOCKF) // Needed for flock. #include #endif @@ -130,7 +130,7 @@ VertexDataSaveFile(const Filename &directory, const string &prefix, // Now try to lock the file, so we can be sure that no other process is // simultaneously writing to the same save file. -#ifdef HAVE_LOCKF +#ifdef PHAVE_LOCKF int result = lockf(_fd, F_TLOCK, 0); #else int result = flock(_fd, LOCK_EX | LOCK_NB); diff --git a/panda/src/gobj/vertexTransform.h b/panda/src/gobj/vertexTransform.h index 51e84c9edb..ff106bf56e 100644 --- a/panda/src/gobj/vertexTransform.h +++ b/panda/src/gobj/vertexTransform.h @@ -67,6 +67,7 @@ private: virtual int complete_pointers(TypedWritable **plist, BamReader *manager); virtual void fillin(DatagramIterator &scan, BamReader *manager); virtual TypeHandle get_parent_type() const { + VertexTransform::init_type(); return VertexTransform::get_class_type(); } diff --git a/panda/src/grutil/movieTexture.cxx b/panda/src/grutil/movieTexture.cxx index a2d8d3bc3a..8f2850380b 100644 --- a/panda/src/grutil/movieTexture.cxx +++ b/panda/src/grutil/movieTexture.cxx @@ -92,17 +92,6 @@ make_copy() const { return new CData(*this); } -/** - * Use MovieTexture::make_copy() to make a duplicate copy of an existing - * MovieTexture. - */ -MovieTexture:: -MovieTexture(const MovieTexture ©) : - Texture(copy) -{ - nassertv(false); -} - /** * xxx */ diff --git a/panda/src/grutil/movieTexture.h b/panda/src/grutil/movieTexture.h index d719f21d87..0881552036 100644 --- a/panda/src/grutil/movieTexture.h +++ b/panda/src/grutil/movieTexture.h @@ -34,9 +34,7 @@ class EXPCL_PANDA_GRUTIL MovieTexture : public Texture { PUBLISHED: explicit MovieTexture(const string &name); explicit MovieTexture(MovieVideo *video); -private: - MovieTexture(const MovieTexture ©); -PUBLISHED: + MovieTexture(const MovieTexture ©) = delete; virtual ~MovieTexture(); INLINE double get_video_length() const; diff --git a/panda/src/grutil/pipeOcclusionCullTraverser.cxx b/panda/src/grutil/pipeOcclusionCullTraverser.cxx index 1052d5ace5..d257611767 100644 --- a/panda/src/grutil/pipeOcclusionCullTraverser.cxx +++ b/panda/src/grutil/pipeOcclusionCullTraverser.cxx @@ -119,16 +119,6 @@ PipeOcclusionCullTraverser(GraphicsOutput *host) { _live = true; } -/** - * - */ -PipeOcclusionCullTraverser:: -PipeOcclusionCullTraverser(const PipeOcclusionCullTraverser ©) : - CullTraverser(copy) -{ - nassertv(false); -} - /** * */ diff --git a/panda/src/grutil/pipeOcclusionCullTraverser.h b/panda/src/grutil/pipeOcclusionCullTraverser.h index 55d2a795ce..d41c5acff4 100644 --- a/panda/src/grutil/pipeOcclusionCullTraverser.h +++ b/panda/src/grutil/pipeOcclusionCullTraverser.h @@ -42,7 +42,7 @@ class EXPCL_PANDA_GRUTIL PipeOcclusionCullTraverser : public CullTraverser, public CullHandler { PUBLISHED: explicit PipeOcclusionCullTraverser(GraphicsOutput *host); - PipeOcclusionCullTraverser(const PipeOcclusionCullTraverser ©); + PipeOcclusionCullTraverser(const PipeOcclusionCullTraverser ©) = delete; virtual void set_scene(SceneSetup *scene_setup, GraphicsStateGuardianBase *gsg, diff --git a/panda/src/linmath/lpoint2_src.h b/panda/src/linmath/lpoint2_src.h index 090b49d4b9..fef5c791f9 100644 --- a/panda/src/linmath/lpoint2_src.h +++ b/panda/src/linmath/lpoint2_src.h @@ -17,7 +17,7 @@ class EXPCL_PANDA_LINMATH FLOATNAME(LPoint2) : public FLOATNAME(LVecBase2) { PUBLISHED: - INLINE_LINMATH FLOATNAME(LPoint2)() DEFAULT_CTOR; + INLINE_LINMATH FLOATNAME(LPoint2)() = default; INLINE_LINMATH FLOATNAME(LPoint2)(const FLOATNAME(LVecBase2)& copy); INLINE_LINMATH FLOATNAME(LPoint2)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LPoint2)(FLOATTYPE x, FLOATTYPE y); diff --git a/panda/src/linmath/lpoint3_src.h b/panda/src/linmath/lpoint3_src.h index 3465fc37d1..5089e81c9e 100644 --- a/panda/src/linmath/lpoint3_src.h +++ b/panda/src/linmath/lpoint3_src.h @@ -20,7 +20,7 @@ */ class EXPCL_PANDA_LINMATH FLOATNAME(LPoint3) : public FLOATNAME(LVecBase3) { PUBLISHED: - INLINE_LINMATH FLOATNAME(LPoint3)() DEFAULT_CTOR; + INLINE_LINMATH FLOATNAME(LPoint3)() = default; INLINE_LINMATH FLOATNAME(LPoint3)(const FLOATNAME(LVecBase3) ©); INLINE_LINMATH FLOATNAME(LPoint3)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LPoint3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); diff --git a/panda/src/linmath/lpoint4_src.h b/panda/src/linmath/lpoint4_src.h index 103c018738..1eda6fa4fe 100644 --- a/panda/src/linmath/lpoint4_src.h +++ b/panda/src/linmath/lpoint4_src.h @@ -16,7 +16,7 @@ */ class EXPCL_PANDA_LINMATH FLOATNAME(LPoint4) : public FLOATNAME(LVecBase4) { PUBLISHED: - INLINE_LINMATH FLOATNAME(LPoint4)() DEFAULT_CTOR; + INLINE_LINMATH FLOATNAME(LPoint4)() = default; INLINE_LINMATH FLOATNAME(LPoint4)(const FLOATNAME(LVecBase4) ©); INLINE_LINMATH FLOATNAME(LPoint4)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LPoint4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); diff --git a/panda/src/linmath/lvecBase2_src.h b/panda/src/linmath/lvecBase2_src.h index d0c0693f55..5d35293544 100644 --- a/panda/src/linmath/lvecBase2_src.h +++ b/panda/src/linmath/lvecBase2_src.h @@ -30,7 +30,7 @@ PUBLISHED: #endif }; - INLINE_LINMATH FLOATNAME(LVecBase2)() DEFAULT_CTOR; + INLINE_LINMATH FLOATNAME(LVecBase2)() = default; INLINE_LINMATH FLOATNAME(LVecBase2)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LVecBase2)(FLOATTYPE x, FLOATTYPE y); ALLOC_DELETED_CHAIN(FLOATNAME(LVecBase2)); @@ -50,7 +50,7 @@ PUBLISHED: INLINE_LINMATH FLOATTYPE operator [](int i) const; INLINE_LINMATH FLOATTYPE &operator [](int i); - CONSTEXPR static int size() { return 2; } + constexpr static int size() { return 2; } INLINE_LINMATH bool is_nan() const; @@ -74,7 +74,7 @@ PUBLISHED: INLINE_LINMATH void add_y(FLOATTYPE value); INLINE_LINMATH const FLOATTYPE *get_data() const; - CONSTEXPR static int get_num_components() { return 2; } + constexpr static int get_num_components() { return 2; } public: INLINE_LINMATH iterator begin(); diff --git a/panda/src/linmath/lvecBase3_src.h b/panda/src/linmath/lvecBase3_src.h index fb9b67ca27..5def855cdd 100644 --- a/panda/src/linmath/lvecBase3_src.h +++ b/panda/src/linmath/lvecBase3_src.h @@ -30,7 +30,7 @@ PUBLISHED: #endif }; - INLINE_LINMATH FLOATNAME(LVecBase3)() DEFAULT_CTOR; + INLINE_LINMATH FLOATNAME(LVecBase3)() = default; INLINE_LINMATH FLOATNAME(LVecBase3)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LVecBase3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); INLINE_LINMATH FLOATNAME(LVecBase3)(const FLOATNAME(LVecBase2) ©, FLOATTYPE z); @@ -52,7 +52,7 @@ PUBLISHED: INLINE_LINMATH FLOATTYPE operator [](int i) const; INLINE_LINMATH FLOATTYPE &operator [](int i); - CONSTEXPR static int size() { return 3; } + constexpr static int size() { return 3; } INLINE_LINMATH bool is_nan() const; @@ -87,7 +87,7 @@ PUBLISHED: INLINE_LINMATH void add_z(FLOATTYPE value); INLINE_LINMATH const FLOATTYPE *get_data() const; - CONSTEXPR static int get_num_components() { return 3; } + constexpr static int get_num_components() { return 3; } public: INLINE_LINMATH iterator begin(); diff --git a/panda/src/linmath/lvecBase4_src.h b/panda/src/linmath/lvecBase4_src.h index d04201d988..b76d89a7ae 100644 --- a/panda/src/linmath/lvecBase4_src.h +++ b/panda/src/linmath/lvecBase4_src.h @@ -36,7 +36,7 @@ PUBLISHED: #endif }; - INLINE_LINMATH FLOATNAME(LVecBase4)() DEFAULT_CTOR; + INLINE_LINMATH FLOATNAME(LVecBase4)() = default; INLINE_LINMATH FLOATNAME(LVecBase4)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LVecBase4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); INLINE_LINMATH FLOATNAME(LVecBase4)(const FLOATNAME(UnalignedLVecBase4) ©); @@ -62,7 +62,7 @@ PUBLISHED: INLINE_LINMATH FLOATTYPE operator [](int i) const; INLINE_LINMATH FLOATTYPE &operator [](int i); - CONSTEXPR static int size() { return 4; } + constexpr static int size() { return 4; } INLINE_LINMATH bool is_nan() const; @@ -100,7 +100,7 @@ PUBLISHED: INLINE_LINMATH void add_w(FLOATTYPE value); INLINE_LINMATH const FLOATTYPE *get_data() const; - CONSTEXPR static int get_num_components() { return 4; } + constexpr static int get_num_components() { return 4; } INLINE_LINMATH void extract_data(float*){}; public: @@ -228,7 +228,7 @@ PUBLISHED: #endif }; - INLINE_LINMATH FLOATNAME(UnalignedLVecBase4)() DEFAULT_CTOR; + INLINE_LINMATH FLOATNAME(UnalignedLVecBase4)() = default; INLINE_LINMATH FLOATNAME(UnalignedLVecBase4)(const FLOATNAME(LVecBase4) ©); INLINE_LINMATH FLOATNAME(UnalignedLVecBase4)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(UnalignedLVecBase4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); @@ -238,10 +238,10 @@ PUBLISHED: INLINE_LINMATH FLOATTYPE operator [](int i) const; INLINE_LINMATH FLOATTYPE &operator [](int i); - CONSTEXPR static int size() { return 4; } + constexpr static int size() { return 4; } INLINE_LINMATH const FLOATTYPE *get_data() const; - CONSTEXPR static int get_num_components() { return 4; } + constexpr static int get_num_components() { return 4; } INLINE_LINMATH bool operator == (const FLOATNAME(UnalignedLVecBase4) &other) const; INLINE_LINMATH bool operator != (const FLOATNAME(UnalignedLVecBase4) &other) const; diff --git a/panda/src/linmath/lvector2_src.h b/panda/src/linmath/lvector2_src.h index 4a78cc7519..9b6020e00a 100644 --- a/panda/src/linmath/lvector2_src.h +++ b/panda/src/linmath/lvector2_src.h @@ -17,7 +17,7 @@ class EXPCL_PANDA_LINMATH FLOATNAME(LVector2) : public FLOATNAME(LVecBase2) { PUBLISHED: - INLINE_LINMATH FLOATNAME(LVector2)() DEFAULT_CTOR; + INLINE_LINMATH FLOATNAME(LVector2)() = default; INLINE_LINMATH FLOATNAME(LVector2)(const FLOATNAME(LVecBase2)& copy); INLINE_LINMATH FLOATNAME(LVector2)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LVector2)(FLOATTYPE x, FLOATTYPE y); diff --git a/panda/src/linmath/lvector3_src.h b/panda/src/linmath/lvector3_src.h index e8f010cec7..777a064ffd 100644 --- a/panda/src/linmath/lvector3_src.h +++ b/panda/src/linmath/lvector3_src.h @@ -20,7 +20,7 @@ */ class EXPCL_PANDA_LINMATH FLOATNAME(LVector3) : public FLOATNAME(LVecBase3) { PUBLISHED: - INLINE_LINMATH FLOATNAME(LVector3)() DEFAULT_CTOR; + INLINE_LINMATH FLOATNAME(LVector3)() = default; INLINE_LINMATH FLOATNAME(LVector3)(const FLOATNAME(LVecBase3) ©); INLINE_LINMATH FLOATNAME(LVector3)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LVector3)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z); diff --git a/panda/src/linmath/lvector4_src.h b/panda/src/linmath/lvector4_src.h index 4c576e8406..93f821b08b 100644 --- a/panda/src/linmath/lvector4_src.h +++ b/panda/src/linmath/lvector4_src.h @@ -16,7 +16,7 @@ */ class EXPCL_PANDA_LINMATH FLOATNAME(LVector4) : public FLOATNAME(LVecBase4) { PUBLISHED: - INLINE_LINMATH FLOATNAME(LVector4)() DEFAULT_CTOR; + INLINE_LINMATH FLOATNAME(LVector4)() = default; INLINE_LINMATH FLOATNAME(LVector4)(const FLOATNAME(LVecBase4) ©); INLINE_LINMATH FLOATNAME(LVector4)(FLOATTYPE fill_value); INLINE_LINMATH FLOATNAME(LVector4)(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w); diff --git a/panda/src/mathutil/geometricBoundingVolume.h b/panda/src/mathutil/geometricBoundingVolume.h index a27c19a724..a8f75a226f 100644 --- a/panda/src/mathutil/geometricBoundingVolume.h +++ b/panda/src/mathutil/geometricBoundingVolume.h @@ -51,8 +51,8 @@ PUBLISHED: virtual void xform(const LMatrix4 &mat)=0; public: - virtual GeometricBoundingVolume *as_geometric_bounding_volume() FINAL; - virtual const GeometricBoundingVolume *as_geometric_bounding_volume() const FINAL; + virtual GeometricBoundingVolume *as_geometric_bounding_volume() final; + virtual const GeometricBoundingVolume *as_geometric_bounding_volume() const final; protected: // Some virtual functions to implement fundamental bounding operations on diff --git a/panda/src/pgraph/cullableObject.cxx b/panda/src/pgraph/cullableObject.cxx index d38fc4f5a4..8c8b24f1c0 100644 --- a/panda/src/pgraph/cullableObject.cxx +++ b/panda/src/pgraph/cullableObject.cxx @@ -583,12 +583,7 @@ munge_points_to_quads(const CullTraverser *traverser, bool force) { } _geom = new_geom.p(); - -#ifdef USE_MOVE_SEMANTICS _munged_data = move(new_data); -#else - _munged_data = new_data; -#endif return true; } diff --git a/panda/src/pgraph/geomNode.I b/panda/src/pgraph/geomNode.I index 431d5e1d2e..7766631662 100644 --- a/panda/src/pgraph/geomNode.I +++ b/panda/src/pgraph/geomNode.I @@ -255,13 +255,12 @@ operator = (const GeomNode::Geoms ©) { _geoms = copy._geoms; } -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE GeomNode::Geoms:: -Geoms(GeomNode::Geoms &&from) NOEXCEPT : - _geoms(move(from._geoms)) +Geoms(GeomNode::Geoms &&from) noexcept : + _geoms(std::move(from._geoms)) { } @@ -269,10 +268,9 @@ Geoms(GeomNode::Geoms &&from) NOEXCEPT : * */ INLINE void GeomNode::Geoms:: -operator = (GeomNode::Geoms &&from) NOEXCEPT { - _geoms = move(from._geoms); +operator = (GeomNode::Geoms &&from) noexcept { + _geoms = std::move(from._geoms); } -#endif // USE_MOVE_SEMANTICS /** * Returns the number of geoms of the node. diff --git a/panda/src/pgraph/geomNode.h b/panda/src/pgraph/geomNode.h index d17903027a..0b5bccd492 100644 --- a/panda/src/pgraph/geomNode.h +++ b/panda/src/pgraph/geomNode.h @@ -164,12 +164,10 @@ public: INLINE Geoms(); INLINE Geoms(const CData *cdata); INLINE Geoms(const Geoms ©); - INLINE void operator = (const Geoms ©); + INLINE Geoms(Geoms &&from) noexcept; -#ifdef USE_MOVE_SEMANTICS - INLINE Geoms(Geoms &&from) NOEXCEPT; - INLINE void operator = (Geoms &&from) NOEXCEPT; -#endif + INLINE void operator = (const Geoms ©); + INLINE void operator = (Geoms &&from) noexcept; INLINE int get_num_geoms() const; INLINE CPT(Geom) get_geom(int n) const; diff --git a/panda/src/pgraph/nodePath.I b/panda/src/pgraph/nodePath.I index c7d75da2c1..8860fff331 100644 --- a/panda/src/pgraph/nodePath.I +++ b/panda/src/pgraph/nodePath.I @@ -90,12 +90,11 @@ operator = (const NodePath ©) { _error_type = copy._error_type; } -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE NodePath:: -NodePath(NodePath &&from) NOEXCEPT : +NodePath(NodePath &&from) noexcept : _head(move(from._head)), _backup_key(from._backup_key), _error_type(from._error_type) @@ -106,12 +105,11 @@ NodePath(NodePath &&from) NOEXCEPT : * */ INLINE void NodePath:: -operator = (NodePath &&from) NOEXCEPT { +operator = (NodePath &&from) noexcept { _head = move(from._head); _backup_key = from._backup_key; _error_type = from._error_type; } -#endif // USE_MOVE_SEMANTICS /** * Sets this NodePath to the empty NodePath. It will no longer point to any diff --git a/panda/src/pgraph/nodePath.cxx b/panda/src/pgraph/nodePath.cxx index 71bbb3a561..f8d7d6c4b0 100644 --- a/panda/src/pgraph/nodePath.cxx +++ b/panda/src/pgraph/nodePath.cxx @@ -71,6 +71,7 @@ #include "bam.h" #include "bamWriter.h" #include "datagramBuffer.h" +#include "weakNodePath.h" // stack seems to overflow on Intel C++ at 7000. If we need more than 7000, // need to increase stack size. @@ -5164,6 +5165,55 @@ get_stashed_ancestor(Thread *current_thread) const { return not_found(); } +/** + * Returns true if the two paths are equivalent; that is, if they contain the + * same list of nodes in the same order. + */ +bool NodePath:: +operator == (const WeakNodePath &other) const { + return _head == other._head; +} + +/** + * Returns true if the two paths are not equivalent. + */ +bool NodePath:: +operator != (const WeakNodePath &other) const { + return _head != other._head; +} + +/** + * Returns true if this NodePath sorts before the other one, false otherwise. + * The sorting order of two nonequivalent NodePaths is consistent but + * undefined, and is useful only for storing NodePaths in a sorted container + * like an STL set. + */ +bool NodePath:: +operator < (const WeakNodePath &other) const { + return _head < other._head; +} + +/** + * Returns a number less than zero if this NodePath sorts before the other + * one, greater than zero if it sorts after, or zero if they are equivalent. + * + * Two NodePaths are considered equivalent if they consist of exactly the same + * list of nodes in the same order. Otherwise, they are different; different + * NodePaths will be ranked in a consistent but undefined ordering; the + * ordering is useful only for placing the NodePaths in a sorted container + * like an STL set. + */ +int NodePath:: +compare_to(const WeakNodePath &other) const { + // Nowadays, the NodePathComponents at the head are pointerwise equivalent + // if and only if the NodePaths are equivalent. So we only have to compare + // pointers. + if (_head != other._head) { + return _head < other._head ? -1 : 1; + } + return 0; +} + /** * Returns true if all of the nodes described in the NodePath are connected, * or false otherwise. @@ -5362,7 +5412,7 @@ calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point, bool found_any = false; node()->calc_tight_bounds(min_point, max_point, found_any, - MOVE(transform), current_thread); + move(transform), current_thread); return found_any; } diff --git a/panda/src/pgraph/nodePath.h b/panda/src/pgraph/nodePath.h index c5a3902c32..bdd9d3f2d7 100644 --- a/panda/src/pgraph/nodePath.h +++ b/panda/src/pgraph/nodePath.h @@ -63,6 +63,7 @@ class SamplerState; class Shader; class ShaderBuffer; class ShaderInput; +class WeakNodePath; // // A NodePath is the fundamental unit of high-level interaction with the scene @@ -176,13 +177,12 @@ PUBLISHED: Thread *current_thread = Thread::get_current_thread()); INLINE NodePath(const NodePath ©); - INLINE void operator = (const NodePath ©); - INLINE void clear(); + INLINE NodePath(NodePath &&from) noexcept; -#ifdef USE_MOVE_SEMANTICS - INLINE NodePath(NodePath &&from) NOEXCEPT; - INLINE void operator = (NodePath &&from) NOEXCEPT; -#endif + INLINE void operator = (const NodePath ©); + INLINE void operator = (NodePath &&from) noexcept; + + INLINE void clear(); EXTENSION(NodePath __copy__() const); EXTENSION(PyObject *__deepcopy__(PyObject *self, PyObject *memo) const); @@ -879,6 +879,11 @@ PUBLISHED: INLINE bool operator < (const NodePath &other) const; INLINE int compare_to(const NodePath &other) const; + bool operator == (const WeakNodePath &other) const; + bool operator != (const WeakNodePath &other) const; + bool operator < (const WeakNodePath &other) const; + int compare_to(const WeakNodePath &other) const; + // Miscellaneous bool verify_complete(Thread *current_thread = Thread::get_current_thread()) const; diff --git a/panda/src/pgraph/nodePathCollection.h b/panda/src/pgraph/nodePathCollection.h index 9eb0c1ce90..7535a28718 100644 --- a/panda/src/pgraph/nodePathCollection.h +++ b/panda/src/pgraph/nodePathCollection.h @@ -25,7 +25,7 @@ */ class EXPCL_PANDA_PGRAPH NodePathCollection { PUBLISHED: - NodePathCollection() DEFAULT_CTOR; + NodePathCollection() = default; #ifdef HAVE_PYTHON EXTENSION(NodePathCollection(PyObject *self, PyObject *sequence)); diff --git a/panda/src/pgraph/nodePathComponent.I b/panda/src/pgraph/nodePathComponent.I index d3abe36c07..b54d4cfc7d 100644 --- a/panda/src/pgraph/nodePathComponent.I +++ b/panda/src/pgraph/nodePathComponent.I @@ -29,23 +29,6 @@ CData(const NodePathComponent::CData ©) : { } -/** - * NodePathComponents should not be copied. - */ -INLINE NodePathComponent:: -NodePathComponent(const NodePathComponent ©) { - nassertv(false); -} - -/** - * NodePathComponents should not be copied. - */ -INLINE void NodePathComponent:: -operator = (const NodePathComponent ©) { - nassertv(false); -} - - /** * */ diff --git a/panda/src/pgraph/nodePathComponent.h b/panda/src/pgraph/nodePathComponent.h index 2106430b7d..b6957ffd9a 100644 --- a/panda/src/pgraph/nodePathComponent.h +++ b/panda/src/pgraph/nodePathComponent.h @@ -39,17 +39,19 @@ * graph, and the NodePathComponents are stored in the nodes themselves to * allow the nodes to keep these up to date as the scene graph is manipulated. */ -class EXPCL_PANDA_PGRAPH NodePathComponent FINAL : public ReferenceCount { +class EXPCL_PANDA_PGRAPH NodePathComponent final : public ReferenceCount { private: NodePathComponent(PandaNode *node, NodePathComponent *next, int pipeline_stage, Thread *current_thread); - INLINE NodePathComponent(const NodePathComponent ©); - INLINE void operator = (const NodePathComponent ©); public: + NodePathComponent(const NodePathComponent ©) = delete; INLINE ~NodePathComponent(); + ALLOC_DELETED_CHAIN(NodePathComponent); + NodePathComponent &operator = (const NodePathComponent ©) = delete; + INLINE PandaNode *get_node() const; INLINE bool has_key() const; int get_key() const; diff --git a/panda/src/pgraph/pandaNode.I b/panda/src/pgraph/pandaNode.I index de6682e911..93bf19cc2d 100644 --- a/panda/src/pgraph/pandaNode.I +++ b/panda/src/pgraph/pandaNode.I @@ -929,12 +929,11 @@ operator = (const PandaNode::Children ©) { _down = copy._down; } -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE PandaNode::Children:: -Children(PandaNode::Children &&from) NOEXCEPT : +Children(PandaNode::Children &&from) noexcept : _down(move(from._down)) { } @@ -943,10 +942,9 @@ Children(PandaNode::Children &&from) NOEXCEPT : * */ INLINE void PandaNode::Children:: -operator = (PandaNode::Children &&from) NOEXCEPT { +operator = (PandaNode::Children &&from) noexcept { _down = move(from._down); } -#endif // USE_MOVE_SEMANTICS /** * Returns the number of children of the node. @@ -1011,13 +1009,12 @@ operator = (const PandaNode::Stashed ©) { _stashed = copy._stashed; } -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE PandaNode::Stashed:: -Stashed(PandaNode::Stashed &&from) NOEXCEPT : - _stashed(move(from._stashed)) +Stashed(PandaNode::Stashed &&from) noexcept : + _stashed(std::move(from._stashed)) { } @@ -1025,10 +1022,9 @@ Stashed(PandaNode::Stashed &&from) NOEXCEPT : * */ INLINE void PandaNode::Stashed:: -operator = (PandaNode::Stashed &&from) NOEXCEPT { - _stashed = move(from._stashed); +operator = (PandaNode::Stashed &&from) noexcept { + _stashed = std::move(from._stashed); } -#endif // USE_MOVE_SEMANTICS /** * Returns the number of stashed children of the node. @@ -1093,13 +1089,12 @@ operator = (const PandaNode::Parents ©) { _up = copy._up; } -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE PandaNode::Parents:: -Parents(PandaNode::Parents &&from) NOEXCEPT : - _up(move(from._up)) +Parents(PandaNode::Parents &&from) noexcept : + _up(std::move(from._up)) { } @@ -1107,10 +1102,9 @@ Parents(PandaNode::Parents &&from) NOEXCEPT : * */ INLINE void PandaNode::Parents:: -operator = (PandaNode::Parents &&from) NOEXCEPT { - _up = move(from._up); +operator = (PandaNode::Parents &&from) noexcept { + _up = std::move(from._up); } -#endif // USE_MOVE_SEMANTICS /** * Returns the number of parents of the node. diff --git a/panda/src/pgraph/pandaNode.cxx b/panda/src/pgraph/pandaNode.cxx index 96b94dd0c2..91afd2f768 100644 --- a/panda/src/pgraph/pandaNode.cxx +++ b/panda/src/pgraph/pandaNode.cxx @@ -175,15 +175,6 @@ PandaNode(const PandaNode ©) : } } -/** - * Do not call the copy assignment operator at all. Use make_copy() or - * copy_subgraph() to make a copy of a node. - */ -void PandaNode:: -operator = (const PandaNode ©) { - nassertv(false); -} - /** * This is similar to make_copy(), but it makes a copy for the specific * purpose of flatten. Typically, this will be a new PandaNode with a new diff --git a/panda/src/pgraph/pandaNode.h b/panda/src/pgraph/pandaNode.h index 1b42e5ed2d..f5cc0fee78 100644 --- a/panda/src/pgraph/pandaNode.h +++ b/panda/src/pgraph/pandaNode.h @@ -71,8 +71,8 @@ PUBLISHED: protected: PandaNode(const PandaNode ©); -private: - void operator = (const PandaNode ©); + + PandaNode &operator = (const PandaNode ©) = delete; public: virtual PandaNode *dupe_for_flatten() const; @@ -710,12 +710,10 @@ PUBLISHED: INLINE Children(); INLINE Children(const CData *cdata); INLINE Children(const Children ©); - INLINE void operator = (const Children ©); + INLINE Children(Children &&from) noexcept; -#ifdef USE_MOVE_SEMANTICS - INLINE Children(Children &&from) NOEXCEPT; - INLINE void operator = (Children &&from) NOEXCEPT; -#endif + INLINE void operator = (const Children ©); + INLINE void operator = (Children &&from) noexcept; INLINE size_t get_num_children() const; INLINE PandaNode *get_child(size_t n) const; @@ -735,12 +733,10 @@ PUBLISHED: INLINE Stashed(); INLINE Stashed(const CData *cdata); INLINE Stashed(const Stashed ©); - INLINE void operator = (const Stashed ©); + INLINE Stashed(Stashed &&from) noexcept; -#ifdef USE_MOVE_SEMANTICS - INLINE Stashed(Stashed &&from) NOEXCEPT; - INLINE void operator = (Stashed &&from) NOEXCEPT; -#endif + INLINE void operator = (const Stashed ©); + INLINE void operator = (Stashed &&from) noexcept; INLINE size_t get_num_stashed() const; INLINE PandaNode *get_stashed(size_t n) const; @@ -760,12 +756,10 @@ PUBLISHED: INLINE Parents(); INLINE Parents(const CData *cdata); INLINE Parents(const Parents ©); - INLINE void operator = (const Parents ©); + INLINE Parents(Parents &&from) noexcept; -#ifdef USE_MOVE_SEMANTICS - INLINE Parents(Parents &&from) NOEXCEPT; - INLINE void operator = (Parents &&from) NOEXCEPT; -#endif + INLINE void operator = (const Parents ©); + INLINE void operator = (Parents &&from) noexcept; INLINE size_t get_num_parents() const; INLINE PandaNode *get_parent(size_t n) const; diff --git a/panda/src/pgraph/pandaNode_ext.cxx b/panda/src/pgraph/pandaNode_ext.cxx index aa24e623ee..4f0a1b4e8d 100644 --- a/panda/src/pgraph/pandaNode_ext.cxx +++ b/panda/src/pgraph/pandaNode_ext.cxx @@ -94,14 +94,9 @@ get_tag_keys() const { */ PyObject *Extension:: get_python_tags() { - if (_this->_python_tag_data == NULL) { - _this->_python_tag_data = new PythonTagDataImpl; - - } else if (_this->_python_tag_data->get_ref_count() > 1) { - // Copy-on-write. - _this->_python_tag_data = new PythonTagDataImpl(*(PythonTagDataImpl *)_this->_python_tag_data.p()); - } - return ((PythonTagDataImpl *)_this->_python_tag_data.p())->_dict; + PyObject *dict = do_get_python_tags(); + Py_INCREF(dict); + return dict; } /** @@ -116,7 +111,7 @@ get_python_tags() { */ int Extension:: set_python_tag(PyObject *key, PyObject *value) { - return PyDict_SetItem(get_python_tags(), key, value); + return PyDict_SetItem(do_get_python_tags(), key, value); } /** @@ -166,7 +161,7 @@ clear_python_tag(PyObject *key) { return; } - PyObject *dict = get_python_tags(); + PyObject *dict = do_get_python_tags(); if (PyDict_GetItem(dict, key) != NULL) { PyDict_DelItem(dict, key); } @@ -201,6 +196,21 @@ __traverse__(visitproc visit, void *arg) { return 0; } +/** + * Same as get_python_tags, without incrementing the reference count. + */ +PyObject *Extension:: +do_get_python_tags() { + if (_this->_python_tag_data == NULL) { + _this->_python_tag_data = new PythonTagDataImpl; + + } else if (_this->_python_tag_data->get_ref_count() > 1) { + // Copy-on-write. + _this->_python_tag_data = new PythonTagDataImpl(*(PythonTagDataImpl *)_this->_python_tag_data.p()); + } + return ((PythonTagDataImpl *)_this->_python_tag_data.p())->_dict; +} + /** * Destroys the tags associated with the node. */ diff --git a/panda/src/pgraph/pandaNode_ext.h b/panda/src/pgraph/pandaNode_ext.h index 86527d42d4..d19bc5475f 100644 --- a/panda/src/pgraph/pandaNode_ext.h +++ b/panda/src/pgraph/pandaNode_ext.h @@ -45,6 +45,8 @@ public: int __traverse__(visitproc visit, void *arg); private: + PyObject *do_get_python_tags(); + // This is what actually stores the Python tags. class PythonTagDataImpl : public PandaNode::PythonTagData { public: diff --git a/panda/src/pgraph/paramNodePath.I b/panda/src/pgraph/paramNodePath.I index beaa9c5c85..89d6a9e67b 100644 --- a/panda/src/pgraph/paramNodePath.I +++ b/panda/src/pgraph/paramNodePath.I @@ -20,16 +20,14 @@ ParamNodePath(const NodePath &node_path) : { } -#ifdef USE_MOVE_SEMANTICS /** * Creates a new ParamNodePath storing the given node path object. */ INLINE ParamNodePath:: -ParamNodePath(NodePath &&node_path) NOEXCEPT : - _node_path(move(node_path)) +ParamNodePath(NodePath &&node_path) noexcept : + _node_path(std::move(node_path)) { } -#endif // USE_MOVE_SEMANTICS /** * Returns NodePath::get_class_type(). diff --git a/panda/src/pgraph/paramNodePath.h b/panda/src/pgraph/paramNodePath.h index 25812d8b0f..86f027eb99 100644 --- a/panda/src/pgraph/paramNodePath.h +++ b/panda/src/pgraph/paramNodePath.h @@ -27,10 +27,7 @@ protected: PUBLISHED: INLINE ParamNodePath(const NodePath &node_path); - -#ifdef USE_MOVE_SEMANTICS - INLINE ParamNodePath(NodePath &&node_path) NOEXCEPT; -#endif + INLINE ParamNodePath(NodePath &&node_path) noexcept; INLINE virtual TypeHandle get_value_type() const; INLINE const NodePath &get_value() const; diff --git a/panda/src/pgraph/renderAttrib.cxx b/panda/src/pgraph/renderAttrib.cxx index 385d7ee740..45f8ea2fb9 100644 --- a/panda/src/pgraph/renderAttrib.cxx +++ b/panda/src/pgraph/renderAttrib.cxx @@ -37,22 +37,6 @@ RenderAttrib() { _saved_entry = -1; } -/** - * RenderAttribs are not meant to be copied. - */ -RenderAttrib:: -RenderAttrib(const RenderAttrib &) { - nassertv(false); -} - -/** - * RenderAttribs are not meant to be copied. - */ -void RenderAttrib:: -operator = (const RenderAttrib &) { - nassertv(false); -} - /** * The destructor is responsible for removing the RenderAttrib from the global * set if it is there. diff --git a/panda/src/pgraph/renderAttrib.h b/panda/src/pgraph/renderAttrib.h index 5bf54cf32f..b506d64841 100644 --- a/panda/src/pgraph/renderAttrib.h +++ b/panda/src/pgraph/renderAttrib.h @@ -51,13 +51,13 @@ class RenderState; class EXPCL_PANDA_PGRAPH RenderAttrib : public TypedWritableReferenceCount { protected: RenderAttrib(); -private: - RenderAttrib(const RenderAttrib ©); - void operator = (const RenderAttrib ©); public: + RenderAttrib(const RenderAttrib ©) = delete; virtual ~RenderAttrib(); + RenderAttrib &operator = (const RenderAttrib ©) = delete; + PUBLISHED: INLINE CPT(RenderAttrib) compose(const RenderAttrib *other) const; INLINE CPT(RenderAttrib) invert_compose(const RenderAttrib *other) const; @@ -72,7 +72,7 @@ PUBLISHED: INLINE size_t get_hash() const; INLINE CPT(RenderAttrib) get_unique() const; - virtual bool unref() const FINAL; + virtual bool unref() const final; virtual void output(ostream &out) const; virtual void write(ostream &out, int indent_level) const; diff --git a/panda/src/pgraph/renderAttribRegistry.I b/panda/src/pgraph/renderAttribRegistry.I index 1a807794a9..5ad950dd4d 100644 --- a/panda/src/pgraph/renderAttribRegistry.I +++ b/panda/src/pgraph/renderAttribRegistry.I @@ -24,19 +24,6 @@ get_slot(TypeHandle type_handle) const { return _slots_by_type[(size_t)type_index]; } -/** - * Returns the maximum number that any slot number is allowed to grow. - * Actually, this number will be one higher than the highest possible slot - * number. This puts an upper bound on the number of RenderAttrib slots that - * may be allocated, and allows other code to define an array of slots. - * - * This number will not change during the lifetime of the application. - */ -CONSTEXPR int RenderAttribRegistry:: -get_max_slots() { - return _max_slots; -} - /** * Returns the number of RenderAttrib slots that have been allocated. This is * one more than the highest slot number in use. diff --git a/panda/src/pgraph/renderAttribRegistry.h b/panda/src/pgraph/renderAttribRegistry.h index 59194fd278..c7cf71b044 100644 --- a/panda/src/pgraph/renderAttribRegistry.h +++ b/panda/src/pgraph/renderAttribRegistry.h @@ -54,7 +54,7 @@ public: PUBLISHED: INLINE int get_slot(TypeHandle type_handle) const; - static CONSTEXPR int get_max_slots(); + static constexpr int get_max_slots() { return _max_slots; } INLINE int get_num_slots() const; INLINE TypeHandle get_slot_type(int slot) const; diff --git a/panda/src/pgraph/renderEffect.cxx b/panda/src/pgraph/renderEffect.cxx index 09572cc445..585db7db26 100644 --- a/panda/src/pgraph/renderEffect.cxx +++ b/panda/src/pgraph/renderEffect.cxx @@ -35,22 +35,6 @@ RenderEffect() { _saved_entry = _effects->end(); } -/** - * RenderEffects are not meant to be copied. - */ -RenderEffect:: -RenderEffect(const RenderEffect &) { - nassertv(false); -} - -/** - * RenderEffects are not meant to be copied. - */ -void RenderEffect:: -operator = (const RenderEffect &) { - nassertv(false); -} - /** * The destructor is responsible for removing the RenderEffect from the global * set if it is there. diff --git a/panda/src/pgraph/renderEffect.h b/panda/src/pgraph/renderEffect.h index d739f5cee7..65a9942fa7 100644 --- a/panda/src/pgraph/renderEffect.h +++ b/panda/src/pgraph/renderEffect.h @@ -48,13 +48,13 @@ class PandaNode; class EXPCL_PANDA_PGRAPH RenderEffect : public TypedWritableReferenceCount { protected: RenderEffect(); -private: - RenderEffect(const RenderEffect ©); - void operator = (const RenderEffect ©); public: + RenderEffect(const RenderEffect ©) = delete; virtual ~RenderEffect(); + RenderEffect &operator = (const RenderEffect ©) = delete; + virtual bool safe_to_transform() const; virtual CPT(TransformState) prepare_flatten_transform(const TransformState *net_transform) const; virtual bool safe_to_combine() const; diff --git a/panda/src/pgraph/renderEffects.cxx b/panda/src/pgraph/renderEffects.cxx index 639f11be9b..aaa81773ce 100644 --- a/panda/src/pgraph/renderEffects.cxx +++ b/panda/src/pgraph/renderEffects.cxx @@ -48,22 +48,6 @@ RenderEffects() : _lock("RenderEffects") { _flags = 0; } -/** - * RenderEffects are not meant to be copied. - */ -RenderEffects:: -RenderEffects(const RenderEffects &) { - nassertv(false); -} - -/** - * RenderEffects are not meant to be copied. - */ -void RenderEffects:: -operator = (const RenderEffects &) { - nassertv(false); -} - /** * The destructor is responsible for removing the RenderEffects from the * global set if it is there. diff --git a/panda/src/pgraph/renderEffects.h b/panda/src/pgraph/renderEffects.h index 1e54c30533..7a8f18aed3 100644 --- a/panda/src/pgraph/renderEffects.h +++ b/panda/src/pgraph/renderEffects.h @@ -42,13 +42,12 @@ class EXPCL_PANDA_PGRAPH RenderEffects : public TypedWritableReferenceCount { protected: RenderEffects(); -private: - RenderEffects(const RenderEffects ©); - void operator = (const RenderEffects ©); - public: + RenderEffects(const RenderEffects ©) = delete; virtual ~RenderEffects(); + RenderEffects &operator = (const RenderEffects ©) = delete; + bool safe_to_transform() const; virtual CPT(TransformState) prepare_flatten_transform(const TransformState *net_transform) const; bool safe_to_combine() const; diff --git a/panda/src/pgraph/renderState.cxx b/panda/src/pgraph/renderState.cxx index 6f035a6557..a4d2952e50 100644 --- a/panda/src/pgraph/renderState.cxx +++ b/panda/src/pgraph/renderState.cxx @@ -105,14 +105,6 @@ RenderState(const RenderState ©) : #endif } -/** - * RenderStates are not meant to be copied. - */ -void RenderState:: -operator = (const RenderState &) { - nassertv(false); -} - /** * The destructor is responsible for removing the RenderState from the global * set if it is there. diff --git a/panda/src/pgraph/renderState.h b/panda/src/pgraph/renderState.h index 1052687314..433582fd2c 100644 --- a/panda/src/pgraph/renderState.h +++ b/panda/src/pgraph/renderState.h @@ -50,12 +50,13 @@ protected: private: RenderState(const RenderState ©); - void operator = (const RenderState ©); public: virtual ~RenderState(); ALLOC_DELETED_CHAIN(RenderState); + RenderState &operator = (const RenderState ©) = delete; + typedef RenderAttribRegistry::SlotMask SlotMask; PUBLISHED: diff --git a/panda/src/pgraph/shaderInput.I b/panda/src/pgraph/shaderInput.I index 8c37322082..b8e182421f 100644 --- a/panda/src/pgraph/shaderInput.I +++ b/panda/src/pgraph/shaderInput.I @@ -18,7 +18,7 @@ */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_invalid), _priority(priority) { @@ -29,7 +29,7 @@ ShaderInput(CPT_InternalName name, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, Texture *tex, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_texture), _priority(priority), _value(tex) @@ -41,7 +41,7 @@ ShaderInput(CPT_InternalName name, Texture *tex, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, ParamValueBase *param, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_param), _priority(priority), _value(param) @@ -53,7 +53,7 @@ ShaderInput(CPT_InternalName name, ParamValueBase *param, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, ShaderBuffer *buf, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_buffer), _priority(priority), _value(buf) @@ -65,7 +65,7 @@ ShaderInput(CPT_InternalName name, ShaderBuffer *buf, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_float &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -77,7 +77,7 @@ ShaderInput(CPT_InternalName name, const PTA_float &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_LVecBase4f &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -89,7 +89,7 @@ ShaderInput(CPT_InternalName name, const PTA_LVecBase4f &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_LVecBase3f &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -101,7 +101,7 @@ ShaderInput(CPT_InternalName name, const PTA_LVecBase3f &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_LVecBase2f &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -113,7 +113,7 @@ ShaderInput(CPT_InternalName name, const PTA_LVecBase2f &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const LVecBase4f &vec, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_vector), _priority(priority), _stored_ptr(vec), @@ -126,7 +126,7 @@ ShaderInput(CPT_InternalName name, const LVecBase4f &vec, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const LVecBase3f &vec, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_vector), _priority(priority), _stored_ptr(vec), @@ -139,7 +139,7 @@ ShaderInput(CPT_InternalName name, const LVecBase3f &vec, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const LVecBase2f &vec, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_vector), _priority(priority), _stored_ptr(vec), @@ -152,7 +152,7 @@ ShaderInput(CPT_InternalName name, const LVecBase2f &vec, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_LMatrix4f &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -164,7 +164,7 @@ ShaderInput(CPT_InternalName name, const PTA_LMatrix4f &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_LMatrix3f &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -176,7 +176,7 @@ ShaderInput(CPT_InternalName name, const PTA_LMatrix3f &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const LMatrix4f &mat, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(mat) @@ -188,7 +188,7 @@ ShaderInput(CPT_InternalName name, const LMatrix4f &mat, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const LMatrix3f &mat, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(mat) @@ -200,7 +200,7 @@ ShaderInput(CPT_InternalName name, const LMatrix3f &mat, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_double &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -212,7 +212,7 @@ ShaderInput(CPT_InternalName name, const PTA_double &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_LVecBase4d &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -224,7 +224,7 @@ ShaderInput(CPT_InternalName name, const PTA_LVecBase4d &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_LVecBase3d &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -236,7 +236,7 @@ ShaderInput(CPT_InternalName name, const PTA_LVecBase3d &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_LVecBase2d &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -248,7 +248,7 @@ ShaderInput(CPT_InternalName name, const PTA_LVecBase2d &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const LVecBase4d &vec, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(vec), @@ -261,7 +261,7 @@ ShaderInput(CPT_InternalName name, const LVecBase4d &vec, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const LVecBase3d &vec, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(vec), @@ -274,7 +274,7 @@ ShaderInput(CPT_InternalName name, const LVecBase3d &vec, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const LVecBase2d &vec, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(vec), @@ -287,7 +287,7 @@ ShaderInput(CPT_InternalName name, const LVecBase2d &vec, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_LMatrix4d &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -299,7 +299,7 @@ ShaderInput(CPT_InternalName name, const PTA_LMatrix4d &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_LMatrix3d &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -311,7 +311,7 @@ ShaderInput(CPT_InternalName name, const PTA_LMatrix3d &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const LMatrix4d &mat, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(mat) @@ -323,7 +323,7 @@ ShaderInput(CPT_InternalName name, const LMatrix4d &mat, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const LMatrix3d &mat, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(mat) @@ -335,7 +335,7 @@ ShaderInput(CPT_InternalName name, const LMatrix3d &mat, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_int &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -347,7 +347,7 @@ ShaderInput(CPT_InternalName name, const PTA_int &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_LVecBase4i &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -359,7 +359,7 @@ ShaderInput(CPT_InternalName name, const PTA_LVecBase4i &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_LVecBase3i &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -371,7 +371,7 @@ ShaderInput(CPT_InternalName name, const PTA_LVecBase3i &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const PTA_LVecBase2i &ptr, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(ptr) @@ -383,7 +383,7 @@ ShaderInput(CPT_InternalName name, const PTA_LVecBase2i &ptr, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const LVecBase4i &vec, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(vec), @@ -396,7 +396,7 @@ ShaderInput(CPT_InternalName name, const LVecBase4i &vec, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const LVecBase3i &vec, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(vec), @@ -409,7 +409,7 @@ ShaderInput(CPT_InternalName name, const LVecBase3i &vec, int priority) : */ INLINE ShaderInput:: ShaderInput(CPT_InternalName name, const LVecBase2i &vec, int priority) : - _name(MOVE(name)), + _name(std::move(name)), _type(M_numeric), _priority(priority), _stored_ptr(vec), diff --git a/panda/src/pgraph/shaderInput.cxx b/panda/src/pgraph/shaderInput.cxx index 44fb91cf23..86a3912ec4 100644 --- a/panda/src/pgraph/shaderInput.cxx +++ b/panda/src/pgraph/shaderInput.cxx @@ -30,7 +30,7 @@ get_blank() { */ ShaderInput:: ShaderInput(CPT_InternalName name, const NodePath &np, int priority) : - _name(MOVE(name)), + _name(move(name)), _type(M_nodepath), _priority(priority), _value(new ParamNodePath(np)) @@ -42,7 +42,7 @@ ShaderInput(CPT_InternalName name, const NodePath &np, int priority) : */ ShaderInput:: ShaderInput(CPT_InternalName name, Texture *tex, bool read, bool write, int z, int n, int priority) : - _name(MOVE(name)), + _name(move(name)), _type(M_texture_image), _priority(priority), _value(new ParamTextureImage(tex, read, write, z, n)) @@ -54,7 +54,7 @@ ShaderInput(CPT_InternalName name, Texture *tex, bool read, bool write, int z, i */ ShaderInput:: ShaderInput(CPT_InternalName name, Texture *tex, const SamplerState &sampler, int priority) : - _name(MOVE(name)), + _name(move(name)), _type(M_texture_sampler), _priority(priority), _value(new ParamTextureSampler(tex, sampler)) diff --git a/panda/src/pgraph/shaderInput.h b/panda/src/pgraph/shaderInput.h index 39a4e32fe8..39ae9ba835 100644 --- a/panda/src/pgraph/shaderInput.h +++ b/panda/src/pgraph/shaderInput.h @@ -124,7 +124,7 @@ PUBLISHED: const SamplerState &get_sampler() const; public: - ShaderInput() DEFAULT_CTOR; + ShaderInput() = default; INLINE ParamValueBase *get_param() const; INLINE TypedWritableReferenceCount *get_value() const; diff --git a/panda/src/pgraph/stateMunger.cxx b/panda/src/pgraph/stateMunger.cxx index db94c81ba8..8eba900f70 100644 --- a/panda/src/pgraph/stateMunger.cxx +++ b/panda/src/pgraph/stateMunger.cxx @@ -32,8 +32,8 @@ munge_state(const RenderState *state) { int id = get_gsg()->_id; int mi = munged_states.find(id); if (mi != -1) { - if (!munged_states.get_data(mi).was_deleted()) { - return munged_states.get_data(mi).p(); + if (auto munged_state = munged_states.get_data(mi).lock()) { + return munged_state; } else { munged_states.remove_element(mi); } diff --git a/panda/src/pgraph/transformState.cxx b/panda/src/pgraph/transformState.cxx index bff497298e..c66bd3a281 100644 --- a/panda/src/pgraph/transformState.cxx +++ b/panda/src/pgraph/transformState.cxx @@ -68,22 +68,6 @@ TransformState() : _lock("TransformState") { #endif } -/** - * TransformStates are not meant to be copied. - */ -TransformState:: -TransformState(const TransformState &) { - nassertv(false); -} - -/** - * TransformStates are not meant to be copied. - */ -void TransformState:: -operator = (const TransformState &) { - nassertv(false); -} - /** * The destructor is responsible for removing the TransformState from the * global set if it is there. diff --git a/panda/src/pgraph/transformState.h b/panda/src/pgraph/transformState.h index b770e7bf52..5edd8985d6 100644 --- a/panda/src/pgraph/transformState.h +++ b/panda/src/pgraph/transformState.h @@ -51,18 +51,17 @@ class FactoryParams; * directly. Instead, call one of the make() functions to create one for you. * And instead of modifying a TransformState object, create a new one. */ -class EXPCL_PANDA_PGRAPH TransformState FINAL : public NodeCachedReferenceCount { +class EXPCL_PANDA_PGRAPH TransformState final : public NodeCachedReferenceCount { protected: TransformState(); -private: - TransformState(const TransformState ©); - void operator = (const TransformState ©); - public: + TransformState(const TransformState ©) = delete; virtual ~TransformState(); ALLOC_DELETED_CHAIN(TransformState); + TransformState &operator = (const TransformState ©) = delete; + PUBLISHED: INLINE bool operator != (const TransformState &other) const; INLINE int compare_to(const TransformState &other) const; diff --git a/panda/src/pgraph/weakNodePath.I b/panda/src/pgraph/weakNodePath.I index 36cdbdbf60..613afe0800 100644 --- a/panda/src/pgraph/weakNodePath.I +++ b/panda/src/pgraph/weakNodePath.I @@ -56,6 +56,24 @@ operator = (const WeakNodePath ©) { _backup_key = copy._backup_key; } +/** + * Sets this NodePath to the empty NodePath. It will no longer point to any + * node. + */ +INLINE void WeakNodePath:: +clear() { + _head.clear(); + _backup_key = 0; +} + +/** + * Returns true if this NodePath points to a valid, non-null node. + */ +INLINE WeakNodePath:: +operator bool () const { + return _head.is_valid_pointer(); +} + /** * Returns true if the NodePath contains no nodes, or if it has been deleted. */ @@ -74,23 +92,30 @@ was_deleted() const { } /** - * Returns the NodePath held within this object. + * Returns the NodePath held within this object, or an empty NodePath with the + * error flag set if the object was deleted. */ INLINE NodePath WeakNodePath:: get_node_path() const { - nassertr_always(!was_deleted(), NodePath::fail()); NodePath result; - result._head = _head; + result._head = _head.lock(); + if (!_head.is_null() && result._head == nullptr) { + result._error_type = NodePath::ET_fail; + } return result; } /** - * Returns the PandaNode held within this object. + * Returns the PandaNode held within this object, or nullptr if the object was + * deleted. */ -INLINE PandaNode *WeakNodePath:: +INLINE PT(PandaNode) WeakNodePath:: node() const { - nassertr_always(!is_empty(), (PandaNode *)NULL); - return _head->get_node(); + if (auto head = _head.lock()) { + return head->get_node(); + } else { + return nullptr; + } } /** @@ -190,10 +215,9 @@ compare_to(const WeakNodePath &other) const { */ INLINE int WeakNodePath:: get_key() const { - if (is_empty() || was_deleted()) { - return _backup_key; + if (auto head = _head.lock()) { + _backup_key = head->get_key(); } - ((WeakNodePath *)this)->_backup_key = _head->get_key(); return _backup_key; } diff --git a/panda/src/pgraph/weakNodePath.h b/panda/src/pgraph/weakNodePath.h index e5b9b79c90..dc82431023 100644 --- a/panda/src/pgraph/weakNodePath.h +++ b/panda/src/pgraph/weakNodePath.h @@ -30,7 +30,7 @@ * associated NodePath. */ class EXPCL_PANDA_PGRAPH WeakNodePath { -public: +PUBLISHED: INLINE WeakNodePath(const NodePath &node_path); INLINE WeakNodePath(const WeakNodePath ©); INLINE ~WeakNodePath(); @@ -38,11 +38,14 @@ public: INLINE void operator = (const NodePath &node_path); INLINE void operator = (const WeakNodePath ©); + INLINE void clear(); + + INLINE operator bool () const; INLINE bool is_empty() const; INLINE bool was_deleted() const; INLINE NodePath get_node_path() const; - INLINE PandaNode *node() const; + INLINE PT(PandaNode) node() const; INLINE bool operator == (const NodePath &other) const; INLINE bool operator != (const NodePath &other) const; @@ -60,7 +63,9 @@ public: private: WPT(NodePathComponent) _head; - int _backup_key; + mutable int _backup_key; + + friend class NodePath; }; INLINE ostream &operator << (ostream &out, const WeakNodePath &node_path); diff --git a/panda/src/pgraphnodes/ambientLight.h b/panda/src/pgraphnodes/ambientLight.h index f3582e54fd..959a2d1485 100644 --- a/panda/src/pgraphnodes/ambientLight.h +++ b/panda/src/pgraphnodes/ambientLight.h @@ -33,7 +33,7 @@ protected: public: virtual PandaNode *make_copy() const; virtual void write(ostream &out, int indent_level) const; - virtual bool is_ambient_light() const FINAL; + virtual bool is_ambient_light() const final; PUBLISHED: virtual int get_class_priority() const; diff --git a/panda/src/pgraphnodes/directionalLight.h b/panda/src/pgraphnodes/directionalLight.h index df2a198273..c78f76f81e 100644 --- a/panda/src/pgraphnodes/directionalLight.h +++ b/panda/src/pgraphnodes/directionalLight.h @@ -39,7 +39,7 @@ public: const LMatrix4 &to_object_space); PUBLISHED: - INLINE const LColor &get_specular_color() const FINAL; + INLINE const LColor &get_specular_color() const final; INLINE void set_specular_color(const LColor &color); INLINE void clear_specular_color(); MAKE_PROPERTY(specular_color, get_specular_color, set_specular_color); diff --git a/panda/src/pgraphnodes/pointLight.h b/panda/src/pgraphnodes/pointLight.h index ba3a334d47..bb37237883 100644 --- a/panda/src/pgraphnodes/pointLight.h +++ b/panda/src/pgraphnodes/pointLight.h @@ -39,12 +39,12 @@ public: const LMatrix4 &to_object_space); PUBLISHED: - INLINE const LColor &get_specular_color() const FINAL; + INLINE const LColor &get_specular_color() const final; INLINE void set_specular_color(const LColor &color); INLINE void clear_specular_color(); MAKE_PROPERTY(specular_color, get_specular_color, set_specular_color); - INLINE const LVecBase3 &get_attenuation() const FINAL; + INLINE const LVecBase3 &get_attenuation() const final; INLINE void set_attenuation(const LVecBase3 &attenuation); MAKE_PROPERTY(attenuation, get_attenuation, set_attenuation); diff --git a/panda/src/pgraphnodes/rectangleLight.h b/panda/src/pgraphnodes/rectangleLight.h index 3870b4f8f7..b6a4e173c1 100644 --- a/panda/src/pgraphnodes/rectangleLight.h +++ b/panda/src/pgraphnodes/rectangleLight.h @@ -35,7 +35,7 @@ public: virtual void write(ostream &out, int indent_level) const; PUBLISHED: - INLINE const LColor &get_specular_color() const FINAL; + INLINE const LColor &get_specular_color() const final; INLINE PN_stdfloat get_max_distance() const; INLINE void set_max_distance(PN_stdfloat max_distance); diff --git a/panda/src/pgraphnodes/spotlight.h b/panda/src/pgraphnodes/spotlight.h index c9a6962b07..d1e56a88b3 100644 --- a/panda/src/pgraphnodes/spotlight.h +++ b/panda/src/pgraphnodes/spotlight.h @@ -46,16 +46,16 @@ public: const LMatrix4 &to_object_space); PUBLISHED: - INLINE PN_stdfloat get_exponent() const FINAL; + INLINE PN_stdfloat get_exponent() const final; INLINE void set_exponent(PN_stdfloat exponent); MAKE_PROPERTY(exponent, get_exponent, set_exponent); - INLINE const LColor &get_specular_color() const FINAL; + INLINE const LColor &get_specular_color() const final; INLINE void set_specular_color(const LColor &color); INLINE void clear_specular_color(); MAKE_PROPERTY(specular_color, get_specular_color, set_specular_color); - INLINE const LVecBase3 &get_attenuation() const FINAL; + INLINE const LVecBase3 &get_attenuation() const final; INLINE void set_attenuation(const LVecBase3 &attenuation); MAKE_PROPERTY(attenuation, get_attenuation, set_attenuation); diff --git a/panda/src/pipeline/conditionVar.I b/panda/src/pipeline/conditionVar.I index d797ab2390..196e4283d0 100644 --- a/panda/src/pipeline/conditionVar.I +++ b/panda/src/pipeline/conditionVar.I @@ -27,44 +27,6 @@ ConditionVar(Mutex &mutex) : { } -/** - * - */ -INLINE ConditionVar:: -~ConditionVar() { -} - -/** - * Do not attempt to copy condition variables. - */ -INLINE ConditionVar:: -ConditionVar(const ConditionVar ©) : -#ifdef DEBUG_THREADS - ConditionVarDebug(copy.get_mutex()) -#else - ConditionVarDirect(copy.get_mutex()) -#endif // DEBUG_THREADS -{ - nassertv(false); -} - -/** - * Do not attempt to copy condition variables. - */ -INLINE void ConditionVar:: -operator = (const ConditionVar ©) { - nassertv(false); -} - -/** - * The notify_all() method is specifically *not* provided by ConditionVar. - * Use ConditionVarFull if you need to call this method. - */ -INLINE void ConditionVar:: -notify_all() { - nassertv(false); -} - /** * Returns the mutex associated with this condition variable. */ diff --git a/panda/src/pipeline/conditionVar.h b/panda/src/pipeline/conditionVar.h index 3c94e03a34..fe90e22063 100644 --- a/panda/src/pipeline/conditionVar.h +++ b/panda/src/pipeline/conditionVar.h @@ -43,20 +43,19 @@ class EXPCL_PANDA_PIPELINE ConditionVar : public ConditionVarDirect { PUBLISHED: INLINE explicit ConditionVar(Mutex &mutex); - INLINE ~ConditionVar(); -private: - INLINE ConditionVar(const ConditionVar ©); - INLINE void operator = (const ConditionVar ©); + ConditionVar(const ConditionVar ©) = delete; + ~ConditionVar() = default; - // These methods are inherited from the base class. INLINE void wait(); - // INLINE void notify(); + ConditionVar &operator = (const ConditionVar ©) = delete; + + // These methods are inherited from the base class. + //INLINE void wait(); + //INLINE void notify(); -private: // The notify_all() method is specifically *not* provided by ConditionVar. // Use ConditionVarFull if you need to call this method. - INLINE void notify_all(); + void notify_all() = delete; -PUBLISHED: INLINE Mutex &get_mutex() const; }; diff --git a/panda/src/pipeline/conditionVarDebug.I b/panda/src/pipeline/conditionVarDebug.I index 6b16125a0e..f7804b22b2 100644 --- a/panda/src/pipeline/conditionVarDebug.I +++ b/panda/src/pipeline/conditionVarDebug.I @@ -11,25 +11,6 @@ * @date 2006-02-13 */ -/** - * Do not attempt to copy condition variables. - */ -INLINE ConditionVarDebug:: -ConditionVarDebug(const ConditionVarDebug ©) : - _mutex(copy._mutex), - _impl(*_mutex._global_lock) -{ - nassertv(false); -} - -/** - * Do not attempt to copy condition variables. - */ -INLINE void ConditionVarDebug:: -operator = (const ConditionVarDebug ©) { - nassertv(false); -} - /** * Returns the mutex associated with this condition variable. */ diff --git a/panda/src/pipeline/conditionVarDebug.cxx b/panda/src/pipeline/conditionVarDebug.cxx index d8c838196e..0cc738542f 100644 --- a/panda/src/pipeline/conditionVarDebug.cxx +++ b/panda/src/pipeline/conditionVarDebug.cxx @@ -57,7 +57,7 @@ ConditionVarDebug:: */ void ConditionVarDebug:: wait() { - _mutex._global_lock->acquire(); + _mutex._global_lock->lock(); Thread *current_thread = Thread::get_current_thread(); @@ -66,7 +66,7 @@ wait() { ostr << *current_thread << " attempted to wait on " << *this << " without holding " << _mutex; nassert_raise(ostr.str()); - _mutex._global_lock->release(); + _mutex._global_lock->unlock(); return; } @@ -80,9 +80,9 @@ wait() { } current_thread->_waiting_on_cvar = this; - _mutex.do_release(); + _mutex.do_unlock(); _impl.wait(); // temporarily releases _global_lock - _mutex.do_acquire(current_thread); + _mutex.do_lock(current_thread); nassertd(current_thread->_waiting_on_cvar == this) { } @@ -93,7 +93,7 @@ wait() { << *current_thread << " awake on " << *this << "\n"; } - _mutex._global_lock->release(); + _mutex._global_lock->unlock(); } /** @@ -106,7 +106,7 @@ wait() { */ void ConditionVarDebug:: wait(double timeout) { - _mutex._global_lock->acquire(); + _mutex._global_lock->lock(); Thread *current_thread = Thread::get_current_thread(); @@ -115,7 +115,7 @@ wait(double timeout) { ostr << *current_thread << " attempted to wait on " << *this << " without holding " << _mutex; nassert_raise(ostr.str()); - _mutex._global_lock->release(); + _mutex._global_lock->unlock(); return; } @@ -130,9 +130,9 @@ wait(double timeout) { } current_thread->_waiting_on_cvar = this; - _mutex.do_release(); + _mutex.do_unlock(); _impl.wait(timeout); // temporarily releases _global_lock - _mutex.do_acquire(current_thread); + _mutex.do_lock(current_thread); nassertd(current_thread->_waiting_on_cvar == this) { } @@ -143,7 +143,7 @@ wait(double timeout) { << *current_thread << " awake on " << *this << "\n"; } - _mutex._global_lock->release(); + _mutex._global_lock->unlock(); } /** @@ -160,7 +160,7 @@ wait(double timeout) { */ void ConditionVarDebug:: notify() { - _mutex._global_lock->acquire(); + _mutex._global_lock->lock(); Thread *current_thread = Thread::get_current_thread(); @@ -169,7 +169,7 @@ notify() { ostr << *current_thread << " attempted to notify " << *this << " without holding " << _mutex; nassert_raise(ostr.str()); - _mutex._global_lock->release(); + _mutex._global_lock->unlock(); return; } @@ -179,7 +179,7 @@ notify() { } _impl.notify(); - _mutex._global_lock->release(); + _mutex._global_lock->unlock(); } /** diff --git a/panda/src/pipeline/conditionVarDebug.h b/panda/src/pipeline/conditionVarDebug.h index 7cbacbaf0d..b8243438c9 100644 --- a/panda/src/pipeline/conditionVarDebug.h +++ b/panda/src/pipeline/conditionVarDebug.h @@ -32,10 +32,10 @@ class EXPCL_PANDA_PIPELINE ConditionVarDebug { public: explicit ConditionVarDebug(MutexDebug &mutex); + ConditionVarDebug(const ConditionVarDebug ©) = delete; virtual ~ConditionVarDebug(); -private: - INLINE ConditionVarDebug(const ConditionVarDebug ©); - INLINE void operator = (const ConditionVarDebug ©); + + ConditionVarDebug &operator = (const ConditionVarDebug ©) = delete; PUBLISHED: INLINE MutexDebug &get_mutex() const; diff --git a/panda/src/pipeline/conditionVarDirect.I b/panda/src/pipeline/conditionVarDirect.I index 6b9d0351bf..bf8e42aea5 100644 --- a/panda/src/pipeline/conditionVarDirect.I +++ b/panda/src/pipeline/conditionVarDirect.I @@ -24,32 +24,6 @@ ConditionVarDirect(MutexDirect &mutex) : { } -/** - * - */ -INLINE ConditionVarDirect:: -~ConditionVarDirect() { -} - -/** - * Do not attempt to copy condition variables. - */ -INLINE ConditionVarDirect:: -ConditionVarDirect(const ConditionVarDirect ©) : - _mutex(copy._mutex), - _impl(_mutex._impl) -{ - nassertv(false); -} - -/** - * Do not attempt to copy condition variables. - */ -INLINE void ConditionVarDirect:: -operator = (const ConditionVarDirect ©) { - nassertv(false); -} - /** * Returns the mutex associated with this condition variable. */ diff --git a/panda/src/pipeline/conditionVarDirect.h b/panda/src/pipeline/conditionVarDirect.h index 116f22b899..7315c0b0bb 100644 --- a/panda/src/pipeline/conditionVarDirect.h +++ b/panda/src/pipeline/conditionVarDirect.h @@ -32,10 +32,10 @@ class EXPCL_PANDA_PIPELINE ConditionVarDirect { public: INLINE explicit ConditionVarDirect(MutexDirect &mutex); - INLINE ~ConditionVarDirect(); -private: - INLINE ConditionVarDirect(const ConditionVarDirect ©); - INLINE void operator = (const ConditionVarDirect ©); + ConditionVarDirect(const ConditionVarDirect ©) = delete; + ~ConditionVarDirect() = default; + + ConditionVarDirect &operator = (const ConditionVarDirect ©) = delete; PUBLISHED: INLINE MutexDirect &get_mutex() const; diff --git a/panda/src/pipeline/conditionVarFull.I b/panda/src/pipeline/conditionVarFull.I index 21b93b5ec6..b796e7aed2 100644 --- a/panda/src/pipeline/conditionVarFull.I +++ b/panda/src/pipeline/conditionVarFull.I @@ -27,35 +27,6 @@ ConditionVarFull(Mutex &mutex) : { } -/** - * - */ -INLINE ConditionVarFull:: -~ConditionVarFull() { -} - -/** - * Do not attempt to copy condition variables. - */ -INLINE ConditionVarFull:: -ConditionVarFull(const ConditionVarFull ©) : -#ifdef DEBUG_THREADS - ConditionVarFullDebug(copy.get_mutex()) -#else - ConditionVarFullDirect(copy.get_mutex()) -#endif // DEBUG_THREADS -{ - nassertv(false); -} - -/** - * Do not attempt to copy condition variables. - */ -INLINE void ConditionVarFull:: -operator = (const ConditionVarFull ©) { - nassertv(false); -} - /** * Returns the mutex associated with this condition variable. */ diff --git a/panda/src/pipeline/conditionVarFull.h b/panda/src/pipeline/conditionVarFull.h index 5f8b7ea731..37a9af1e11 100644 --- a/panda/src/pipeline/conditionVarFull.h +++ b/panda/src/pipeline/conditionVarFull.h @@ -46,12 +46,11 @@ class EXPCL_PANDA_PIPELINE ConditionVarFull : public ConditionVarFullDirect { PUBLISHED: INLINE explicit ConditionVarFull(Mutex &mutex); - INLINE ~ConditionVarFull(); -private: - INLINE ConditionVarFull(const ConditionVarFull ©); - INLINE void operator = (const ConditionVarFull ©); + ConditionVarFull(const ConditionVarFull ©) = delete; + ~ConditionVarFull() = default; + + ConditionVarFull &operator = (const ConditionVarFull ©) = delete; -PUBLISHED: INLINE Mutex &get_mutex() const; }; diff --git a/panda/src/pipeline/conditionVarFullDebug.I b/panda/src/pipeline/conditionVarFullDebug.I index bbf60f603d..5a09f03a3d 100644 --- a/panda/src/pipeline/conditionVarFullDebug.I +++ b/panda/src/pipeline/conditionVarFullDebug.I @@ -11,25 +11,6 @@ * @date 2006-08-28 */ -/** - * Do not attempt to copy condition variables. - */ -INLINE ConditionVarFullDebug:: -ConditionVarFullDebug(const ConditionVarFullDebug ©) : - _mutex(copy._mutex), - _impl(*_mutex._global_lock) -{ - nassertv(false); -} - -/** - * Do not attempt to copy condition variables. - */ -INLINE void ConditionVarFullDebug:: -operator = (const ConditionVarFullDebug ©) { - nassertv(false); -} - /** * Returns the mutex associated with this condition variable. */ diff --git a/panda/src/pipeline/conditionVarFullDebug.cxx b/panda/src/pipeline/conditionVarFullDebug.cxx index 4c76b513d0..8f59702a3f 100644 --- a/panda/src/pipeline/conditionVarFullDebug.cxx +++ b/panda/src/pipeline/conditionVarFullDebug.cxx @@ -57,7 +57,7 @@ ConditionVarFullDebug:: */ void ConditionVarFullDebug:: wait() { - _mutex._global_lock->acquire(); + _mutex._global_lock->lock(); Thread *current_thread = Thread::get_current_thread(); @@ -66,7 +66,7 @@ wait() { ostr << *current_thread << " attempted to wait on " << *this << " without holding " << _mutex; nassert_raise(ostr.str()); - _mutex._global_lock->release(); + _mutex._global_lock->unlock(); return; } @@ -80,9 +80,9 @@ wait() { } current_thread->_waiting_on_cvar_full = this; - _mutex.do_release(); + _mutex.do_unlock(); _impl.wait(); // temporarily releases _global_lock - _mutex.do_acquire(current_thread); + _mutex.do_lock(current_thread); nassertd(current_thread->_waiting_on_cvar_full == this) { } @@ -93,7 +93,7 @@ wait() { << *current_thread << " awake on " << *this << "\n"; } - _mutex._global_lock->release(); + _mutex._global_lock->unlock(); } /** @@ -106,7 +106,7 @@ wait() { */ void ConditionVarFullDebug:: wait(double timeout) { - _mutex._global_lock->acquire(); + _mutex._global_lock->lock(); Thread *current_thread = Thread::get_current_thread(); @@ -115,7 +115,7 @@ wait(double timeout) { ostr << *current_thread << " attempted to wait on " << *this << " without holding " << _mutex; nassert_raise(ostr.str()); - _mutex._global_lock->release(); + _mutex._global_lock->unlock(); return; } @@ -130,9 +130,9 @@ wait(double timeout) { } current_thread->_waiting_on_cvar_full = this; - _mutex.do_release(); + _mutex.do_unlock(); _impl.wait(timeout); // temporarily releases _global_lock - _mutex.do_acquire(current_thread); + _mutex.do_lock(current_thread); nassertd(current_thread->_waiting_on_cvar_full == this) { } @@ -143,7 +143,7 @@ wait(double timeout) { << *current_thread << " awake on " << *this << "\n"; } - _mutex._global_lock->release(); + _mutex._global_lock->unlock(); } /** @@ -160,7 +160,7 @@ wait(double timeout) { */ void ConditionVarFullDebug:: notify() { - _mutex._global_lock->acquire(); + _mutex._global_lock->lock(); Thread *current_thread = Thread::get_current_thread(); @@ -169,7 +169,7 @@ notify() { ostr << *current_thread << " attempted to notify " << *this << " without holding " << _mutex; nassert_raise(ostr.str()); - _mutex._global_lock->release(); + _mutex._global_lock->unlock(); return; } @@ -179,7 +179,7 @@ notify() { } _impl.notify(); - _mutex._global_lock->release(); + _mutex._global_lock->unlock(); } /** @@ -193,7 +193,7 @@ notify() { */ void ConditionVarFullDebug:: notify_all() { - _mutex._global_lock->acquire(); + _mutex._global_lock->lock(); Thread *current_thread = Thread::get_current_thread(); @@ -202,7 +202,7 @@ notify_all() { ostr << *current_thread << " attempted to notify " << *this << " without holding " << _mutex; nassert_raise(ostr.str()); - _mutex._global_lock->release(); + _mutex._global_lock->unlock(); return; } @@ -212,7 +212,7 @@ notify_all() { } _impl.notify_all(); - _mutex._global_lock->release(); + _mutex._global_lock->unlock(); } /** diff --git a/panda/src/pipeline/conditionVarFullDebug.h b/panda/src/pipeline/conditionVarFullDebug.h index 02c5957f72..696a57e2cf 100644 --- a/panda/src/pipeline/conditionVarFullDebug.h +++ b/panda/src/pipeline/conditionVarFullDebug.h @@ -32,10 +32,10 @@ class EXPCL_PANDA_PIPELINE ConditionVarFullDebug { public: explicit ConditionVarFullDebug(MutexDebug &mutex); + ConditionVarFullDebug(const ConditionVarFullDebug ©) = delete; virtual ~ConditionVarFullDebug(); -private: - INLINE ConditionVarFullDebug(const ConditionVarFullDebug ©); - INLINE void operator = (const ConditionVarFullDebug ©); + + ConditionVarFullDebug &operator = (const ConditionVarFullDebug ©) = delete; PUBLISHED: INLINE MutexDebug &get_mutex() const; diff --git a/panda/src/pipeline/conditionVarFullDirect.I b/panda/src/pipeline/conditionVarFullDirect.I index fa0da2b3c6..207cb01538 100644 --- a/panda/src/pipeline/conditionVarFullDirect.I +++ b/panda/src/pipeline/conditionVarFullDirect.I @@ -24,32 +24,6 @@ ConditionVarFullDirect(MutexDirect &mutex) : { } -/** - * - */ -INLINE ConditionVarFullDirect:: -~ConditionVarFullDirect() { -} - -/** - * Do not attempt to copy condition variables. - */ -INLINE ConditionVarFullDirect:: -ConditionVarFullDirect(const ConditionVarFullDirect ©) : - _mutex(copy._mutex), - _impl(_mutex._impl) -{ - nassertv(false); -} - -/** - * Do not attempt to copy condition variables. - */ -INLINE void ConditionVarFullDirect:: -operator = (const ConditionVarFullDirect ©) { - nassertv(false); -} - /** * Returns the mutex associated with this condition variable. */ diff --git a/panda/src/pipeline/conditionVarFullDirect.h b/panda/src/pipeline/conditionVarFullDirect.h index 45cd0ac3f4..e2db984ab9 100644 --- a/panda/src/pipeline/conditionVarFullDirect.h +++ b/panda/src/pipeline/conditionVarFullDirect.h @@ -32,10 +32,10 @@ class EXPCL_PANDA_PIPELINE ConditionVarFullDirect { public: INLINE explicit ConditionVarFullDirect(MutexDirect &mutex); - INLINE ~ConditionVarFullDirect(); -private: - INLINE ConditionVarFullDirect(const ConditionVarFullDirect ©); - INLINE void operator = (const ConditionVarFullDirect ©); + ConditionVarFullDirect(const ConditionVarFullDirect ©) = delete; + ~ConditionVarFullDirect() = default; + + ConditionVarFullDirect &operator = (const ConditionVarFullDirect ©) = delete; PUBLISHED: INLINE MutexDirect &get_mutex() const; diff --git a/panda/src/pipeline/conditionVarSimpleImpl.cxx b/panda/src/pipeline/conditionVarSimpleImpl.cxx index 9c60c98ff0..761798d227 100644 --- a/panda/src/pipeline/conditionVarSimpleImpl.cxx +++ b/panda/src/pipeline/conditionVarSimpleImpl.cxx @@ -23,14 +23,14 @@ */ void ConditionVarSimpleImpl:: wait() { - _mutex.release_quietly(); + _mutex.unlock_quietly(); ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr(); ThreadSimpleImpl *thread = manager->get_current_thread(); manager->enqueue_block(thread, this); manager->next_context(); - _mutex.acquire(); + _mutex.lock(); } /** @@ -38,7 +38,7 @@ wait() { */ void ConditionVarSimpleImpl:: wait(double timeout) { - _mutex.release_quietly(); + _mutex.unlock_quietly(); // TODO. For now this will release every frame, since we don't have an // interface yet on ThreadSimpleManager to do a timed wait. Maybe that's @@ -49,7 +49,7 @@ wait(double timeout) { manager->enqueue_ready(thread, true); manager->next_context(); - _mutex.acquire(); + _mutex.lock(); } /** diff --git a/panda/src/pipeline/cycleData.h b/panda/src/pipeline/cycleData.h index 72ba074088..44c0a7b88c 100644 --- a/panda/src/pipeline/cycleData.h +++ b/panda/src/pipeline/cycleData.h @@ -49,9 +49,9 @@ class EXPCL_PANDA_PIPELINE CycleData #endif // DO_PIPELINING { public: - INLINE CycleData() DEFAULT_CTOR; - INLINE CycleData(CycleData &&from) DEFAULT_CTOR; - INLINE CycleData(const CycleData ©) DEFAULT_CTOR; + INLINE CycleData() = default; + INLINE CycleData(CycleData &&from) = default; + INLINE CycleData(const CycleData ©) = default; virtual ~CycleData(); virtual CycleData *make_copy() const=0; diff --git a/panda/src/pipeline/cycleDataLockedReader.I b/panda/src/pipeline/cycleDataLockedReader.I index 0ac88ebb67..311314e1dd 100644 --- a/panda/src/pipeline/cycleDataLockedReader.I +++ b/panda/src/pipeline/cycleDataLockedReader.I @@ -61,13 +61,12 @@ operator = (const CycleDataLockedReader ©) { _cycler->increment_read(_pointer); } -#ifdef USE_MOVE_SEMANTICS /** * */ template INLINE CycleDataLockedReader:: -CycleDataLockedReader(CycleDataLockedReader &&from) NOEXCEPT : +CycleDataLockedReader(CycleDataLockedReader &&from) noexcept : _cycler(from._cycler), _current_thread(from._current_thread), _pointer(from._pointer) @@ -80,7 +79,7 @@ CycleDataLockedReader(CycleDataLockedReader &&from) NOEXCEPT : */ template INLINE void CycleDataLockedReader:: -operator = (CycleDataLockedReader &&from) NOEXCEPT { +operator = (CycleDataLockedReader &&from) noexcept { nassertv(_pointer == (CycleDataType *)NULL); nassertv(_current_thread == from._current_thread); @@ -89,7 +88,6 @@ operator = (CycleDataLockedReader &&from) NOEXCEPT { from._pointer = NULL; } -#endif // USE_MOVE_SEMANTICS /** * diff --git a/panda/src/pipeline/cycleDataLockedReader.h b/panda/src/pipeline/cycleDataLockedReader.h index f66143fab4..62c1a72b1a 100644 --- a/panda/src/pipeline/cycleDataLockedReader.h +++ b/panda/src/pipeline/cycleDataLockedReader.h @@ -45,12 +45,10 @@ public: INLINE CycleDataLockedReader(const PipelineCycler &cycler, Thread *current_thread = Thread::get_current_thread()); INLINE CycleDataLockedReader(const CycleDataLockedReader ©); - INLINE void operator = (const CycleDataLockedReader ©); + INLINE CycleDataLockedReader(CycleDataLockedReader &&from) noexcept; -#if defined(USE_MOVE_SEMANTICS) && defined(DO_PIPELINING) - INLINE CycleDataLockedReader(CycleDataLockedReader &&from) NOEXCEPT; - INLINE void operator = (CycleDataLockedReader &&from) NOEXCEPT; -#endif + INLINE void operator = (const CycleDataLockedReader ©); + INLINE void operator = (CycleDataLockedReader &&from) noexcept; INLINE ~CycleDataLockedReader(); diff --git a/panda/src/pipeline/cycleDataLockedStageReader.I b/panda/src/pipeline/cycleDataLockedStageReader.I index 9f2c74d23a..d65d9da889 100644 --- a/panda/src/pipeline/cycleDataLockedStageReader.I +++ b/panda/src/pipeline/cycleDataLockedStageReader.I @@ -64,13 +64,12 @@ operator = (const CycleDataLockedStageReader ©) { _cycler->increment_read(_pointer); } -#ifdef USE_MOVE_SEMANTICS /** * */ template INLINE CycleDataLockedStageReader:: -CycleDataLockedStageReader(CycleDataLockedStageReader &&from) NOEXCEPT : +CycleDataLockedStageReader(CycleDataLockedStageReader &&from) noexcept : _cycler(from._cycler), _current_thread(from._current_thread), _pointer(from._pointer), @@ -84,7 +83,7 @@ CycleDataLockedStageReader(CycleDataLockedStageReader &&from) NOE */ template INLINE void CycleDataLockedStageReader:: -operator = (CycleDataLockedStageReader &&from) NOEXCEPT { +operator = (CycleDataLockedStageReader &&from) noexcept { nassertv(_pointer == (CycleDataType *)NULL); nassertv(_current_thread == from._current_thread); @@ -94,7 +93,6 @@ operator = (CycleDataLockedStageReader &&from) NOEXCEPT { from._pointer = NULL; } -#endif // USE_MOVE_SEMANTICS /** * diff --git a/panda/src/pipeline/cycleDataLockedStageReader.h b/panda/src/pipeline/cycleDataLockedStageReader.h index 6837a6edf4..4220a2ce0f 100644 --- a/panda/src/pipeline/cycleDataLockedStageReader.h +++ b/panda/src/pipeline/cycleDataLockedStageReader.h @@ -32,12 +32,10 @@ public: INLINE CycleDataLockedStageReader(const PipelineCycler &cycler, int stage, Thread *current_thread = Thread::get_current_thread()); INLINE CycleDataLockedStageReader(const CycleDataLockedStageReader ©); - INLINE void operator = (const CycleDataLockedStageReader ©); + INLINE CycleDataLockedStageReader(CycleDataLockedStageReader &&from) noexcept; -#if defined(USE_MOVE_SEMANTICS) && defined(DO_PIPELINING) - INLINE CycleDataLockedStageReader(CycleDataLockedStageReader &&from) NOEXCEPT; - INLINE void operator = (CycleDataLockedStageReader &&from) NOEXCEPT; -#endif + INLINE void operator = (const CycleDataLockedStageReader ©); + INLINE void operator = (CycleDataLockedStageReader &&from) noexcept; INLINE ~CycleDataLockedStageReader(); diff --git a/panda/src/pipeline/cycleDataStageWriter.I b/panda/src/pipeline/cycleDataStageWriter.I index 3e6d464768..a4ccc54c60 100644 --- a/panda/src/pipeline/cycleDataStageWriter.I +++ b/panda/src/pipeline/cycleDataStageWriter.I @@ -114,13 +114,12 @@ CycleDataStageWriter(PipelineCycler &cycler, int stage, force_to_0, _current_thread); } -#ifdef USE_MOVE_SEMANTICS /** * */ template INLINE CycleDataStageWriter:: -CycleDataStageWriter(CycleDataStageWriter &&from) NOEXCEPT : +CycleDataStageWriter(CycleDataStageWriter &&from) noexcept : _cycler(from._cycler), _current_thread(from._current_thread), _pointer(from._pointer), @@ -134,7 +133,7 @@ CycleDataStageWriter(CycleDataStageWriter &&from) NOEXCEPT : */ template INLINE void CycleDataStageWriter:: -operator = (CycleDataStageWriter &&from) NOEXCEPT { +operator = (CycleDataStageWriter &&from) noexcept { nassertv(_pointer == (CycleDataType *)NULL); nassertv(_current_thread == from._current_thread); @@ -144,7 +143,6 @@ operator = (CycleDataStageWriter &&from) NOEXCEPT { from._pointer = NULL; } -#endif // USE_MOVE_SEMANTICS /** * diff --git a/panda/src/pipeline/cycleDataStageWriter.h b/panda/src/pipeline/cycleDataStageWriter.h index d154adb6d8..0357d1863d 100644 --- a/panda/src/pipeline/cycleDataStageWriter.h +++ b/panda/src/pipeline/cycleDataStageWriter.h @@ -39,7 +39,7 @@ public: bool force_to_0, Thread *current_thread = Thread::get_current_thread()); INLINE CycleDataStageWriter(const CycleDataStageWriter ©); - INLINE void operator = (const CycleDataStageWriter ©); + INLINE CycleDataStageWriter(CycleDataStageWriter &&from) noexcept; INLINE CycleDataStageWriter(PipelineCycler &cycler, int stage, CycleDataLockedStageReader &take_from); @@ -47,13 +47,11 @@ public: CycleDataLockedStageReader &take_from, bool force_to_0); -#if defined(USE_MOVE_SEMANTICS) && defined(DO_PIPELINING) - INLINE CycleDataStageWriter(CycleDataStageWriter &&from) NOEXCEPT; - INLINE void operator = (CycleDataStageWriter &&from) NOEXCEPT; -#endif - INLINE ~CycleDataStageWriter(); + INLINE void operator = (const CycleDataStageWriter ©); + INLINE void operator = (CycleDataStageWriter &&from) noexcept; + INLINE CycleDataType *operator -> (); INLINE const CycleDataType *operator -> () const; diff --git a/panda/src/pipeline/cycleDataWriter.I b/panda/src/pipeline/cycleDataWriter.I index 3706468612..e142c38b3a 100644 --- a/panda/src/pipeline/cycleDataWriter.I +++ b/panda/src/pipeline/cycleDataWriter.I @@ -130,13 +130,12 @@ CycleDataWriter(PipelineCycler &cycler, force_to_0, _current_thread); } -#ifdef USE_MOVE_SEMANTICS /** * */ template INLINE CycleDataWriter:: -CycleDataWriter(CycleDataWriter &&from) NOEXCEPT : +CycleDataWriter(CycleDataWriter &&from) noexcept : _cycler(from._cycler), _current_thread(from._current_thread), _pointer(from._pointer) @@ -149,7 +148,7 @@ CycleDataWriter(CycleDataWriter &&from) NOEXCEPT : */ template INLINE void CycleDataWriter:: -operator = (CycleDataWriter &&from) NOEXCEPT { +operator = (CycleDataWriter &&from) noexcept { nassertv(_pointer == (CycleDataType *)NULL); nassertv(_current_thread == from._current_thread); @@ -158,7 +157,6 @@ operator = (CycleDataWriter &&from) NOEXCEPT { from._pointer = NULL; } -#endif // USE_MOVE_SEMANTICS /** * diff --git a/panda/src/pipeline/cycleDataWriter.h b/panda/src/pipeline/cycleDataWriter.h index e2a4da7831..616ddae28e 100644 --- a/panda/src/pipeline/cycleDataWriter.h +++ b/panda/src/pipeline/cycleDataWriter.h @@ -44,15 +44,13 @@ public: CycleDataType *locked_cdata, Thread *current_thread = Thread::get_current_thread()); INLINE CycleDataWriter(const CycleDataWriter ©); - INLINE void operator = (const CycleDataWriter ©); + INLINE CycleDataWriter(CycleDataWriter &&from) noexcept; INLINE CycleDataWriter(PipelineCycler &cycler, CycleDataLockedReader &take_from); INLINE CycleDataWriter(PipelineCycler &cycler, CycleDataLockedReader &take_from, bool force_to_0); -#if defined(USE_MOVE_SEMANTICS) && defined(DO_PIPELINING) - INLINE CycleDataWriter(CycleDataWriter &&from) NOEXCEPT; - INLINE void operator = (CycleDataWriter &&from) NOEXCEPT; -#endif + INLINE void operator = (CycleDataWriter &&from) noexcept; + INLINE void operator = (const CycleDataWriter ©); INLINE ~CycleDataWriter(); diff --git a/panda/src/pipeline/cyclerHolder.I b/panda/src/pipeline/cyclerHolder.I index d9d2782373..f30ca75751 100644 --- a/panda/src/pipeline/cyclerHolder.I +++ b/panda/src/pipeline/cyclerHolder.I @@ -31,19 +31,3 @@ INLINE CyclerHolder:: _cycler->release(); #endif } - -/** - * Do not attempt to copy CyclerHolders. - */ -INLINE CyclerHolder:: -CyclerHolder(const CyclerHolder ©) { - nassertv(false); -} - -/** - * Do not attempt to copy CyclerHolders. - */ -INLINE void CyclerHolder:: -operator = (const CyclerHolder ©) { - nassertv(false); -} diff --git a/panda/src/pipeline/cyclerHolder.h b/panda/src/pipeline/cyclerHolder.h index fa5b81a30f..f1888345be 100644 --- a/panda/src/pipeline/cyclerHolder.h +++ b/panda/src/pipeline/cyclerHolder.h @@ -25,10 +25,10 @@ class EXPCL_PANDA_PIPELINE CyclerHolder { public: INLINE CyclerHolder(PipelineCyclerBase &cycler); + CyclerHolder(const CyclerHolder ©) = delete; INLINE ~CyclerHolder(); -private: - INLINE CyclerHolder(const CyclerHolder ©); - INLINE void operator = (const CyclerHolder ©); + + CyclerHolder &operator = (const CyclerHolder ©) = delete; private: #ifdef DO_PIPELINING diff --git a/panda/src/pipeline/lightMutex.I b/panda/src/pipeline/lightMutex.I index a7bb09ed17..4121d607e2 100644 --- a/panda/src/pipeline/lightMutex.I +++ b/panda/src/pipeline/lightMutex.I @@ -46,31 +46,3 @@ LightMutex(const string &) #endif // DEBUG_THREADS { } - -/** - * - */ -INLINE LightMutex:: -~LightMutex() { -} - -/** - * Do not attempt to copy lightMutexes. - */ -INLINE LightMutex:: -#ifdef DEBUG_THREADS -LightMutex(const LightMutex ©) : MutexDebug(string(), false, true) -#else - LightMutex(const LightMutex ©) -#endif // DEBUG_THREADS -{ - nassertv(false); -} - -/** - * Do not attempt to copy lightMutexes. - */ -INLINE void LightMutex:: -operator = (const LightMutex ©) { - nassertv(false); -} diff --git a/panda/src/pipeline/lightMutex.h b/panda/src/pipeline/lightMutex.h index 77ad4b26ae..4e2d1fa67b 100644 --- a/panda/src/pipeline/lightMutex.h +++ b/panda/src/pipeline/lightMutex.h @@ -45,10 +45,10 @@ public: INLINE explicit LightMutex(const char *name); PUBLISHED: INLINE explicit LightMutex(const string &name); - INLINE ~LightMutex(); -private: - INLINE LightMutex(const LightMutex ©); - INLINE void operator = (const LightMutex ©); + LightMutex(const LightMutex ©) = delete; + ~LightMutex() = default; + + LightMutex &operator = (const LightMutex ©) = delete; }; #include "lightMutex.I" diff --git a/panda/src/pipeline/lightMutexDirect.I b/panda/src/pipeline/lightMutexDirect.I index 052ba9a8bf..041f388ce2 100644 --- a/panda/src/pipeline/lightMutexDirect.I +++ b/panda/src/pipeline/lightMutexDirect.I @@ -12,33 +12,33 @@ */ /** - * - */ -INLINE LightMutexDirect:: -LightMutexDirect() { -} - -/** - * - */ -INLINE LightMutexDirect:: -~LightMutexDirect() { -} - -/** - * Do not attempt to copy lightMutexes. - */ -INLINE LightMutexDirect:: -LightMutexDirect(const LightMutexDirect ©) { - nassertv(false); -} - -/** - * Do not attempt to copy lightMutexes. + * Alias for acquire() to match C++11 semantics. + * @see acquire() */ INLINE void LightMutexDirect:: -operator = (const LightMutexDirect ©) { - nassertv(false); +lock() { + TAU_PROFILE("void LightMutexDirect::acquire()", " ", TAU_USER); + _impl.lock(); +} + +/** + * Alias for try_acquire() to match C++11 semantics. + * @see try_acquire() + */ +INLINE bool LightMutexDirect:: +try_lock() { + TAU_PROFILE("void LightMutexDirect::try_acquire()", " ", TAU_USER); + return _impl.try_lock(); +} + +/** + * Alias for release() to match C++11 semantics. + * @see release() + */ +INLINE void LightMutexDirect:: +unlock() { + TAU_PROFILE("void LightMutexDirect::unlock()", " ", TAU_USER); + _impl.unlock(); } /** @@ -55,7 +55,7 @@ operator = (const LightMutexDirect ©) { INLINE void LightMutexDirect:: acquire() const { TAU_PROFILE("void LightMutexDirect::acquire()", " ", TAU_USER); - ((LightMutexDirect *)this)->_impl.acquire(); + _impl.lock(); } /** @@ -68,7 +68,7 @@ acquire() const { INLINE void LightMutexDirect:: release() const { TAU_PROFILE("void LightMutexDirect::release()", " ", TAU_USER); - ((LightMutexDirect *)this)->_impl.release(); + _impl.unlock(); } /** diff --git a/panda/src/pipeline/lightMutexDirect.h b/panda/src/pipeline/lightMutexDirect.h index e2085f6d29..78ffcce433 100644 --- a/panda/src/pipeline/lightMutexDirect.h +++ b/panda/src/pipeline/lightMutexDirect.h @@ -30,11 +30,16 @@ class Thread; */ class EXPCL_PANDA_PIPELINE LightMutexDirect { protected: - INLINE LightMutexDirect(); - INLINE ~LightMutexDirect(); -private: - INLINE LightMutexDirect(const LightMutexDirect ©); - INLINE void operator = (const LightMutexDirect ©); + LightMutexDirect() = default; + LightMutexDirect(const LightMutexDirect ©) = delete; + ~LightMutexDirect() = default; + + void operator = (const LightMutexDirect ©) = delete; + +public: + INLINE void lock(); + INLINE bool try_lock(); + INLINE void unlock(); PUBLISHED: BLOCKING INLINE void acquire() const; @@ -54,9 +59,9 @@ private: // even in the SIMPLE_THREADS case. We have to do this since any PStatTimer // call may trigger a context switch, and any low-level context switch // requires all containing mutexes to be true mutexes. - MutexTrueImpl _impl; + mutable MutexTrueImpl _impl; #else - MutexImpl _impl; + mutable MutexImpl _impl; #endif // DO_PSTATS }; diff --git a/panda/src/pipeline/lightMutexHolder.I b/panda/src/pipeline/lightMutexHolder.I index 392a234b29..fb8a8951e4 100644 --- a/panda/src/pipeline/lightMutexHolder.I +++ b/panda/src/pipeline/lightMutexHolder.I @@ -50,19 +50,3 @@ INLINE LightMutexHolder:: _mutex->release(); #endif } - -/** - * Do not attempt to copy LightMutexHolders. - */ -INLINE LightMutexHolder:: -LightMutexHolder(const LightMutexHolder ©) { - nassertv(false); -} - -/** - * Do not attempt to copy LightMutexHolders. - */ -INLINE void LightMutexHolder:: -operator = (const LightMutexHolder ©) { - nassertv(false); -} diff --git a/panda/src/pipeline/lightMutexHolder.h b/panda/src/pipeline/lightMutexHolder.h index 778ac69722..fde6a4ba9a 100644 --- a/panda/src/pipeline/lightMutexHolder.h +++ b/panda/src/pipeline/lightMutexHolder.h @@ -26,10 +26,10 @@ class EXPCL_PANDA_PIPELINE LightMutexHolder { public: INLINE LightMutexHolder(const LightMutex &mutex); INLINE LightMutexHolder(LightMutex *&mutex); + LightMutexHolder(const LightMutexHolder ©) = delete; INLINE ~LightMutexHolder(); -private: - INLINE LightMutexHolder(const LightMutexHolder ©); - INLINE void operator = (const LightMutexHolder ©); + + LightMutexHolder &operator = (const LightMutexHolder ©) = delete; private: #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) diff --git a/panda/src/pipeline/lightReMutex.I b/panda/src/pipeline/lightReMutex.I index e1993f5dee..c0cb459c87 100644 --- a/panda/src/pipeline/lightReMutex.I +++ b/panda/src/pipeline/lightReMutex.I @@ -46,18 +46,3 @@ LightReMutex(const string &) #endif // DEBUG_THREADS { } - -/** - * - */ -INLINE LightReMutex:: -~LightReMutex() { -} - -/** - * Do not attempt to copy mutexes. - */ -INLINE void LightReMutex:: -operator = (const LightReMutex ©) { - nassertv(false); -} diff --git a/panda/src/pipeline/lightReMutex.h b/panda/src/pipeline/lightReMutex.h index 6959c4ab17..2fff13a1ee 100644 --- a/panda/src/pipeline/lightReMutex.h +++ b/panda/src/pipeline/lightReMutex.h @@ -36,10 +36,10 @@ public: INLINE explicit LightReMutex(const char *name); PUBLISHED: INLINE explicit LightReMutex(const string &name); - INLINE ~LightReMutex(); -private: - INLINE LightReMutex(const LightReMutex ©); - INLINE void operator = (const LightReMutex ©); + LightReMutex(const LightReMutex ©) = delete; + ~LightReMutex() = default; + + LightReMutex &operator = (const LightReMutex ©) = delete; }; #include "lightReMutex.I" diff --git a/panda/src/pipeline/lightReMutexDirect.I b/panda/src/pipeline/lightReMutexDirect.I index be78a3919e..388387517c 100644 --- a/panda/src/pipeline/lightReMutexDirect.I +++ b/panda/src/pipeline/lightReMutexDirect.I @@ -27,30 +27,33 @@ LightReMutexDirect() } /** - * - */ -INLINE LightReMutexDirect:: -~LightReMutexDirect() { -} - -/** - * Do not attempt to copy lightReMutexes. - */ -INLINE LightReMutexDirect:: -LightReMutexDirect(const LightReMutexDirect ©) -#ifndef HAVE_REMUTEXIMPL - : _cvar_impl(_lock_impl) -#endif -{ - nassertv(false); -} - -/** - * Do not attempt to copy lightReMutexes. + * Alias for acquire() to match C++11 semantics. + * @see acquire() */ INLINE void LightReMutexDirect:: -operator = (const LightReMutexDirect ©) { - nassertv(false); +lock() { + TAU_PROFILE("void LightReMutexDirect::acquire()", " ", TAU_USER); + _impl.lock(); +} + +/** + * Alias for try_acquire() to match C++11 semantics. + * @see try_acquire() + */ +INLINE bool LightReMutexDirect:: +try_lock() { + TAU_PROFILE("void LightReMutexDirect::try_acquire()", " ", TAU_USER); + return _impl.try_lock(); +} + +/** + * Alias for release() to match C++11 semantics. + * @see release() + */ +INLINE void LightReMutexDirect:: +unlock() { + TAU_PROFILE("void LightReMutexDirect::unlock()", " ", TAU_USER); + _impl.unlock(); } /** @@ -67,7 +70,11 @@ operator = (const LightReMutexDirect ©) { INLINE void LightReMutexDirect:: acquire() const { TAU_PROFILE("void LightReMutexDirect::acquire()", " ", TAU_USER); - ((LightReMutexDirect *)this)->_impl.acquire(); +#ifdef HAVE_REMUTEXTRUEIMPL + _impl.lock(); +#else + _impl.do_lock(Thread::get_current_thread()); +#endif } /** @@ -77,10 +84,10 @@ acquire() const { INLINE void LightReMutexDirect:: acquire(Thread *current_thread) const { TAU_PROFILE("void LightReMutexDirect::acquire(Thread *)", " ", TAU_USER); -#ifdef HAVE_REMUTEXIMPL - ((LightReMutexDirect *)this)->_impl.acquire(); +#ifdef HAVE_REMUTEXTRUEIMPL + _impl.lock(); #else - ((LightReMutexDirect *)this)->_impl.do_lock(current_thread); + _impl.do_lock(current_thread); #endif // HAVE_REMUTEXIMPL } @@ -97,10 +104,10 @@ acquire(Thread *current_thread) const { INLINE void LightReMutexDirect:: elevate_lock() const { TAU_PROFILE("void LightReMutexDirect::elevate_lock()", " ", TAU_USER); -#ifdef HAVE_REMUTEXIMPL - ((LightReMutexDirect *)this)->_impl.acquire(); +#ifdef HAVE_REMUTEXTRUEIMPL + _impl.lock(); #else - ((LightReMutexDirect *)this)->_impl.do_elevate_lock(); + _impl.do_elevate_lock(); #endif // HAVE_REMUTEXIMPL } @@ -114,7 +121,11 @@ elevate_lock() const { INLINE void LightReMutexDirect:: release() const { TAU_PROFILE("void LightReMutexDirect::release()", " ", TAU_USER); - ((LightReMutexDirect *)this)->_impl.release(); +#ifdef HAVE_REMUTEXTRUEIMPL + _impl.unlock(); +#else + _impl.do_unlock(Thread::get_current_thread()); +#endif } /** diff --git a/panda/src/pipeline/lightReMutexDirect.h b/panda/src/pipeline/lightReMutexDirect.h index 9daeff46a2..21f25c1c31 100644 --- a/panda/src/pipeline/lightReMutexDirect.h +++ b/panda/src/pipeline/lightReMutexDirect.h @@ -30,10 +30,15 @@ class Thread; class EXPCL_PANDA_PIPELINE LightReMutexDirect { protected: INLINE LightReMutexDirect(); - INLINE ~LightReMutexDirect(); -private: - INLINE LightReMutexDirect(const LightReMutexDirect ©); - INLINE void operator = (const LightReMutexDirect ©); + LightReMutexDirect(const LightReMutexDirect ©) = delete; + ~LightReMutexDirect() = default; + + void operator = (const LightReMutexDirect ©) = delete; + +public: + INLINE void lock(); + INLINE bool try_lock(); + INLINE void unlock(); PUBLISHED: BLOCKING INLINE void acquire() const; @@ -51,13 +56,13 @@ PUBLISHED: void output(ostream &out) const; private: -#if defined(HAVE_REMUTEXIMPL) && !defined(DO_PSTATS) - ReMutexImpl _impl; +#ifdef HAVE_REMUTEXTRUEIMPL + mutable ReMutexImpl _impl; #else // If we don't have a reentrant mutex, use the one we hand-rolled in // ReMutexDirect. - ReMutexDirect _impl; + mutable ReMutexDirect _impl; #endif // HAVE_REMUTEXIMPL }; diff --git a/panda/src/pipeline/lightReMutexHolder.I b/panda/src/pipeline/lightReMutexHolder.I index 96141251d7..4158d92c26 100644 --- a/panda/src/pipeline/lightReMutexHolder.I +++ b/panda/src/pipeline/lightReMutexHolder.I @@ -62,19 +62,3 @@ INLINE LightReMutexHolder:: _mutex->release(); #endif } - -/** - * Do not attempt to copy LightReMutexHolders. - */ -INLINE LightReMutexHolder:: -LightReMutexHolder(const LightReMutexHolder ©) { - nassertv(false); -} - -/** - * Do not attempt to copy LightReMutexHolders. - */ -INLINE void LightReMutexHolder:: -operator = (const LightReMutexHolder ©) { - nassertv(false); -} diff --git a/panda/src/pipeline/lightReMutexHolder.h b/panda/src/pipeline/lightReMutexHolder.h index 462b22180b..019206fbac 100644 --- a/panda/src/pipeline/lightReMutexHolder.h +++ b/panda/src/pipeline/lightReMutexHolder.h @@ -27,10 +27,10 @@ public: INLINE LightReMutexHolder(const LightReMutex &mutex); INLINE LightReMutexHolder(const LightReMutex &mutex, Thread *current_thread); INLINE LightReMutexHolder(LightReMutex *&mutex); + LightReMutexHolder(const LightReMutexHolder ©) = delete; INLINE ~LightReMutexHolder(); -private: - INLINE LightReMutexHolder(const LightReMutexHolder ©); - INLINE void operator = (const LightReMutexHolder ©); + + LightReMutexHolder &operator = (const LightReMutexHolder ©) = delete; private: #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) diff --git a/panda/src/pipeline/mutexDebug.I b/panda/src/pipeline/mutexDebug.I index 6a487bde8f..9262f3e6d3 100644 --- a/panda/src/pipeline/mutexDebug.I +++ b/panda/src/pipeline/mutexDebug.I @@ -12,19 +12,40 @@ */ /** - * Do not attempt to copy mutexes. + * Alias for acquire() to match C++11 semantics. + * @see acquire() */ -INLINE MutexDebug:: -MutexDebug(const MutexDebug ©) : _cvar_impl(*get_global_lock()) { - nassertv(false); +INLINE void MutexDebug:: +lock() { + TAU_PROFILE("void MutexDebug::acquire()", " ", TAU_USER); + _global_lock->lock(); + ((MutexDebug *)this)->do_lock(Thread::get_current_thread()); + _global_lock->unlock(); } /** - * Do not attempt to copy mutexes. + * Alias for try_acquire() to match C++11 semantics. + * @see try_acquire() + */ +INLINE bool MutexDebug:: +try_lock() { + TAU_PROFILE("void MutexDebug::try_lock()", " ", TAU_USER); + _global_lock->lock(); + bool acquired = ((MutexDebug *)this)->do_try_lock(Thread::get_current_thread()); + _global_lock->unlock(); + return acquired; +} + +/** + * Alias for release() to match C++11 semantics. + * @see release() */ INLINE void MutexDebug:: -operator = (const MutexDebug ©) { - nassertv(false); +unlock() { + TAU_PROFILE("void MutexDebug::unlock()", " ", TAU_USER); + _global_lock->lock(); + ((MutexDebug *)this)->do_unlock(); + _global_lock->unlock(); } /** @@ -41,9 +62,9 @@ INLINE void MutexDebug:: acquire(Thread *current_thread) const { TAU_PROFILE("void MutexDebug::acquire(Thread *)", " ", TAU_USER); nassertv(current_thread == Thread::get_current_thread()); - _global_lock->acquire(); - ((MutexDebug *)this)->do_acquire(current_thread); - _global_lock->release(); + _global_lock->lock(); + ((MutexDebug *)this)->do_lock(current_thread); + _global_lock->unlock(); } /** @@ -52,11 +73,11 @@ acquire(Thread *current_thread) const { */ INLINE bool MutexDebug:: try_acquire(Thread *current_thread) const { - TAU_PROFILE("void MutexDebug::acquire(Thread *)", " ", TAU_USER); + TAU_PROFILE("void MutexDebug::try_acquire(Thread *)", " ", TAU_USER); nassertr(current_thread == Thread::get_current_thread(), false); - _global_lock->acquire(); - bool acquired = ((MutexDebug *)this)->do_try_acquire(current_thread); - _global_lock->release(); + _global_lock->lock(); + bool acquired = ((MutexDebug *)this)->do_try_lock(current_thread); + _global_lock->unlock(); return acquired; } @@ -93,9 +114,9 @@ elevate_lock() const { INLINE void MutexDebug:: release() const { TAU_PROFILE("void MutexDebug::release()", " ", TAU_USER); - _global_lock->acquire(); - ((MutexDebug *)this)->do_release(); - _global_lock->release(); + _global_lock->lock(); + ((MutexDebug *)this)->do_unlock(); + _global_lock->unlock(); } /** @@ -107,9 +128,9 @@ release() const { INLINE bool MutexDebug:: debug_is_locked() const { TAU_PROFILE("bool MutexDebug::debug_is_locked()", " ", TAU_USER); - _global_lock->acquire(); + _global_lock->lock(); bool is_locked = do_debug_is_locked(); - _global_lock->release(); + _global_lock->unlock(); return is_locked; } diff --git a/panda/src/pipeline/mutexDebug.cxx b/panda/src/pipeline/mutexDebug.cxx index d22a923694..ea75142fc6 100644 --- a/panda/src/pipeline/mutexDebug.cxx +++ b/panda/src/pipeline/mutexDebug.cxx @@ -84,12 +84,12 @@ output(ostream &out) const { */ void MutexDebug:: output_with_holder(ostream &out) const { - _global_lock->acquire(); + _global_lock->lock(); output(out); if (_locking_thread != (Thread *)NULL) { out << " (held by " << *_locking_thread << ")\n"; } - _global_lock->release(); + _global_lock->unlock(); } /** @@ -99,9 +99,9 @@ output_with_holder(ostream &out) const { */ void MutexDebug:: increment_pstats() { - _global_lock->acquire(); + _global_lock->lock(); ++_pstats_count; - _global_lock->release(); + _global_lock->unlock(); } /** @@ -110,16 +110,16 @@ increment_pstats() { */ void MutexDebug:: decrement_pstats() { - _global_lock->acquire(); + _global_lock->lock(); --_pstats_count; - _global_lock->release(); + _global_lock->unlock(); } /** * The private implementation of acquire() assumes that _lock_impl is held. */ void MutexDebug:: -do_acquire(Thread *current_thread) { +do_lock(Thread *current_thread) { // If this assertion is triggered, you tried to lock a recently-destructed // mutex. nassertd(_lock_count != -100) { @@ -235,7 +235,7 @@ do_acquire(Thread *current_thread) { * held. */ bool MutexDebug:: -do_try_acquire(Thread *current_thread) { +do_try_lock(Thread *current_thread) { // If this assertion is triggered, you tried to lock a recently-destructed // mutex. nassertd(_lock_count != -100) { @@ -301,7 +301,7 @@ do_try_acquire(Thread *current_thread) { * The private implementation of acquire() assumes that _lock_impl is held. */ void MutexDebug:: -do_release() { +do_unlock() { // If this assertion is triggered, you tried to release a recently- // destructed mutex. nassertd(_lock_count != -100) { diff --git a/panda/src/pipeline/mutexDebug.h b/panda/src/pipeline/mutexDebug.h index 24b8b6500f..4fc3e4eeaa 100644 --- a/panda/src/pipeline/mutexDebug.h +++ b/panda/src/pipeline/mutexDebug.h @@ -30,10 +30,15 @@ class EXPCL_PANDA_PIPELINE MutexDebug : public Namable { protected: MutexDebug(const string &name, bool allow_recursion, bool lightweight); + MutexDebug(const MutexDebug ©) = delete; virtual ~MutexDebug(); -private: - INLINE MutexDebug(const MutexDebug ©); - INLINE void operator = (const MutexDebug ©); + + void operator = (const MutexDebug ©) = delete; + +public: + INLINE void lock(); + INLINE bool try_lock(); + INLINE void unlock(); PUBLISHED: BLOCKING INLINE void acquire(Thread *current_thread = Thread::get_current_thread()) const; @@ -52,9 +57,9 @@ public: static void decrement_pstats(); private: - void do_acquire(Thread *current_thread); - bool do_try_acquire(Thread *current_thread); - void do_release(); + void do_lock(Thread *current_thread); + bool do_try_lock(Thread *current_thread); + void do_unlock(); bool do_debug_is_locked() const; void report_deadlock(Thread *current_thread); diff --git a/panda/src/pipeline/mutexDirect.I b/panda/src/pipeline/mutexDirect.I index 0fb8c8b954..e12442289c 100644 --- a/panda/src/pipeline/mutexDirect.I +++ b/panda/src/pipeline/mutexDirect.I @@ -12,33 +12,33 @@ */ /** - * - */ -INLINE MutexDirect:: -MutexDirect() { -} - -/** - * - */ -INLINE MutexDirect:: -~MutexDirect() { -} - -/** - * Do not attempt to copy mutexes. - */ -INLINE MutexDirect:: -MutexDirect(const MutexDirect ©) { - nassertv(false); -} - -/** - * Do not attempt to copy mutexes. + * Alias for acquire() to match C++11 semantics. + * @see acquire() */ INLINE void MutexDirect:: -operator = (const MutexDirect ©) { - nassertv(false); +lock() { + TAU_PROFILE("void MutexDirect::acquire()", " ", TAU_USER); + _impl.lock(); +} + +/** + * Alias for try_acquire() to match C++11 semantics. + * @see try_acquire() + */ +INLINE bool MutexDirect:: +try_lock() { + TAU_PROFILE("void MutexDirect::try_acquire()", " ", TAU_USER); + return _impl.try_lock(); +} + +/** + * Alias for release() to match C++11 semantics. + * @see release() + */ +INLINE void MutexDirect:: +unlock() { + TAU_PROFILE("void MutexDirect::unlock()", " ", TAU_USER); + _impl.unlock(); } /** @@ -54,7 +54,7 @@ operator = (const MutexDirect ©) { INLINE void MutexDirect:: acquire() const { TAU_PROFILE("void MutexDirect::acquire()", " ", TAU_USER); - ((MutexDirect *)this)->_impl.acquire(); + _impl.lock(); } /** @@ -64,7 +64,7 @@ acquire() const { INLINE bool MutexDirect:: try_acquire() const { TAU_PROFILE("void MutexDirect::acquire(bool)", " ", TAU_USER); - return ((MutexDirect *)this)->_impl.try_acquire(); + return _impl.try_lock(); } /** @@ -77,7 +77,7 @@ try_acquire() const { INLINE void MutexDirect:: release() const { TAU_PROFILE("void MutexDirect::release()", " ", TAU_USER); - ((MutexDirect *)this)->_impl.release(); + _impl.unlock(); } /** diff --git a/panda/src/pipeline/mutexDirect.h b/panda/src/pipeline/mutexDirect.h index 494c067a12..b288dc0648 100644 --- a/panda/src/pipeline/mutexDirect.h +++ b/panda/src/pipeline/mutexDirect.h @@ -29,11 +29,16 @@ class Thread; */ class EXPCL_PANDA_PIPELINE MutexDirect { protected: - INLINE MutexDirect(); - INLINE ~MutexDirect(); -private: - INLINE MutexDirect(const MutexDirect ©); - INLINE void operator = (const MutexDirect ©); + MutexDirect() = default; + MutexDirect(const MutexDirect ©) = delete; + ~MutexDirect() = default; + + void operator = (const MutexDirect ©) = delete; + +public: + INLINE void lock(); + INLINE bool try_lock(); + INLINE void unlock(); PUBLISHED: BLOCKING INLINE void acquire() const; @@ -49,7 +54,7 @@ PUBLISHED: void output(ostream &out) const; private: - MutexTrueImpl _impl; + mutable MutexTrueImpl _impl; friend class ConditionVarDirect; friend class ConditionVarFullDirect; diff --git a/panda/src/pipeline/mutexHolder.I b/panda/src/pipeline/mutexHolder.I index 9b1b99d6b6..c2b6204e5a 100644 --- a/panda/src/pipeline/mutexHolder.I +++ b/panda/src/pipeline/mutexHolder.I @@ -64,19 +64,3 @@ INLINE MutexHolder:: _mutex->release(); #endif } - -/** - * Do not attempt to copy MutexHolders. - */ -INLINE MutexHolder:: -MutexHolder(const MutexHolder ©) { - nassertv(false); -} - -/** - * Do not attempt to copy MutexHolders. - */ -INLINE void MutexHolder:: -operator = (const MutexHolder ©) { - nassertv(false); -} diff --git a/panda/src/pipeline/mutexHolder.h b/panda/src/pipeline/mutexHolder.h index 26f1af5d9d..ccd7b321a8 100644 --- a/panda/src/pipeline/mutexHolder.h +++ b/panda/src/pipeline/mutexHolder.h @@ -27,10 +27,10 @@ public: INLINE MutexHolder(const Mutex &mutex); INLINE MutexHolder(const Mutex &mutex, Thread *current_thread); INLINE MutexHolder(Mutex *&mutex); + MutexHolder(const MutexHolder ©) = delete; INLINE ~MutexHolder(); -private: - INLINE MutexHolder(const MutexHolder ©); - INLINE void operator = (const MutexHolder ©); + + MutexHolder &operator = (const MutexHolder ©) = delete; private: // If HAVE_THREADS is defined, the Mutex class implements an actual mutex diff --git a/panda/src/pipeline/mutexSimpleImpl.I b/panda/src/pipeline/mutexSimpleImpl.I index 82b3f5fa51..61123f83f6 100644 --- a/panda/src/pipeline/mutexSimpleImpl.I +++ b/panda/src/pipeline/mutexSimpleImpl.I @@ -11,27 +11,13 @@ * @date 2007-06-19 */ -/** - * - */ -INLINE MutexSimpleImpl:: -MutexSimpleImpl() { -} - -/** - * - */ -INLINE MutexSimpleImpl:: -~MutexSimpleImpl() { -} - /** * */ INLINE void MutexSimpleImpl:: -acquire() { - if (!try_acquire()) { - do_acquire(); +lock() { + if (!try_lock()) { + do_lock(); } } @@ -39,7 +25,7 @@ acquire() { * */ INLINE bool MutexSimpleImpl:: -try_acquire() { +try_lock() { if ((_flags & F_lock_count) != 0) { return false; } @@ -52,12 +38,12 @@ try_acquire() { * waiters on the mutex. */ INLINE void MutexSimpleImpl:: -release() { +unlock() { nassertv((_flags & F_lock_count) != 0); _flags &= ~F_lock_count; if (_flags & F_has_waiters) { - do_release(); + do_unlock(); } } @@ -65,11 +51,11 @@ release() { * Releases the mutex, without allowing a context switch to occur. */ INLINE void MutexSimpleImpl:: -release_quietly() { +unlock_quietly() { nassertv((_flags & F_lock_count) != 0); _flags &= ~F_lock_count; if (_flags & F_has_waiters) { - do_release_quietly(); + do_unlock_quietly(); } } diff --git a/panda/src/pipeline/mutexSimpleImpl.cxx b/panda/src/pipeline/mutexSimpleImpl.cxx index 0908104ae7..624a1989eb 100644 --- a/panda/src/pipeline/mutexSimpleImpl.cxx +++ b/panda/src/pipeline/mutexSimpleImpl.cxx @@ -23,7 +23,7 @@ * */ void MutexSimpleImpl:: -do_acquire() { +do_lock() { // By the time we get here, we already know that someone else is holding the // lock: (_flags & F_lock_count) != 0. ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr(); @@ -41,7 +41,7 @@ do_acquire() { * */ void MutexSimpleImpl:: -do_release() { +do_unlock() { // By the time we get here, we already know that someone else is blocked on // this mutex: (_flags & F_waiters) != 0. ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr(); @@ -58,7 +58,7 @@ do_release() { * */ void MutexSimpleImpl:: -do_release_quietly() { +do_unlock_quietly() { ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr(); manager->unblock_one(this); } diff --git a/panda/src/pipeline/mutexSimpleImpl.h b/panda/src/pipeline/mutexSimpleImpl.h index 60b5bc56b1..3c194a08f1 100644 --- a/panda/src/pipeline/mutexSimpleImpl.h +++ b/panda/src/pipeline/mutexSimpleImpl.h @@ -36,18 +36,17 @@ */ class EXPCL_PANDA_PIPELINE MutexSimpleImpl : public BlockerSimple { public: - INLINE MutexSimpleImpl(); - INLINE ~MutexSimpleImpl(); + constexpr MutexSimpleImpl() = default; - INLINE void acquire(); - INLINE bool try_acquire(); - INLINE void release(); - INLINE void release_quietly(); + INLINE void lock(); + INLINE bool try_lock(); + INLINE void unlock(); + INLINE void unlock_quietly(); private: - void do_acquire(); - void do_release(); - void do_release_quietly(); + void do_lock(); + void do_unlock(); + void do_unlock_quietly(); friend class ThreadSimpleManager; }; diff --git a/panda/src/pipeline/pipeline.cxx b/panda/src/pipeline/pipeline.cxx index e6fd1b6cee..94e1ff3c2a 100644 --- a/panda/src/pipeline/pipeline.cxx +++ b/panda/src/pipeline/pipeline.cxx @@ -134,7 +134,7 @@ cycle() { while (link != &prev_dirty) { PipelineCyclerTrueImpl *cycler = (PipelineCyclerTrueImpl *)link; - if (!cycler->_lock.try_acquire()) { + if (!cycler->_lock.try_lock()) { // No big deal, just move on to the next one for now, and we'll // come back around to it. It's important not to block here in // order to prevent one cycler from deadlocking another. @@ -144,7 +144,7 @@ cycle() { } else { // Well, we are the last cycler left, so we might as well wait. // This is necessary to trigger the deadlock detection code. - cycler->_lock.acquire(); + cycler->_lock.lock(); } } @@ -162,7 +162,7 @@ cycle() { #ifdef DEBUG_THREADS inc_cycler_type(_dirty_cycler_types, cycler->get_parent_type(), -1); #endif - cycler->_lock.release(); + cycler->_lock.unlock(); break; } } @@ -174,7 +174,7 @@ cycle() { while (link != &prev_dirty) { PipelineCyclerTrueImpl *cycler = (PipelineCyclerTrueImpl *)link; - if (!cycler->_lock.try_acquire()) { + if (!cycler->_lock.try_lock()) { // No big deal, just move on to the next one for now, and we'll // come back around to it. It's important not to block here in // order to prevent one cycler from deadlocking another. @@ -184,7 +184,7 @@ cycle() { } else { // Well, we are the last cycler left, so we might as well wait. // This is necessary to trigger the deadlock detection code. - cycler->_lock.acquire(); + cycler->_lock.lock(); } } @@ -206,7 +206,7 @@ cycle() { inc_cycler_type(_dirty_cycler_types, cycler->get_parent_type(), -1); #endif } - cycler->_lock.release(); + cycler->_lock.unlock(); break; } } @@ -218,7 +218,7 @@ cycle() { while (link != &prev_dirty) { PipelineCyclerTrueImpl *cycler = (PipelineCyclerTrueImpl *)link; - if (!cycler->_lock.try_acquire()) { + if (!cycler->_lock.try_lock()) { // No big deal, just move on to the next one for now, and we'll // come back around to it. It's important not to block here in // order to prevent one cycler from deadlocking another. @@ -228,7 +228,7 @@ cycle() { } else { // Well, we are the last cycler left, so we might as well wait. // This is necessary to trigger the deadlock detection code. - cycler->_lock.acquire(); + cycler->_lock.lock(); } } @@ -250,7 +250,7 @@ cycle() { inc_cycler_type(_dirty_cycler_types, cycler->get_parent_type(), -1); #endif } - cycler->_lock.release(); + cycler->_lock.unlock(); break; } } @@ -293,11 +293,11 @@ set_num_stages(int num_stages) { PipelineCyclerLinks *links; for (links = _clean._next; links != &_clean; links = links->_next) { PipelineCyclerTrueImpl *cycler = (PipelineCyclerTrueImpl *)links; - cycler->_lock.acquire(); + cycler->_lock.lock(); } for (links = _dirty._next; links != &_dirty; links = links->_next) { PipelineCyclerTrueImpl *cycler = (PipelineCyclerTrueImpl *)links; - cycler->_lock.acquire(); + cycler->_lock.lock(); } _num_stages = num_stages; @@ -315,12 +315,12 @@ set_num_stages(int num_stages) { int count = 0; for (links = _clean._next; links != &_clean; links = links->_next) { PipelineCyclerTrueImpl *cycler = (PipelineCyclerTrueImpl *)links; - cycler->_lock.release(); + cycler->_lock.unlock(); ++count; } for (links = _dirty._next; links != &_dirty; links = links->_next) { PipelineCyclerTrueImpl *cycler = (PipelineCyclerTrueImpl *)links; - cycler->_lock.release(); + cycler->_lock.unlock(); ++count; } nassertv(count == _num_cyclers); @@ -402,7 +402,7 @@ remove_cycler(PipelineCyclerTrueImpl *cycler) { // during cycle only if it's 0 (clean) or _next_cycle_seq (scheduled for the // next cycle, so not owned by the current one). while (cycler->_dirty != 0 && cycler->_dirty != _next_cycle_seq) { - if (_cycle_lock.try_acquire()) { + if (_cycle_lock.try_lock()) { // OK, great, we got the lock, so it finished cycling already. nassertv(!_cycling); @@ -417,16 +417,16 @@ remove_cycler(PipelineCyclerTrueImpl *cycler) { inc_cycler_type(_dirty_cycler_types, cycler->get_parent_type(), -1); #endif - _cycle_lock.release(); + _cycle_lock.unlock(); return; } else { // It's possibly currently being cycled. We will wait for the cycler // to be done with it, so that we can safely remove it. - _lock.release(); - cycler->_lock.release(); + _lock.unlock(); + cycler->_lock.unlock(); Thread::force_yield(); - cycler->_lock.acquire(); - _lock.acquire(); + cycler->_lock.lock(); + _lock.lock(); } } diff --git a/panda/src/pipeline/pipelineCyclerTrivialImpl.I b/panda/src/pipeline/pipelineCyclerTrivialImpl.I index 5cc1eecf39..316cadae30 100644 --- a/panda/src/pipeline/pipelineCyclerTrivialImpl.I +++ b/panda/src/pipeline/pipelineCyclerTrivialImpl.I @@ -30,35 +30,6 @@ PipelineCyclerTrivialImpl(CycleData *initial_data, Pipeline *) { #endif // SIMPLE_STRUCT_POINTERS } -/** - * - */ -INLINE PipelineCyclerTrivialImpl:: -PipelineCyclerTrivialImpl(const PipelineCyclerTrivialImpl &) { - // The copy constructor for the PipelineCyclerTrivialImpl case doesn't work. - // Don't try to use it. The PipelineCycler template class is ifdeffed - // appropriately to call the normal constructor instead. - nassertv(false); -} - -/** - * - */ -INLINE void PipelineCyclerTrivialImpl:: -operator = (const PipelineCyclerTrivialImpl &) { - // The copy assignment operator for the PipelineCyclerTrivialImpl case - // doesn't work. Don't try to use it. The PipelineCycler template class is - // ifdeffed appropriately not to call this method. - nassertv(false); -} - -/** - * - */ -INLINE PipelineCyclerTrivialImpl:: -~PipelineCyclerTrivialImpl() { -} - /** * Grabs an overall lock on the cycler. Release it with a call to release(). * This lock should be held while walking the list of stages. diff --git a/panda/src/pipeline/pipelineCyclerTrivialImpl.h b/panda/src/pipeline/pipelineCyclerTrivialImpl.h index ea0593ba24..9bcc9f12c9 100644 --- a/panda/src/pipeline/pipelineCyclerTrivialImpl.h +++ b/panda/src/pipeline/pipelineCyclerTrivialImpl.h @@ -41,11 +41,10 @@ class Pipeline; struct EXPCL_PANDA_PIPELINE PipelineCyclerTrivialImpl { public: INLINE PipelineCyclerTrivialImpl(CycleData *initial_data, Pipeline *pipeline = NULL); -private: - INLINE PipelineCyclerTrivialImpl(const PipelineCyclerTrivialImpl ©); - INLINE void operator = (const PipelineCyclerTrivialImpl ©); -public: - INLINE ~PipelineCyclerTrivialImpl(); + PipelineCyclerTrivialImpl(const PipelineCyclerTrivialImpl ©) = delete; + ~PipelineCyclerTrivialImpl() = default; + + PipelineCyclerTrivialImpl &operator = (const PipelineCyclerTrivialImpl ©) = delete; INLINE void acquire(Thread *current_thread = NULL); INLINE void release(); diff --git a/panda/src/pipeline/pmutex.I b/panda/src/pipeline/pmutex.I index 1cdfd011d4..9a5ca4c926 100644 --- a/panda/src/pipeline/pmutex.I +++ b/panda/src/pipeline/pmutex.I @@ -46,31 +46,3 @@ Mutex(const string &) #endif // DEBUG_THREADS { } - -/** - * - */ -INLINE Mutex:: -~Mutex() { -} - -/** - * Do not attempt to copy mutexes. - */ -INLINE Mutex:: -#ifdef DEBUG_THREADS -Mutex(const Mutex ©) : MutexDebug(string(), false, false) -#else - Mutex(const Mutex ©) -#endif // DEBUG_THREADS -{ - nassertv(false); -} - -/** - * Do not attempt to copy mutexes. - */ -INLINE void Mutex:: -operator = (const Mutex ©) { - nassertv(false); -} diff --git a/panda/src/pipeline/pmutex.h b/panda/src/pipeline/pmutex.h index c5d471ae0c..bc547afab3 100644 --- a/panda/src/pipeline/pmutex.h +++ b/panda/src/pipeline/pmutex.h @@ -44,10 +44,10 @@ public: INLINE Mutex(const char *name); PUBLISHED: INLINE explicit Mutex(const string &name); - INLINE ~Mutex(); -private: - INLINE Mutex(const Mutex ©); - INLINE void operator = (const Mutex ©); + Mutex(const Mutex ©) = delete; + ~Mutex() = default; + + void operator = (const Mutex ©) = delete; public: // This is a global mutex set aside for the purpose of protecting Notify diff --git a/panda/src/pipeline/psemaphore.I b/panda/src/pipeline/psemaphore.I index 1111e01857..0d1fe57bdf 100644 --- a/panda/src/pipeline/psemaphore.I +++ b/panda/src/pipeline/psemaphore.I @@ -23,31 +23,6 @@ Semaphore(int initial_count) : nassertv(_count >= 0); } -/** - * - */ -INLINE Semaphore:: -~Semaphore() { -} - -/** - * Do not attempt to copy semaphores. - */ -INLINE Semaphore:: -Semaphore(const Semaphore ©) : - _cvar(_lock) -{ - nassertv(false); -} - -/** - * Do not attempt to copy semaphores. - */ -INLINE void Semaphore:: -operator = (const Semaphore ©) { - nassertv(false); -} - /** * Decrements the internal count. If the count was already at zero, blocks * until the count is nonzero, then decrements it. diff --git a/panda/src/pipeline/psemaphore.h b/panda/src/pipeline/psemaphore.h index 6fd9162cc2..9c724a94c1 100644 --- a/panda/src/pipeline/psemaphore.h +++ b/panda/src/pipeline/psemaphore.h @@ -30,10 +30,10 @@ class EXPCL_PANDA_PIPELINE Semaphore { PUBLISHED: INLINE explicit Semaphore(int initial_count = 1); - INLINE ~Semaphore(); -private: - INLINE Semaphore(const Semaphore ©); - INLINE void operator = (const Semaphore ©); + Semaphore(const Semaphore ©) = delete; + ~Semaphore() = default; + + Semaphore &operator = (const Semaphore ©) = delete; PUBLISHED: BLOCKING INLINE void acquire(); diff --git a/panda/src/pipeline/reMutex.I b/panda/src/pipeline/reMutex.I index e67f378c35..361d3a1c85 100644 --- a/panda/src/pipeline/reMutex.I +++ b/panda/src/pipeline/reMutex.I @@ -46,18 +46,3 @@ ReMutex(const string &) #endif // DEBUG_THREADS { } - -/** - * - */ -INLINE ReMutex:: -~ReMutex() { -} - -/** - * Do not attempt to copy mutexes. - */ -INLINE void ReMutex:: -operator = (const ReMutex ©) { - nassertv(false); -} diff --git a/panda/src/pipeline/reMutex.h b/panda/src/pipeline/reMutex.h index fd6a710b55..1597c2d7c4 100644 --- a/panda/src/pipeline/reMutex.h +++ b/panda/src/pipeline/reMutex.h @@ -38,10 +38,10 @@ public: INLINE explicit ReMutex(const char *name); PUBLISHED: INLINE explicit ReMutex(const string &name); - INLINE ~ReMutex(); -private: - INLINE ReMutex(const ReMutex ©); - INLINE void operator = (const ReMutex ©); + ReMutex(const ReMutex ©) = delete; + ~ReMutex() = default; + + void operator = (const ReMutex ©) = delete; }; #include "reMutex.I" diff --git a/panda/src/pipeline/reMutexDirect.I b/panda/src/pipeline/reMutexDirect.I index abdce3562f..cdcc7fd45e 100644 --- a/panda/src/pipeline/reMutexDirect.I +++ b/panda/src/pipeline/reMutexDirect.I @@ -27,30 +27,33 @@ ReMutexDirect() } /** - * - */ -INLINE ReMutexDirect:: -~ReMutexDirect() { -} - -/** - * Do not attempt to copy reMutexes. - */ -INLINE ReMutexDirect:: -ReMutexDirect(const ReMutexDirect ©) -#ifndef HAVE_REMUTEXTRUEIMPL - : _cvar_impl(_lock_impl) -#endif -{ - nassertv(false); -} - -/** - * Do not attempt to copy reMutexes. + * Alias for acquire() to match C++11 semantics. + * @see acquire() */ INLINE void ReMutexDirect:: -operator = (const ReMutexDirect ©) { - nassertv(false); +lock() { + TAU_PROFILE("void ReMutexDirect::acquire()", " ", TAU_USER); + _impl.lock(); +} + +/** + * Alias for try_acquire() to match C++11 semantics. + * @see try_acquire() + */ +INLINE bool ReMutexDirect:: +try_lock() { + TAU_PROFILE("void ReMutexDirect::try_acquire()", " ", TAU_USER); + return _impl.try_lock(); +} + +/** + * Alias for release() to match C++11 semantics. + * @see release() + */ +INLINE void ReMutexDirect:: +unlock() { + TAU_PROFILE("void ReMutexDirect::unlock()", " ", TAU_USER); + _impl.unlock(); } /** @@ -67,9 +70,9 @@ INLINE void ReMutexDirect:: acquire() const { TAU_PROFILE("void ReMutexDirect::acquire()", " ", TAU_USER); #ifdef HAVE_REMUTEXTRUEIMPL - ((ReMutexDirect *)this)->_impl.acquire(); + _impl.lock(); #else - ((ReMutexDirect *)this)->do_acquire(); + ((ReMutexDirect *)this)->do_lock(); #endif // HAVE_REMUTEXTRUEIMPL } @@ -81,9 +84,9 @@ INLINE void ReMutexDirect:: acquire(Thread *current_thread) const { TAU_PROFILE("void ReMutexDirect::acquire(Thread *)", " ", TAU_USER); #ifdef HAVE_REMUTEXTRUEIMPL - ((ReMutexDirect *)this)->_impl.acquire(); + _impl.lock(); #else - ((ReMutexDirect *)this)->do_acquire(current_thread); + ((ReMutexDirect *)this)->do_lock(current_thread); #endif // HAVE_REMUTEXTRUEIMPL } @@ -95,9 +98,9 @@ INLINE bool ReMutexDirect:: try_acquire() const { TAU_PROFILE("void ReMutexDirect::acquire(bool)", " ", TAU_USER); #ifdef HAVE_REMUTEXTRUEIMPL - return ((ReMutexDirect *)this)->_impl.try_acquire(); + return _impl.try_lock(); #else - return ((ReMutexDirect *)this)->do_try_acquire(); + return ((ReMutexDirect *)this)->do_try_lock(); #endif // HAVE_REMUTEXTRUEIMPL } @@ -109,9 +112,9 @@ INLINE bool ReMutexDirect:: try_acquire(Thread *current_thread) const { TAU_PROFILE("void ReMutexDirect::acquire(bool)", " ", TAU_USER); #ifdef HAVE_REMUTEXTRUEIMPL - return ((ReMutexDirect *)this)->_impl.try_acquire(); + return _impl.try_lock(); #else - return ((ReMutexDirect *)this)->do_try_acquire(current_thread); + return ((ReMutexDirect *)this)->do_try_lock(current_thread); #endif // HAVE_REMUTEXTRUEIMPL } @@ -129,7 +132,7 @@ INLINE void ReMutexDirect:: elevate_lock() const { TAU_PROFILE("void ReMutexDirect::elevate_lock()", " ", TAU_USER); #ifdef HAVE_REMUTEXTRUEIMPL - ((ReMutexDirect *)this)->_impl.acquire(); + _impl.lock(); #else ((ReMutexDirect *)this)->do_elevate_lock(); #endif // HAVE_REMUTEXTRUEIMPL @@ -146,9 +149,9 @@ INLINE void ReMutexDirect:: release() const { TAU_PROFILE("void ReMutexDirect::release()", " ", TAU_USER); #ifdef HAVE_REMUTEXTRUEIMPL - ((ReMutexDirect *)this)->_impl.release(); + _impl.unlock(); #else - ((ReMutexDirect *)this)->do_release(); + ((ReMutexDirect *)this)->do_unlock(); #endif // HAVE_REMUTEXTRUEIMPL } @@ -201,8 +204,8 @@ get_name() const { * mutex). */ INLINE void ReMutexDirect:: -do_acquire() { - do_acquire(Thread::get_current_thread()); +do_lock() { + do_lock(Thread::get_current_thread()); } #endif @@ -214,7 +217,7 @@ do_acquire() { * mutex). */ INLINE bool ReMutexDirect:: -do_try_acquire() { - return do_try_acquire(Thread::get_current_thread()); +do_try_lock() { + return do_try_lock(Thread::get_current_thread()); } #endif diff --git a/panda/src/pipeline/reMutexDirect.cxx b/panda/src/pipeline/reMutexDirect.cxx index 33ff64c4cc..b82ed0f364 100644 --- a/panda/src/pipeline/reMutexDirect.cxx +++ b/panda/src/pipeline/reMutexDirect.cxx @@ -33,8 +33,8 @@ output(ostream &out) const { * mutex). */ void ReMutexDirect:: -do_acquire(Thread *current_thread) { - _lock_impl.acquire(); +do_lock(Thread *current_thread) { + _lock_impl.lock(); if (_locking_thread == (Thread *)NULL) { // The mutex is not already locked by anyone. Lock it. @@ -61,7 +61,7 @@ do_acquire(Thread *current_thread) { nassertd(_lock_count == 1) { } } - _lock_impl.release(); + _lock_impl.unlock(); } #endif // !HAVE_REMUTEXTRUEIMPL @@ -73,9 +73,9 @@ do_acquire(Thread *current_thread) { * mutex). */ bool ReMutexDirect:: -do_try_acquire(Thread *current_thread) { +do_try_lock(Thread *current_thread) { bool acquired = true; - _lock_impl.acquire(); + _lock_impl.lock(); if (_locking_thread == (Thread *)NULL) { // The mutex is not already locked by anyone. Lock it. @@ -94,7 +94,7 @@ do_try_acquire(Thread *current_thread) { // The mutex is locked by some other thread. Return false. acquired = false; } - _lock_impl.release(); + _lock_impl.unlock(); return acquired; } @@ -109,16 +109,16 @@ do_try_acquire(Thread *current_thread) { */ void ReMutexDirect:: do_elevate_lock() { - _lock_impl.acquire(); + _lock_impl.lock(); #ifdef _DEBUG nassertd(_locking_thread == Thread::get_current_thread()) { - _lock_impl.release(); + _lock_impl.unlock(); return; } #elif !defined(NDEBUG) nassertd(_locking_thread != (Thread *)NULL) { - _lock_impl.release(); + _lock_impl.unlock(); return; } #endif // NDEBUG @@ -129,7 +129,7 @@ do_elevate_lock() { nassertd(_lock_count > 0) { } - _lock_impl.release(); + _lock_impl.unlock(); } #endif // !HAVE_REMUTEXTRUEIMPL @@ -141,8 +141,8 @@ do_elevate_lock() { * mutex). */ void ReMutexDirect:: -do_release() { - _lock_impl.acquire(); +do_unlock() { + _lock_impl.lock(); #ifdef _DEBUG if (_locking_thread != Thread::get_current_thread()) { @@ -150,7 +150,7 @@ do_release() { ostr << *_locking_thread << " attempted to release " << *this << " which it does not own"; nassert_raise(ostr.str()); - _lock_impl.release(); + _lock_impl.unlock(); return; } #endif // _DEBUG @@ -164,7 +164,7 @@ do_release() { _locking_thread = (Thread *)NULL; _cvar_impl.notify(); } - _lock_impl.release(); + _lock_impl.unlock(); } #endif // !HAVE_REMUTEXTRUEIMPL diff --git a/panda/src/pipeline/reMutexDirect.h b/panda/src/pipeline/reMutexDirect.h index ce86e774f0..c47c4b02bd 100644 --- a/panda/src/pipeline/reMutexDirect.h +++ b/panda/src/pipeline/reMutexDirect.h @@ -30,10 +30,15 @@ class Thread; class EXPCL_PANDA_PIPELINE ReMutexDirect { protected: INLINE ReMutexDirect(); - INLINE ~ReMutexDirect(); -private: - INLINE ReMutexDirect(const ReMutexDirect ©); - INLINE void operator = (const ReMutexDirect ©); + ReMutexDirect(const ReMutexDirect ©) = delete; + ~ReMutexDirect() = default; + + void operator = (const ReMutexDirect ©) = delete; + +public: + INLINE void lock(); + INLINE bool try_lock(); + INLINE void unlock(); PUBLISHED: BLOCKING INLINE void acquire() const; @@ -54,16 +59,16 @@ PUBLISHED: private: #ifdef HAVE_REMUTEXTRUEIMPL - ReMutexImpl _impl; + mutable ReMutexImpl _impl; #else // If we don't have a reentrant mutex, we have to hand-roll one. - INLINE void do_acquire(); - void do_acquire(Thread *current_thread); - INLINE bool do_try_acquire(); - bool do_try_acquire(Thread *current_thread); + INLINE void do_lock(); + void do_lock(Thread *current_thread); + INLINE bool do_try_lock(); + bool do_try_lock(Thread *current_thread); void do_elevate_lock(); - void do_release(); + void do_unlock(); Thread *_locking_thread; int _lock_count; diff --git a/panda/src/pipeline/reMutexHolder.I b/panda/src/pipeline/reMutexHolder.I index 25a0032b4e..00cd980e01 100644 --- a/panda/src/pipeline/reMutexHolder.I +++ b/panda/src/pipeline/reMutexHolder.I @@ -61,19 +61,3 @@ INLINE ReMutexHolder:: _mutex->release(); #endif } - -/** - * Do not attempt to copy ReMutexHolders. - */ -INLINE ReMutexHolder:: -ReMutexHolder(const ReMutexHolder ©) { - nassertv(false); -} - -/** - * Do not attempt to copy ReMutexHolders. - */ -INLINE void ReMutexHolder:: -operator = (const ReMutexHolder ©) { - nassertv(false); -} diff --git a/panda/src/pipeline/reMutexHolder.h b/panda/src/pipeline/reMutexHolder.h index f0830803fb..3411f7e3f8 100644 --- a/panda/src/pipeline/reMutexHolder.h +++ b/panda/src/pipeline/reMutexHolder.h @@ -27,10 +27,10 @@ public: INLINE ReMutexHolder(const ReMutex &mutex); INLINE ReMutexHolder(const ReMutex &mutex, Thread *current_thread); INLINE ReMutexHolder(ReMutex *&mutex); + ReMutexHolder(const ReMutexHolder ©) = delete; INLINE ~ReMutexHolder(); -private: - INLINE ReMutexHolder(const ReMutexHolder ©); - INLINE void operator = (const ReMutexHolder ©); + + ReMutexHolder &operator = (const ReMutexHolder ©) = delete; private: #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) diff --git a/panda/src/pipeline/test_mutex.cxx b/panda/src/pipeline/test_mutex.cxx index 39f5e8a24c..f02ccd1434 100644 --- a/panda/src/pipeline/test_mutex.cxx +++ b/panda/src/pipeline/test_mutex.cxx @@ -33,9 +33,9 @@ public: double start = clock->get_short_time(); double end = start + thread_duration; while (clock->get_short_time() < end) { - _m1.acquire(); + _m1.lock(); Thread::sleep(_period); - _m1.release(); + _m1.unlock(); } } @@ -47,8 +47,8 @@ int main(int argc, char *argv[]) { MutexImpl _m1; - _m1.acquire(); - _m1.release(); + _m1.lock(); + _m1.unlock(); cerr << "Making threads.\n"; MyThread *a = new MyThread("a", _m1, 1.0); diff --git a/panda/src/pipeline/thread.I b/panda/src/pipeline/thread.I index 10d7b6e44f..d108f025dd 100644 --- a/panda/src/pipeline/thread.I +++ b/panda/src/pipeline/thread.I @@ -11,22 +11,6 @@ * @date 2002-08-08 */ -/** - * Do not attempt to copy threads. - */ -INLINE Thread:: -Thread(const Thread ©) : _impl(this) { - nassertv(false); -} - -/** - * Do not attempt to copy threads. - */ -INLINE void Thread:: -operator = (const Thread ©) { - nassertv(false); -} - /** * Returns the sync name of the thread. This name collects threads into "sync * groups", which are expected to run synchronously. This is mainly used for diff --git a/panda/src/pipeline/thread.h b/panda/src/pipeline/thread.h index 730deb5872..6749883fb6 100644 --- a/panda/src/pipeline/thread.h +++ b/panda/src/pipeline/thread.h @@ -46,15 +46,14 @@ class AsyncTask; class EXPCL_PANDA_PIPELINE Thread : public TypedReferenceCount, public Namable { protected: Thread(const string &name, const string &sync_name); + Thread(const Thread ©) = delete; PUBLISHED: virtual ~Thread(); -private: - INLINE Thread(const Thread ©); - INLINE void operator = (const Thread ©); - protected: + Thread &operator = (const Thread ©) = delete; + virtual void thread_main()=0; PUBLISHED: diff --git a/panda/src/pipeline/threadPosixImpl.cxx b/panda/src/pipeline/threadPosixImpl.cxx index 5104c67926..9983ad24ea 100644 --- a/panda/src/pipeline/threadPosixImpl.cxx +++ b/panda/src/pipeline/threadPosixImpl.cxx @@ -41,14 +41,14 @@ ThreadPosixImpl:: << "Deleting thread " << _parent_obj->get_name() << "\n"; } - _mutex.acquire(); + _mutex.lock(); if (!_detached) { pthread_detach(_thread); _detached = true; } - _mutex.release(); + _mutex.unlock(); } /** @@ -65,13 +65,13 @@ setup_main_thread() { */ bool ThreadPosixImpl:: start(ThreadPriority priority, bool joinable) { - _mutex.acquire(); + _mutex.lock(); if (thread_cat->is_debug()) { thread_cat.debug() << "Starting " << *_parent_obj << "\n"; } nassertd(_status == S_new) { - _mutex.release(); + _mutex.unlock(); return false; } @@ -148,12 +148,12 @@ start(ThreadPriority priority, bool joinable) { // Oops, we couldn't start the thread. Be sure to decrement the reference // count we incremented above, and return false to indicate failure. unref_delete(_parent_obj); - _mutex.release(); + _mutex.unlock(); return false; } // Thread was successfully started. - _mutex.release(); + _mutex.unlock(); return true; } @@ -163,15 +163,15 @@ start(ThreadPriority priority, bool joinable) { */ void ThreadPosixImpl:: join() { - _mutex.acquire(); + _mutex.lock(); if (!_detached) { - _mutex.release(); + _mutex.unlock(); void *return_val; pthread_join(_thread, &return_val); _detached = true; return; } - _mutex.release(); + _mutex.unlock(); } /** @@ -246,14 +246,14 @@ root_func(void *data) { nassertr(result == 0, NULL); { - self->_mutex.acquire(); + self->_mutex.lock(); nassertd(self->_status == S_start_called) { - self->_mutex.release(); + self->_mutex.unlock(); return NULL; } self->_status = S_running; - self->_mutex.release(); + self->_mutex.unlock(); } #ifdef ANDROID @@ -270,13 +270,13 @@ root_func(void *data) { } { - self->_mutex.acquire(); + self->_mutex.lock(); nassertd(self->_status == S_running) { - self->_mutex.release(); + self->_mutex.unlock(); return NULL; } self->_status = S_finished; - self->_mutex.release(); + self->_mutex.unlock(); } #ifdef ANDROID diff --git a/panda/src/pipeline/threadWin32Impl.cxx b/panda/src/pipeline/threadWin32Impl.cxx index 006a98441e..8508f23ac6 100644 --- a/panda/src/pipeline/threadWin32Impl.cxx +++ b/panda/src/pipeline/threadWin32Impl.cxx @@ -49,13 +49,13 @@ setup_main_thread() { */ bool ThreadWin32Impl:: start(ThreadPriority priority, bool joinable) { - _mutex.acquire(); + _mutex.lock(); if (thread_cat->is_debug()) { thread_cat.debug() << "Starting " << *_parent_obj << "\n"; } nassertd(_status == S_new && _thread == 0) { - _mutex.release(); + _mutex.unlock(); return false; } @@ -76,7 +76,7 @@ start(ThreadPriority priority, bool joinable) { // Oops, we couldn't start the thread. Be sure to decrement the reference // count we incremented above, and return false to indicate failure. unref_delete(_parent_obj); - _mutex.release(); + _mutex.unlock(); return false; } @@ -100,7 +100,7 @@ start(ThreadPriority priority, bool joinable) { break; } - _mutex.release(); + _mutex.unlock(); return true; } @@ -110,16 +110,16 @@ start(ThreadPriority priority, bool joinable) { */ void ThreadWin32Impl:: join() { - _mutex.acquire(); + _mutex.lock(); nassertd(_joinable && _status != S_new) { - _mutex.release(); + _mutex.unlock(); return; } while (_status != S_finished) { _cv.wait(); } - _mutex.release(); + _mutex.unlock(); } /** @@ -147,14 +147,14 @@ root_func(LPVOID data) { nassertr(result, 1); { - self->_mutex.acquire(); + self->_mutex.lock(); nassertd(self->_status == S_start_called) { - self->_mutex.release(); + self->_mutex.unlock(); return 1; } self->_status = S_running; self->_cv.notify(); - self->_mutex.release(); + self->_mutex.unlock(); } self->_parent_obj->thread_main(); @@ -166,14 +166,14 @@ root_func(LPVOID data) { } { - self->_mutex.acquire(); + self->_mutex.lock(); nassertd(self->_status == S_running) { - self->_mutex.release(); + self->_mutex.unlock(); return 1; } self->_status = S_finished; self->_cv.notify(); - self->_mutex.release(); + self->_mutex.unlock(); } // Now drop the parent object reference that we grabbed in start(). This diff --git a/panda/src/pstatclient/pStatClient.I b/panda/src/pstatclient/pStatClient.I index 8ce9381978..2338eaa0ad 100644 --- a/panda/src/pstatclient/pStatClient.I +++ b/panda/src/pstatclient/pStatClient.I @@ -60,14 +60,11 @@ get_thread_sync_name(int index) const { /** * Returns the Panda Thread object associated with the indicated PStatThread. */ -INLINE Thread *PStatClient:: +INLINE PT(Thread) PStatClient:: get_thread_object(int index) const { nassertr(index >= 0 && index < AtomicAdjust::get(_num_threads), NULL); InternalThread *thread = get_thread_ptr(index); - if (thread->_thread.was_deleted()) { - return NULL; - } - return thread->_thread; + return thread->_thread.lock(); } /** diff --git a/panda/src/pstatclient/pStatClient.h b/panda/src/pstatclient/pStatClient.h index 2d285c6f8a..6fb41c4c3c 100644 --- a/panda/src/pstatclient/pStatClient.h +++ b/panda/src/pstatclient/pStatClient.h @@ -73,7 +73,7 @@ PUBLISHED: MAKE_SEQ(get_threads, get_num_threads, get_thread); INLINE string get_thread_name(int index) const; INLINE string get_thread_sync_name(int index) const; - INLINE Thread *get_thread_object(int index) const; + INLINE PT(Thread) get_thread_object(int index) const; PStatThread get_main_thread() const; PStatThread get_current_thread() const; diff --git a/panda/src/putil/bamCache.cxx b/panda/src/putil/bamCache.cxx index 94c31665c6..cd3fab2113 100644 --- a/panda/src/putil/bamCache.cxx +++ b/panda/src/putil/bamCache.cxx @@ -311,7 +311,7 @@ emergency_read_only() { void BamCache:: consider_flush_index() { #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) - if (!_lock.try_acquire()) { + if (!_lock.try_lock()) { // If we can't grab the lock, no big deal. We don't want to hold up // the frame waiting for a cache operation. We can try again later. return; @@ -326,7 +326,7 @@ consider_flush_index() { } #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) - _lock.release(); + _lock.unlock(); #endif } diff --git a/panda/src/putil/bitArray.I b/panda/src/putil/bitArray.I index f746a9ba77..605cf40a57 100644 --- a/panda/src/putil/bitArray.I +++ b/panda/src/putil/bitArray.I @@ -78,44 +78,6 @@ range(int low_bit, int size) { return result; } -/** - * Returns true if there is a maximum number of bits that may be stored in - * this structure, false otherwise. If this returns true, the number may be - * queried in get_max_num_bits(). - * - * This method always returns false. The BitArray has no maximum number of - * bits. This method is defined so generic programming algorithms can use - * BitMask or BitArray interchangeably. - */ -CONSTEXPR bool BitArray:: -has_max_num_bits() { - return false; -} - -/** - * If get_max_num_bits() returned true, this method may be called to return - * the maximum number of bits that may be stored in this structure. It is an - * error to call this if get_max_num_bits() return false. - * - * It is always an error to call this method. The BitArray has no maximum - * number of bits. This method is defined so generic programming algorithms - * can use BitMask or BitArray interchangeably. - */ -CONSTEXPR int BitArray:: -get_max_num_bits() { - return INT_MAX; -} - -/** - * Returns the number of bits stored per word internally. This is of interest - * only in that it limits the maximum number of bits that may be queried or - * set at once by extract() and store(). - */ -CONSTEXPR int BitArray:: -get_num_bits_per_word() { - return num_bits_per_word; -} - /** * Returns the current number of possibly different bits in this array. There * are actually an infinite number of bits, but every bit higher than this bit diff --git a/panda/src/putil/bitArray.h b/panda/src/putil/bitArray.h index 72ef1f656d..bb00dea0d7 100644 --- a/panda/src/putil/bitArray.h +++ b/panda/src/putil/bitArray.h @@ -54,10 +54,10 @@ PUBLISHED: INLINE static BitArray bit(int index); INLINE static BitArray range(int low_bit, int size); - CONSTEXPR static bool has_max_num_bits(); - CONSTEXPR static int get_max_num_bits(); + constexpr static bool has_max_num_bits() { return false; } + constexpr static int get_max_num_bits() { return INT_MAX; } - CONSTEXPR static int get_num_bits_per_word(); + constexpr static int get_num_bits_per_word() { return num_bits_per_word; } INLINE size_t get_num_bits() const; INLINE bool get_bit(int index) const; INLINE void set_bit(int index); diff --git a/panda/src/putil/bitMask.I b/panda/src/putil/bitMask.I index 0411d06042..fa1073ad4b 100644 --- a/panda/src/putil/bitMask.I +++ b/panda/src/putil/bitMask.I @@ -101,41 +101,12 @@ range(int low_bit, int size) { return result; } -/** - * Returns true if there is a maximum number of bits that may be stored in - * this structure, false otherwise. If this returns true, the number may be - * queried in get_max_num_bits(). - * - * This method always returns true. This method is defined so generic - * programming algorithms can use BitMask or BitArray interchangeably. - */ -template -CONSTEXPR bool BitMask:: -has_max_num_bits() { - return true; -} - -/** - * If get_max_num_bits() returned true, this method may be called to return - * the maximum number of bits that may be stored in this structure. It is an - * error to call this if get_max_num_bits() return false. - * - * It is never an error to call this method. This returns the same thing as - * get_num_bits(). This method is defined so generic programming algorithms - * can use BitMask or BitArray interchangeably. - */ -template -CONSTEXPR int BitMask:: -get_max_num_bits() { - return num_bits; -} - /** * Returns the number of bits available to set in the bitmask. */ template -CONSTEXPR int BitMask:: -get_num_bits() { +constexpr int BitMask:: +get_num_bits() const { return num_bits; } diff --git a/panda/src/putil/bitMask.h b/panda/src/putil/bitMask.h index 5333562025..3d73089b50 100644 --- a/panda/src/putil/bitMask.h +++ b/panda/src/putil/bitMask.h @@ -45,10 +45,10 @@ PUBLISHED: INLINE static BitMask bit(int index); INLINE static BitMask range(int low_bit, int size); - CONSTEXPR static bool has_max_num_bits(); - CONSTEXPR static int get_max_num_bits(); + constexpr static bool has_max_num_bits() { return true; } + constexpr static int get_max_num_bits() { return num_bits; } - CONSTEXPR static int get_num_bits(); + constexpr int get_num_bits() const; INLINE bool get_bit(int index) const; INLINE void set_bit(int index); INLINE void clear_bit(int index); diff --git a/panda/src/putil/buttonHandle.I b/panda/src/putil/buttonHandle.I index 2353b01689..2df12e8cd0 100644 --- a/panda/src/putil/buttonHandle.I +++ b/panda/src/putil/buttonHandle.I @@ -15,7 +15,7 @@ * Constructs a ButtonHandle with the corresponding index number, which may * have been returned by an earlier call to ButtonHandle::get_index(). */ -CONSTEXPR ButtonHandle:: +constexpr ButtonHandle:: ButtonHandle(int index) : _index(index) { } @@ -124,7 +124,7 @@ matches(const ButtonHandle &other) const { * opaque classes. This is provided for the convenience of non-C++ scripting * languages to build a hashtable of ButtonHandles. */ -CONSTEXPR int ButtonHandle:: +constexpr int ButtonHandle:: get_index() const { return _index; } diff --git a/panda/src/putil/buttonHandle.h b/panda/src/putil/buttonHandle.h index 429108249f..4ee27b01ae 100644 --- a/panda/src/putil/buttonHandle.h +++ b/panda/src/putil/buttonHandle.h @@ -23,14 +23,14 @@ * keyboard buttons and mouse buttons (but see KeyboardButton and * MouseButton). */ -class EXPCL_PANDA_PUTIL ButtonHandle FINAL { +class EXPCL_PANDA_PUTIL ButtonHandle final { PUBLISHED: // The default constructor must do nothing, because we can't guarantee // ordering of static initializers. If the constructor tried to initialize // its value, it might happen after the value had already been set // previously by another static initializer! - INLINE ButtonHandle() DEFAULT_CTOR; - CONSTEXPR ButtonHandle(int index); + INLINE ButtonHandle() = default; + constexpr ButtonHandle(int index); ButtonHandle(const string &name); PUBLISHED: @@ -51,7 +51,7 @@ PUBLISHED: INLINE bool matches(const ButtonHandle &other) const; - CONSTEXPR int get_index() const; + constexpr int get_index() const; INLINE void output(ostream &out) const; INLINE static ButtonHandle none(); diff --git a/panda/src/putil/copyOnWritePointer.I b/panda/src/putil/copyOnWritePointer.I index 9e996355fa..9354fe350a 100644 --- a/panda/src/putil/copyOnWritePointer.I +++ b/panda/src/putil/copyOnWritePointer.I @@ -69,12 +69,11 @@ INLINE CopyOnWritePointer:: } } -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE CopyOnWritePointer:: -CopyOnWritePointer(CopyOnWritePointer &&from) NOEXCEPT : +CopyOnWritePointer(CopyOnWritePointer &&from) noexcept : _cow_object(from._cow_object) { // Steal the other's reference count. @@ -85,7 +84,7 @@ CopyOnWritePointer(CopyOnWritePointer &&from) NOEXCEPT : * */ INLINE CopyOnWritePointer:: -CopyOnWritePointer(PointerTo &&from) NOEXCEPT : +CopyOnWritePointer(PointerTo &&from) noexcept : _cow_object(from.p()) { // Steal the other's reference count, but because it is a regular pointer, @@ -100,7 +99,7 @@ CopyOnWritePointer(PointerTo &&from) NOEXCEPT : * */ INLINE void CopyOnWritePointer:: -operator = (CopyOnWritePointer &&from) NOEXCEPT { +operator = (CopyOnWritePointer &&from) noexcept { // Protect against self-move-assignment. if (from._cow_object != _cow_object) { CopyOnWriteObject *old_object = _cow_object; @@ -117,7 +116,7 @@ operator = (CopyOnWritePointer &&from) NOEXCEPT { * */ INLINE void CopyOnWritePointer:: -operator = (PointerTo &&from) NOEXCEPT { +operator = (PointerTo &&from) noexcept { if (from.p() != _cow_object) { CopyOnWriteObject *old_object = _cow_object; @@ -132,7 +131,6 @@ operator = (PointerTo &&from) NOEXCEPT { } } } -#endif // USE_MOVE_SEMANTICS /** * @@ -290,14 +288,13 @@ operator = (To *object) { } #endif // CPPPARSER -#ifdef USE_MOVE_SEMANTICS #ifndef CPPPARSER /** * */ template INLINE CopyOnWritePointerTo:: -CopyOnWritePointerTo(CopyOnWritePointerTo &&from) NOEXCEPT : +CopyOnWritePointerTo(CopyOnWritePointerTo &&from) noexcept : CopyOnWritePointer((CopyOnWritePointer &&)from) { } @@ -309,7 +306,7 @@ CopyOnWritePointerTo(CopyOnWritePointerTo &&from) NOEXCEPT : */ template INLINE CopyOnWritePointerTo:: -CopyOnWritePointerTo(PointerTo &&from) NOEXCEPT { +CopyOnWritePointerTo(PointerTo &&from) noexcept { // Steal the other's reference count, but because it is a regular pointer, // we do need to include the cache reference count. _cow_object = from.p(); @@ -326,7 +323,7 @@ CopyOnWritePointerTo(PointerTo &&from) NOEXCEPT { */ template INLINE void CopyOnWritePointerTo:: -operator = (CopyOnWritePointerTo &&from) NOEXCEPT { +operator = (CopyOnWritePointerTo &&from) noexcept { CopyOnWritePointer::operator = ((CopyOnWritePointer &&)from); } #endif // CPPPARSER @@ -337,7 +334,7 @@ operator = (CopyOnWritePointerTo &&from) NOEXCEPT { */ template INLINE void CopyOnWritePointerTo:: -operator = (PointerTo &&from) NOEXCEPT { +operator = (PointerTo &&from) noexcept { if (from.p() != _cow_object) { CopyOnWriteObject *old_object = _cow_object; @@ -353,7 +350,6 @@ operator = (PointerTo &&from) NOEXCEPT { } } #endif // CPPPARSER -#endif // USE_MOVE_SEMANTICS #ifndef CPPPARSER #ifdef COW_THREADED diff --git a/panda/src/putil/copyOnWritePointer.cxx b/panda/src/putil/copyOnWritePointer.cxx index 4beb105ada..5a8f1700b6 100644 --- a/panda/src/putil/copyOnWritePointer.cxx +++ b/panda/src/putil/copyOnWritePointer.cxx @@ -66,7 +66,7 @@ get_write_pointer() { Thread *current_thread = Thread::get_current_thread(); - _cow_object->_lock_mutex.acquire(); + _cow_object->_lock_mutex.lock(); while (_cow_object->_lock_status == CopyOnWriteObject::LS_locked_write && _cow_object->_locking_thread != current_thread) { if (util_cat.is_debug()) { @@ -89,7 +89,7 @@ get_write_pointer() { PT(CopyOnWriteObject) new_object = _cow_object->make_cow_copy(); _cow_object->CachedTypedWritableReferenceCount::cache_unref(); - _cow_object->_lock_mutex.release(); + _cow_object->_lock_mutex.unlock(); MutexHolder holder(new_object->_lock_mutex); _cow_object = new_object; @@ -112,7 +112,7 @@ get_write_pointer() { PT(CopyOnWriteObject) new_object = _cow_object->make_cow_copy(); _cow_object->CachedTypedWritableReferenceCount::cache_unref(); - _cow_object->_lock_mutex.release(); + _cow_object->_lock_mutex.unlock(); MutexHolder holder(new_object->_lock_mutex); _cow_object = new_object; @@ -132,7 +132,7 @@ get_write_pointer() { // reference. _cow_object->_lock_status = CopyOnWriteObject::LS_locked_write; _cow_object->_locking_thread = current_thread; - _cow_object->_lock_mutex.release(); + _cow_object->_lock_mutex.unlock(); } return _cow_object; diff --git a/panda/src/putil/copyOnWritePointer.h b/panda/src/putil/copyOnWritePointer.h index 2178b6b433..a98599361a 100644 --- a/panda/src/putil/copyOnWritePointer.h +++ b/panda/src/putil/copyOnWritePointer.h @@ -32,16 +32,14 @@ class EXPCL_PANDA_PUTIL CopyOnWritePointer { public: INLINE CopyOnWritePointer(CopyOnWriteObject *object = NULL); INLINE CopyOnWritePointer(const CopyOnWritePointer ©); - INLINE void operator = (const CopyOnWritePointer ©); - INLINE void operator = (CopyOnWriteObject *object); + INLINE CopyOnWritePointer(CopyOnWritePointer &&from) noexcept; + INLINE CopyOnWritePointer(PointerTo &&from) noexcept; INLINE ~CopyOnWritePointer(); -#ifdef USE_MOVE_SEMANTICS - INLINE CopyOnWritePointer(CopyOnWritePointer &&from) NOEXCEPT; - INLINE CopyOnWritePointer(PointerTo &&from) NOEXCEPT; - INLINE void operator = (CopyOnWritePointer &&from) NOEXCEPT; - INLINE void operator = (PointerTo &&from) NOEXCEPT; -#endif + INLINE void operator = (const CopyOnWritePointer ©); + INLINE void operator = (CopyOnWritePointer &&from) noexcept; + INLINE void operator = (PointerTo &&from) noexcept; + INLINE void operator = (CopyOnWriteObject *object); INLINE bool operator == (const CopyOnWritePointer &other) const; INLINE bool operator != (const CopyOnWritePointer &other) const; @@ -82,15 +80,13 @@ public: INLINE CopyOnWritePointerTo(To *object = NULL); INLINE CopyOnWritePointerTo(const CopyOnWritePointerTo ©); + INLINE CopyOnWritePointerTo(CopyOnWritePointerTo &&from) noexcept; + INLINE CopyOnWritePointerTo(PointerTo &&from) noexcept; + INLINE void operator = (const CopyOnWritePointerTo ©); INLINE void operator = (To *object); - -#ifdef USE_MOVE_SEMANTICS - INLINE CopyOnWritePointerTo(CopyOnWritePointerTo &&from) NOEXCEPT; - INLINE CopyOnWritePointerTo(PointerTo &&from) NOEXCEPT; - INLINE void operator = (CopyOnWritePointerTo &&from) NOEXCEPT; - INLINE void operator = (PointerTo &&from) NOEXCEPT; -#endif + INLINE void operator = (CopyOnWritePointerTo &&from) noexcept; + INLINE void operator = (PointerTo &&from) noexcept; #ifdef COW_THREADED INLINE CPT(To) get_read_pointer(Thread *current_thread = Thread::get_current_thread()) const; diff --git a/panda/src/putil/doubleBitMask.I b/panda/src/putil/doubleBitMask.I index a6997af549..0768263afe 100644 --- a/panda/src/putil/doubleBitMask.I +++ b/panda/src/putil/doubleBitMask.I @@ -119,41 +119,12 @@ INLINE DoubleBitMask:: ~DoubleBitMask() { } -/** - * Returns true if there is a maximum number of bits that may be stored in - * this structure, false otherwise. If this returns true, the number may be - * queried in get_max_num_bits(). - * - * This method always returns true. This method is defined so generic - * programming algorithms can use DoubleBitMask or BitArray interchangeably. - */ -template -CONSTEXPR bool DoubleBitMask:: -has_max_num_bits() { - return true; -} - -/** - * If get_max_num_bits() returned true, this method may be called to return - * the maximum number of bits that may be stored in this structure. It is an - * error to call this if get_max_num_bits() return false. - * - * It is never an error to call this method. This returns the same thing as - * get_num_bits(). This method is defined so generic programming algorithms - * can use DoubleBitMask or BitArray interchangeably. - */ -template -CONSTEXPR int DoubleBitMask:: -get_max_num_bits() { - return num_bits; -} - /** * Returns the number of bits available to set in the doubleBitMask. */ template -CONSTEXPR int DoubleBitMask:: -get_num_bits() { +constexpr int DoubleBitMask:: +get_num_bits() const { return num_bits; } diff --git a/panda/src/putil/doubleBitMask.h b/panda/src/putil/doubleBitMask.h index d229eb03a6..6c32cd0122 100644 --- a/panda/src/putil/doubleBitMask.h +++ b/panda/src/putil/doubleBitMask.h @@ -49,10 +49,10 @@ PUBLISHED: INLINE ~DoubleBitMask(); - CONSTEXPR static bool has_max_num_bits(); - CONSTEXPR static int get_max_num_bits(); + constexpr static bool has_max_num_bits() {return true;} + constexpr static int get_max_num_bits() {return num_bits;} - CONSTEXPR static int get_num_bits(); + constexpr int get_num_bits() const; INLINE bool get_bit(int index) const; INLINE void set_bit(int index); INLINE void clear_bit(int index); diff --git a/panda/src/putil/factoryParams.I b/panda/src/putil/factoryParams.I index 0c6fdd09e7..04b7d2c634 100644 --- a/panda/src/putil/factoryParams.I +++ b/panda/src/putil/factoryParams.I @@ -35,24 +35,22 @@ INLINE FactoryParams:: ~FactoryParams() { } -#ifdef USE_MOVE_SEMANTICS /** * */ INLINE FactoryParams:: -FactoryParams(FactoryParams &&from) NOEXCEPT : - _params(move(from._params)), +FactoryParams(FactoryParams &&from) noexcept : + _params(std::move(from._params)), _user_data(from._user_data) {} /** * */ INLINE void FactoryParams:: -operator = (FactoryParams &&from) NOEXCEPT { - _params = move(from._params); +operator = (FactoryParams &&from) noexcept { + _params = std::move(from._params); _user_data = from._user_data; } -#endif /** * Returns the custom pointer that was associated with the factory function. diff --git a/panda/src/putil/factoryParams.h b/panda/src/putil/factoryParams.h index 5c45a6e2ee..3f987e7f66 100644 --- a/panda/src/putil/factoryParams.h +++ b/panda/src/putil/factoryParams.h @@ -37,12 +37,10 @@ class EXPCL_PANDA_PUTIL FactoryParams { public: INLINE FactoryParams(); INLINE FactoryParams(const FactoryParams ©); + INLINE FactoryParams(FactoryParams &&from) noexcept; INLINE ~FactoryParams(); -#ifdef USE_MOVE_SEMANTICS - INLINE FactoryParams(FactoryParams &&from) NOEXCEPT; - INLINE void operator = (FactoryParams &&from) NOEXCEPT; -#endif + INLINE void operator = (FactoryParams &&from) noexcept; void add_param(FactoryParam *param); void clear(); diff --git a/panda/src/putil/iterator_types.h b/panda/src/putil/iterator_types.h index 2f2966cde7..80d8f32882 100644 --- a/panda/src/putil/iterator_types.h +++ b/panda/src/putil/iterator_types.h @@ -26,7 +26,7 @@ class first_of_pair_iterator : public pair_iterator { public: typedef TYPENAME pair_iterator::value_type::first_type value_type; - first_of_pair_iterator() DEFAULT_CTOR; + first_of_pair_iterator() = default; first_of_pair_iterator(const pair_iterator &init) : pair_iterator(init) { } value_type operator *() { @@ -44,7 +44,7 @@ class second_of_pair_iterator : public pair_iterator { public: typedef TYPENAME pair_iterator::value_type::second_type value_type; - second_of_pair_iterator() DEFAULT_CTOR; + second_of_pair_iterator() = default; second_of_pair_iterator(const pair_iterator &init) : pair_iterator(init) { } value_type operator *() { @@ -61,7 +61,7 @@ class typecast_iterator : public base_iterator { public: typedef new_type value_type; - typecast_iterator() DEFAULT_CTOR; + typecast_iterator() = default; typecast_iterator(const base_iterator &init) : base_iterator(init) { } value_type operator *() { diff --git a/panda/src/putil/simpleHashMap.I b/panda/src/putil/simpleHashMap.I index 26728f1e01..2cc4e006df 100644 --- a/panda/src/putil/simpleHashMap.I +++ b/panda/src/putil/simpleHashMap.I @@ -15,7 +15,7 @@ * */ template -CONSTEXPR SimpleHashMap:: +constexpr SimpleHashMap:: SimpleHashMap(const Compare &comp) : _table(nullptr), _deleted_chain(nullptr), @@ -55,7 +55,7 @@ SimpleHashMap(const SimpleHashMap ©) : */ template INLINE SimpleHashMap:: -SimpleHashMap(SimpleHashMap &&from) NOEXCEPT : +SimpleHashMap(SimpleHashMap &&from) noexcept : _table(from._table), _deleted_chain(from._deleted_chain), _table_size(from._table_size), @@ -109,7 +109,7 @@ operator = (const SimpleHashMap ©) { */ template INLINE SimpleHashMap &SimpleHashMap:: -operator = (SimpleHashMap &&from) NOEXCEPT { +operator = (SimpleHashMap &&from) noexcept { if (this != &from) { _table = from._table; _deleted_chain = from._deleted_chain; @@ -360,7 +360,7 @@ operator [] (const Key &key) { * Returns the total number of entries in the table. Same as get_num_entries. */ template -CONSTEXPR size_t SimpleHashMap:: +constexpr size_t SimpleHashMap:: size() const { return _num_entries; } diff --git a/panda/src/putil/simpleHashMap.h b/panda/src/putil/simpleHashMap.h index 68f6352a88..6d08de5554 100644 --- a/panda/src/putil/simpleHashMap.h +++ b/panda/src/putil/simpleHashMap.h @@ -59,8 +59,8 @@ public: Key _key; - ALWAYS_INLINE_CONSTEXPR static nullptr_t get_data() { return nullptr; } - ALWAYS_INLINE_CONSTEXPR static nullptr_t modify_data() { return nullptr; } + ALWAYS_INLINE constexpr static nullptr_t get_data() { return nullptr; } + ALWAYS_INLINE constexpr static nullptr_t modify_data() { return nullptr; } ALWAYS_INLINE static void set_data(nullptr_t) {} }; @@ -85,13 +85,13 @@ class SimpleHashMap { public: #ifndef CPPPARSER - CONSTEXPR SimpleHashMap(const Compare &comp = Compare()); + constexpr SimpleHashMap(const Compare &comp = Compare()); INLINE SimpleHashMap(const SimpleHashMap ©); - INLINE SimpleHashMap(SimpleHashMap &&from) NOEXCEPT; + INLINE SimpleHashMap(SimpleHashMap &&from) noexcept; INLINE ~SimpleHashMap(); INLINE SimpleHashMap &operator = (const SimpleHashMap ©); - INLINE SimpleHashMap &operator = (SimpleHashMap &&from) NOEXCEPT; + INLINE SimpleHashMap &operator = (SimpleHashMap &&from) noexcept; INLINE void swap(SimpleHashMap &other); @@ -101,7 +101,7 @@ public: void clear(); INLINE Value &operator [] (const Key &key); - CONSTEXPR size_t size() const; + constexpr size_t size() const; INLINE const Key &get_key(size_t n) const; INLINE const Value &get_data(size_t n) const; diff --git a/panda/src/putil/updateSeq.I b/panda/src/putil/updateSeq.I index 99703059d4..ea9af8427c 100644 --- a/panda/src/putil/updateSeq.I +++ b/panda/src/putil/updateSeq.I @@ -14,41 +14,17 @@ /** * Creates an UpdateSeq in the given state. */ -CONSTEXPR UpdateSeq:: +constexpr UpdateSeq:: UpdateSeq(unsigned int seq) : _seq(seq) { } /** * Creates an UpdateSeq in the 'initial' state. */ -CONSTEXPR UpdateSeq:: +constexpr UpdateSeq:: UpdateSeq() : _seq((unsigned int)SC_initial) { } -/** - * Returns an UpdateSeq in the 'initial' state. - */ -CONSTEXPR UpdateSeq UpdateSeq:: -initial() { - return UpdateSeq((unsigned int)SC_initial); -} - -/** - * Returns an UpdateSeq in the 'old' state. - */ -CONSTEXPR UpdateSeq UpdateSeq:: -old() { - return UpdateSeq((unsigned int)SC_old); -} - -/** - * Returns an UpdateSeq in the 'fresh' state. - */ -CONSTEXPR UpdateSeq UpdateSeq:: -fresh() { - return UpdateSeq((unsigned int)SC_fresh); -} - /** * */ @@ -59,8 +35,8 @@ UpdateSeq(const UpdateSeq ©) : _seq(AtomicAdjust::get(copy._seq)) { /** * */ -CONSTEXPR UpdateSeq:: -UpdateSeq(const UpdateSeq &&from) NOEXCEPT : _seq(from._seq) { +constexpr UpdateSeq:: +UpdateSeq(const UpdateSeq &&from) noexcept : _seq(from._seq) { } /** @@ -111,7 +87,7 @@ is_fresh() const { INLINE bool UpdateSeq:: is_special() const { // This relies on the assumption that (~0 + 1) == 0. - return ((AtomicAdjust::get(_seq) + 1) <= 2); + return (((unsigned int)AtomicAdjust::get(_seq) + 1u) <= 2u); } /** diff --git a/panda/src/putil/updateSeq.h b/panda/src/putil/updateSeq.h index 5ba9de908f..bdddadde6e 100644 --- a/panda/src/putil/updateSeq.h +++ b/panda/src/putil/updateSeq.h @@ -36,16 +36,16 @@ */ class EXPCL_PANDA_PUTIL UpdateSeq { private: - CONSTEXPR UpdateSeq(unsigned int seq); + constexpr UpdateSeq(unsigned int seq); PUBLISHED: - CONSTEXPR UpdateSeq(); - CONSTEXPR static UpdateSeq initial(); - CONSTEXPR static UpdateSeq old(); - CONSTEXPR static UpdateSeq fresh(); + constexpr UpdateSeq(); + constexpr static UpdateSeq initial() { return UpdateSeq(SC_initial); } + constexpr static UpdateSeq old() { return UpdateSeq(SC_old); } + constexpr static UpdateSeq fresh() { return UpdateSeq(SC_fresh); } INLINE UpdateSeq(const UpdateSeq ©); - CONSTEXPR UpdateSeq(const UpdateSeq &&from) NOEXCEPT; + constexpr UpdateSeq(const UpdateSeq &&from) noexcept; INLINE UpdateSeq &operator = (const UpdateSeq ©); INLINE void clear(); @@ -76,7 +76,7 @@ private: INLINE static bool priv_le(AtomicAdjust::Integer a, AtomicAdjust::Integer b); private: - enum SpecialCases { + enum SpecialCases : unsigned int { SC_initial = 0, SC_old = 1, SC_fresh = ~(unsigned int)0, diff --git a/panda/src/putil/weakKeyHashMap.I b/panda/src/putil/weakKeyHashMap.I index f894411f24..514818a9be 100644 --- a/panda/src/putil/weakKeyHashMap.I +++ b/panda/src/putil/weakKeyHashMap.I @@ -295,7 +295,6 @@ set_data(size_t n, const Value &data) { _table[n]._data = data; } -#ifdef USE_MOVE_SEMANTICS /** * Changes the data for the nth slot of the table. * @@ -309,7 +308,6 @@ set_data(size_t n, Value &&data) { nassertv(has_element(n)); _table[n]._data = move(data); } -#endif // USE_MOVE_SEMANTICS /** * Removes the nth slot from the table. @@ -337,7 +335,7 @@ remove_element(size_t n) { clear_element(i); --_num_entries; } else { - size_t wants_index = get_hash(_table[i]._key); + size_t wants_index = get_hash(_table[i]._key.get_orig()); if (wants_index != i) { // This one was a hash conflict; try to put it where it belongs. We // can't just put it in n, since maybe it belongs somewhere after n. @@ -611,13 +609,9 @@ expand_table() { new_index = (new_index + 1) & (_table_size - 1); } -#ifdef USE_MOVE_SEMANTICS // Use C++11 rvalue references to invoke the move constructor, which may // be more efficient. - new(&_table[new_index]) TableEntry(move(old_map._table[i])); -#else - new(&_table[new_index]) TableEntry(old_map._table[i]); -#endif + new(&_table[new_index]) TableEntry(std::move(old_map._table[i])); exists_array[new_index] = true; ++_num_entries; } diff --git a/panda/src/putil/weakKeyHashMap.h b/panda/src/putil/weakKeyHashMap.h index 3769660fbc..b29a846e96 100644 --- a/panda/src/putil/weakKeyHashMap.h +++ b/panda/src/putil/weakKeyHashMap.h @@ -50,9 +50,7 @@ public: INLINE const Value &get_data(size_t n) const; INLINE Value &modify_data(size_t n); INLINE void set_data(size_t n, const Value &data); -#ifdef USE_MOVE_SEMANTICS INLINE void set_data(size_t n, Value &&data); -#endif void remove_element(size_t n); INLINE size_t get_num_entries() const; @@ -82,11 +80,10 @@ private: INLINE TableEntry(const TableEntry ©) : _key(copy._key), _data(copy._data) {} -#ifdef USE_MOVE_SEMANTICS - INLINE TableEntry(TableEntry &&from) NOEXCEPT : - _key(move(from._key)), - _data(move(from._data)) {} -#endif + INLINE TableEntry(TableEntry &&from) noexcept : + _key(std::move(from._key)), + _data(std::move(from._data)) {} + WCPT(Key) _key; Value _data; }; diff --git a/panda/src/putil/writableParam.h b/panda/src/putil/writableParam.h index 7bd49ebd30..bc0f600696 100644 --- a/panda/src/putil/writableParam.h +++ b/panda/src/putil/writableParam.h @@ -39,7 +39,7 @@ public: private: // The assignment operator cannot be used for this class. - WritableParam &operator = (const WritableParam &other) DELETED_ASSIGN; + WritableParam &operator = (const WritableParam &other) = delete; public: virtual TypeHandle get_type() const { diff --git a/panda/src/recorder/mouseRecorder.h b/panda/src/recorder/mouseRecorder.h index f43150c2b8..7122c12299 100644 --- a/panda/src/recorder/mouseRecorder.h +++ b/panda/src/recorder/mouseRecorder.h @@ -77,9 +77,9 @@ public: virtual void write_datagram(BamWriter *manager, Datagram &dg); virtual void write_recorder(BamWriter *manager, Datagram &dg); - INLINE virtual int get_ref_count() const FINAL { return ReferenceCount::get_ref_count(); }; - INLINE virtual void ref() const FINAL { ReferenceCount::ref(); }; - INLINE virtual bool unref() const FINAL { return ReferenceCount::unref(); }; + INLINE virtual int get_ref_count() const final { return ReferenceCount::get_ref_count(); }; + INLINE virtual void ref() const final { ReferenceCount::ref(); }; + INLINE virtual bool unref() const final { return ReferenceCount::unref(); }; protected: static TypedWritable *make_from_bam(const FactoryParams ¶ms); diff --git a/panda/src/recorder/socketStreamRecorder.h b/panda/src/recorder/socketStreamRecorder.h index 3b43f5ffcd..231ac19f28 100644 --- a/panda/src/recorder/socketStreamRecorder.h +++ b/panda/src/recorder/socketStreamRecorder.h @@ -74,9 +74,9 @@ public: static void register_with_read_factory(); virtual void write_recorder(BamWriter *manager, Datagram &dg); - INLINE virtual int get_ref_count() const FINAL { return ReferenceCount::get_ref_count(); }; - INLINE virtual void ref() const FINAL { ReferenceCount::ref(); }; - INLINE virtual bool unref() const FINAL { return ReferenceCount::unref(); }; + INLINE virtual int get_ref_count() const final { return ReferenceCount::get_ref_count(); }; + INLINE virtual void ref() const final { ReferenceCount::ref(); }; + INLINE virtual bool unref() const final { return ReferenceCount::unref(); }; protected: static RecorderBase *make_recorder(const FactoryParams ¶ms); diff --git a/panda/src/speedtree/stTree.cxx b/panda/src/speedtree/stTree.cxx index fb00fc1bea..7a09205d6e 100644 --- a/panda/src/speedtree/stTree.cxx +++ b/panda/src/speedtree/stTree.cxx @@ -61,15 +61,6 @@ STTree(const Filename &fullpath) : _is_valid = true; } - -/** - * An STTree copy constructor is not supported. - */ -STTree:: -STTree(const STTree ©) { - nassertv(false); -} - /** * */ diff --git a/panda/src/speedtree/stTree.h b/panda/src/speedtree/stTree.h index 55c4dacbb7..379223aa97 100644 --- a/panda/src/speedtree/stTree.h +++ b/panda/src/speedtree/stTree.h @@ -28,8 +28,7 @@ class SpeedTreeNode; class EXPCL_PANDASPEEDTREE STTree : public TypedReferenceCount, public Namable { PUBLISHED: STTree(const Filename &fullpath); -private: - STTree(const STTree ©); + STTree(const STTree ©) = delete; PUBLISHED: INLINE const Filename &get_fullpath() const; diff --git a/panda/src/testbed/pview.cxx b/panda/src/testbed/pview.cxx index 6d68f099ab..b5bb629b0c 100644 --- a/panda/src/testbed/pview.cxx +++ b/panda/src/testbed/pview.cxx @@ -29,12 +29,6 @@ #include "asyncTask.h" #include "boundingSphere.h" -// By including checkPandaVersion.h, we guarantee that runtime attempts to run -// pview will fail if it inadvertently links with the wrong version of -// libdtool.so.dll. - -#include "checkPandaVersion.h" - PandaFramework framework; ConfigVariableBool pview_test_hack diff --git a/panda/src/text/dynamicTextGlyph.I b/panda/src/text/dynamicTextGlyph.I index e6406e0d0d..23e44ee8ce 100644 --- a/panda/src/text/dynamicTextGlyph.I +++ b/panda/src/text/dynamicTextGlyph.I @@ -39,25 +39,6 @@ DynamicTextGlyph(int character, PN_stdfloat advance) : { } -/** - * Copying DynamicTextGlyph objects is not allowed. - */ -INLINE DynamicTextGlyph:: -DynamicTextGlyph(const DynamicTextGlyph &) : - TextGlyph(0) -{ - nassertv(false); -} - -/** - * Copying DynamicTextGlyph objects is not allowed. - */ -INLINE void DynamicTextGlyph:: -operator = (const DynamicTextGlyph &) { - nassertv(false); -} - - /** * Returns the DynamicTextPage that this glyph is on. */ diff --git a/panda/src/text/dynamicTextGlyph.h b/panda/src/text/dynamicTextGlyph.h index a90308977c..73ec2835a8 100644 --- a/panda/src/text/dynamicTextGlyph.h +++ b/panda/src/text/dynamicTextGlyph.h @@ -34,9 +34,9 @@ public: int x, int y, int x_size, int y_size, int margin, PN_stdfloat advance); INLINE DynamicTextGlyph(int character, PN_stdfloat advance); -private: - INLINE DynamicTextGlyph(const DynamicTextGlyph ©); - INLINE void operator = (const DynamicTextGlyph ©); + DynamicTextGlyph(const DynamicTextGlyph ©) = delete; + + DynamicTextGlyph &operator = (const DynamicTextGlyph ©) = delete; PUBLISHED: virtual ~DynamicTextGlyph(); diff --git a/panda/src/text/textAssembler.cxx b/panda/src/text/textAssembler.cxx index 49c507dafd..6abe29d7a0 100644 --- a/panda/src/text/textAssembler.cxx +++ b/panda/src/text/textAssembler.cxx @@ -1222,7 +1222,7 @@ generate_quads(GeomNode *geom_node, const QuadMap &quad_map) { *(idx_ptr++) = i + 3; i += 4; - glyphs.push_back(MOVE(quad._glyph)); + glyphs.push_back(move(quad._glyph)); } } else { // 16-bit index case. @@ -1278,7 +1278,7 @@ generate_quads(GeomNode *geom_node, const QuadMap &quad_map) { *(idx_ptr++) = i + 3; i += 4; - glyphs.push_back(MOVE(quad._glyph)); + glyphs.push_back(move(quad._glyph)); } } } @@ -1796,7 +1796,7 @@ draw_underscore(TextAssembler::PlacedGlyphs &placed_glyphs, // LVecBase4(0), RenderState::make_empty()); GlyphPlacement placement; - placement._glyph = MOVE(glyph); + placement._glyph = move(glyph); placement._xpos = 0; placement._ypos = 0; placement._scale = 1; @@ -2453,7 +2453,7 @@ assign_quad_to(QuadMap &quad_map, const RenderState *state, quad._dimensions += LVecBase4(offset[0], -offset[1], offset[0], -offset[1]); quad._glyph = _glyph; - quad_map[state->compose(_glyph->get_state())].push_back(MOVE(quad)); + quad_map[state->compose(_glyph->get_state())].push_back(move(quad)); } } diff --git a/panda/src/vision/openCVTexture.cxx b/panda/src/vision/openCVTexture.cxx index 7d09636b0c..5990e77321 100644 --- a/panda/src/vision/openCVTexture.cxx +++ b/panda/src/vision/openCVTexture.cxx @@ -48,18 +48,6 @@ OpenCVTexture(const string &name) : { } -/** - * Use OpenCVTexture::make_copy() to make a duplicate copy of an existing - * OpenCVTexture. - */ -OpenCVTexture:: -OpenCVTexture(const OpenCVTexture ©) : - VideoTexture(copy), - _pages(copy._pages) -{ - nassertv(false); -} - /** * */ diff --git a/panda/src/vision/openCVTexture.h b/panda/src/vision/openCVTexture.h index 1ad8e11a7a..7226202a7f 100644 --- a/panda/src/vision/openCVTexture.h +++ b/panda/src/vision/openCVTexture.h @@ -29,9 +29,7 @@ struct CvCapture; class EXPCL_VISION OpenCVTexture : public VideoTexture { PUBLISHED: OpenCVTexture(const string &name = string()); -protected: - OpenCVTexture(const OpenCVTexture ©); -PUBLISHED: + OpenCVTexture(const OpenCVTexture ©) = delete; virtual ~OpenCVTexture(); bool from_camera(int camera_index = -1, int z = 0, diff --git a/tests/pgraph/test_nodepath.py b/tests/pgraph/test_nodepath.py index a625533634..1b98da32d7 100644 --- a/tests/pgraph/test_nodepath.py +++ b/tests/pgraph/test_nodepath.py @@ -1,3 +1,5 @@ +import pytest, sys + def test_nodepath_empty(): """Tests NodePath behavior for empty NodePaths.""" from panda3d.core import NodePath @@ -79,3 +81,45 @@ def test_nodepath_transform_composition(): leg2 = node1.get_transform().compose(node3.get_transform()) relative_transform = leg1.get_inverse().compose(leg2) assert np1.get_transform(np2) == relative_transform + + +def test_weak_nodepath_comparison(): + from panda3d.core import NodePath, WeakNodePath + + path = NodePath("node") + weak = WeakNodePath(path) + + assert path == weak + assert weak == path + assert weak <= path + assert path <= weak + assert weak >= path + assert path >= weak + assert not (path != weak) + assert not (weak != path) + assert not (weak > path) + assert not (path > weak) + assert not (weak < path) + assert not (path < weak) + + assert hash(path) == hash(weak) + assert weak.get_node_path() == path + assert weak.node() == path.node() + + +def test_nodepath_python_tags(): + from panda3d.core import NodePath + + path = NodePath("node") + + with pytest.raises(KeyError): + path.python_tags["foo"] + + path.python_tags["foo"] = "bar" + + assert path.python_tags["foo"] == "bar" + + # Make sure reference count stays the same + rc1 = sys.getrefcount(path.python_tags) + rc2 = sys.getrefcount(path.python_tags) + assert rc1 == rc2 diff --git a/tests/putil/test_datagram.py b/tests/putil/test_datagram.py index 1349bd5656..171363109a 100644 --- a/tests/putil/test_datagram.py +++ b/tests/putil/test_datagram.py @@ -97,6 +97,24 @@ def test_iterator(datagram_small): verify(dgi) +# This tests the copy constructor: +def test_copy(datagram_small): + dg, verify = datagram_small + + dg2 = core.Datagram(dg) + dgi = core.DatagramIterator(dg2) + verify(dgi) + + +def test_assign(datagram_small): + dg, verify = datagram_small + + dg2 = core.Datagram() + dg2.assign(dg) + dgi = core.DatagramIterator(dg2) + verify(dgi) + + # These test DatagramInputFile/DatagramOutputFile: def do_file_test(dg, verify, filename): @@ -147,10 +165,10 @@ def test_file_corrupt(datagram_small, tmpdir): dof.put_datagram(dg) dof.close() - # Corrupt the size header to 4GB - with p.open(mode='wb') as f: + # Corrupt the size header to 1GB + with p.open(mode='r+b') as f: f.seek(0) - f.write(b'\xFF\xFF\xFF\xFF') + f.write(b'\xFF\xFF\xFF\x4F') dg2 = core.Datagram() dif = core.DatagramInputFile() @@ -158,4 +176,15 @@ def test_file_corrupt(datagram_small, tmpdir): assert not dif.get_datagram(dg2) dif.close() + # Truncate the file + for size in [12, 8, 4, 3, 2, 1, 0]: + with p.open(mode='r+b') as f: + f.truncate(size) + + dg2 = core.Datagram() + dif = core.DatagramInputFile() + dif.open(filename) + assert not dif.get_datagram(dg2) + dif.close() + # Should we test that dg2 is unmodified? diff --git a/tests/putil/test_updateseq.py b/tests/putil/test_updateseq.py new file mode 100644 index 0000000000..5cd7312595 --- /dev/null +++ b/tests/putil/test_updateseq.py @@ -0,0 +1,105 @@ +from panda3d.core import UpdateSeq + + +def test_updateseq_initial(): + seq = UpdateSeq() + assert seq == UpdateSeq.initial() + + assert seq.is_special() + assert seq.is_initial() + assert not seq.is_old() + assert not seq.is_fresh() + + assert seq.seq == 0 + + initial = UpdateSeq.initial() + assert seq == initial + assert seq >= initial + assert seq <= initial + assert not (seq != initial) + assert not (seq > initial) + assert not (seq < initial) + + fresh = UpdateSeq.fresh() + assert not (seq == fresh) + assert not (seq >= fresh) + assert seq <= fresh + assert seq != fresh + assert not (seq > fresh) + assert seq < fresh + + old = UpdateSeq.old() + assert not (seq == old) + assert not (seq >= old) + assert not (seq > old) + assert seq != old + assert seq <= old + assert seq < old + + +def test_updateseq_fresh(): + seq = UpdateSeq.fresh() + + assert seq.is_special() + assert not seq.is_initial() + assert not seq.is_old() + assert seq.is_fresh() + + initial = UpdateSeq.initial() + assert not (seq == initial) + assert seq != initial + assert seq > initial + assert seq >= initial + assert not (seq < initial) + assert not (seq <= initial) + + fresh = UpdateSeq.fresh() + assert seq == fresh + assert seq >= fresh + assert seq <= fresh + assert not (seq != fresh) + assert not (seq > fresh) + assert not (seq < fresh) + + old = UpdateSeq.old() + assert not (seq == old) + assert not (seq <= old) + assert not (seq < old) + assert seq != old + assert seq >= old + assert seq > old + + +def test_updateseq_old(): + seq = UpdateSeq.old() + + assert seq.is_special() + assert not seq.is_initial() + assert seq.is_old() + assert not seq.is_fresh() + + assert seq.seq == 1 + + initial = UpdateSeq.initial() + assert not (seq == initial) + assert not (seq <= initial) + assert not (seq < initial) + assert seq != initial + assert seq > initial + assert seq >= initial + + fresh = UpdateSeq.fresh() + assert not (seq == fresh) + assert not (seq >= fresh) + assert not (seq > fresh) + assert seq <= fresh + assert seq != fresh + assert seq < fresh + + old = UpdateSeq.old() + assert seq == old + assert seq >= old + assert seq <= old + assert not (seq != old) + assert not (seq > old) + assert not (seq < old)