summaryrefslogtreecommitdiff
path: root/src/threading
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-10-27 02:51:43 -0400
committerkwolekr <kwolekr@minetest.net>2015-10-27 22:05:08 -0400
commitc56d7fe0eba7905b0a63c4a1cfe909988653c23d (patch)
treefd5158b3efe0a2f2b48c54afc73f7bcecb1cb9b7 /src/threading
parentca8e56c15a26bc5f3d1dffe5fd39e1ca4b82d6f8 (diff)
downloadminetest-c56d7fe0eba7905b0a63c4a1cfe909988653c23d.tar.gz
minetest-c56d7fe0eba7905b0a63c4a1cfe909988653c23d.tar.bz2
minetest-c56d7fe0eba7905b0a63c4a1cfe909988653c23d.zip
Add DISABLE_CLASS_COPY macro (and use it)
Use this macro to disallow copying of an object using the assignment operator or copy constructor. This catches otherwise silent-but-deadly mistakes such as "ServerMap map = env->getMap();" at compile time. If so desired, it is still possible to copy a class, but it now requires an explicit call to memcpy or std::copy.
Diffstat (limited to 'src/threading')
-rw-r--r--src/threading/mutex.h3
-rw-r--r--src/threading/semaphore.h3
-rw-r--r--src/threading/thread.h1
3 files changed, 7 insertions, 0 deletions
diff --git a/src/threading/mutex.h b/src/threading/mutex.h
index 4c9af71bf..f1a4882b7 100644
--- a/src/threading/mutex.h
+++ b/src/threading/mutex.h
@@ -44,6 +44,7 @@ DEALINGS IN THE SOFTWARE.
#include <pthread.h>
#endif
+#include "basicmacros.h"
class Mutex
{
@@ -59,6 +60,8 @@ private:
#else // pthread
pthread_mutex_t mutex;
#endif
+
+ DISABLE_CLASS_COPY(Mutex);
};
#endif // C++11
diff --git a/src/threading/semaphore.h b/src/threading/semaphore.h
index 58d758f2e..736f2bc78 100644
--- a/src/threading/semaphore.h
+++ b/src/threading/semaphore.h
@@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <semaphore.h>
#endif
+#include "basicmacros.h"
class Semaphore {
public:
@@ -46,6 +47,8 @@ private:
#else
sem_t semaphore;
#endif
+
+ DISABLE_CLASS_COPY(Semaphore);
};
#endif
diff --git a/src/threading/thread.h b/src/threading/thread.h
index 3d85e0eb9..83ca785c7 100644
--- a/src/threading/thread.h
+++ b/src/threading/thread.h
@@ -161,6 +161,7 @@ private:
std::thread *m_thread_obj;
#endif
+ DISABLE_CLASS_COPY(Thread);
};
#endif