wrap dangerdeep's mutex into its own namespace so that it doesn't conflict

with std::mutex on modern compilers.
Fixes the build with clang, and still builds with gcc
This commit is contained in:
espie 2017-04-30 08:56:45 +00:00
parent ad99aa28c7
commit 6def882e02
10 changed files with 147 additions and 1 deletions

View File

@ -1,8 +1,9 @@
# $OpenBSD: Makefile,v 1.2 2017/04/10 11:45:28 sthen Exp $
# $OpenBSD: Makefile,v 1.3 2017/04/30 08:56:45 espie Exp $
COMMENT = WWII German submarine simulator
PKGNAME = dangerdeep-0.3.99.3327
REVISION = 0
CATEGORIES = games

View File

@ -0,0 +1,11 @@
$OpenBSD: patch-src_condvar_cpp,v 1.1 2017/04/30 08:56:45 espie Exp $
--- src/condvar.cpp.orig
+++ src/condvar.cpp
@@ -24,6 +24,7 @@
#include "error.h"
#include <SDL.h>
+using dd::mutex;
condvar::condvar()
{
cdv = SDL_CreateCond();

View File

@ -0,0 +1,11 @@
$OpenBSD: patch-src_condvar_h,v 1.1 2017/04/30 08:56:45 espie Exp $
--- src/condvar.h.orig
+++ src/condvar.h
@@ -29,6 +29,7 @@
///@note Condition variables work toger with class mutex.
class condvar
{
+ typedef dd::mutex mutex;
protected:
struct SDL_cond* cdv;
private:

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-src_game_h,v 1.1 2017/04/30 08:56:45 espie Exp $
--- src/game.h.orig
+++ src/game.h
@@ -212,7 +212,7 @@ class game (protected)
class simulate_worker : public thread
{
- mutex mtx;
+ dd::mutex mtx;
condvar cond;
condvar condfini;
game& gm;

View File

@ -0,0 +1,11 @@
$OpenBSD: patch-src_log_cpp,v 1.1 2017/04/30 08:56:45 espie Exp $
--- src/log.cpp.orig
+++ src/log.cpp
@@ -30,6 +30,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston,
#include <stdexcept>
#include <SDL.h>
+using dd::mutex;
struct log_msg
{

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-src_message_queue_h,v 1.1 2017/04/30 08:56:45 espie Exp $
--- src/message_queue.h.orig
+++ src/message_queue.h
@@ -73,7 +73,7 @@ class message_queue
protected:
std::list<message*> myqueue;
- mutex mymutex;
+ dd::mutex mymutex;
condvar emptycondvar;
condvar ackcondvar;
bool msginqueue;

View File

@ -0,0 +1,11 @@
$OpenBSD: patch-src_modelmeasure_cpp,v 1.1 2017/04/30 08:56:45 espie Exp $
--- src/modelmeasure.cpp.orig
+++ src/modelmeasure.cpp
@@ -42,6 +42,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston,
#include "primitives.h"
using namespace std;
+using dd::mutex;
/*
- measure cross section (graphical)

View File

@ -0,0 +1,17 @@
$OpenBSD: patch-src_mutex_cpp,v 1.1 2017/04/30 08:56:45 espie Exp $
--- src/mutex.cpp.orig
+++ src/mutex.cpp
@@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston,
#include "error.h"
#include <SDL.h>
+namespace dd {
mutex::mutex()
{
mtx = SDL_CreateMutex();
@@ -52,4 +53,5 @@ void mutex::unlock()
{
if (SDL_mutexV(mtx) < 0)
throw sdl_error("mutex unlock failed");
+}
}

View File

@ -0,0 +1,40 @@
$OpenBSD: patch-src_mutex_h,v 1.1 2017/04/30 08:56:45 espie Exp $
--- src/mutex.h.orig
+++ src/mutex.h
@@ -26,11 +26,15 @@
/// A classical mutex.
///@note This implementation is per default recursive, so you can lock the mutex again
/// in the same thread where you already have locked it.
+struct SDL_mutex;
+class condvar;
+
+namespace dd {
class mutex
{
- friend class condvar;
+ friend class ::condvar;
protected:
- struct SDL_mutex* mtx;
+ struct ::SDL_mutex* mtx;
private:
mutex(const mutex& );
mutex& operator=(const mutex& );
@@ -47,9 +51,9 @@ class mutex
/// unlock the mutex
void unlock();
};
+}
-
/// A handy helper class for mutexes.
///@note Create a local object of that class and give it a mutex. It will lock the mutex
/// in its constructor and automatically unlock it in the destructor.
@@ -57,6 +61,7 @@ class mutex
/// inside the block or function that the object is declared in.
class mutex_locker
{
+ typedef dd::mutex mutex;
protected:
mutex& mymutex;
private:

View File

@ -0,0 +1,20 @@
$OpenBSD: patch-src_thread_h,v 1.1 2017/04/30 08:56:45 espie Exp $
--- src/thread.h.orig
+++ src/thread.h
@@ -25,6 +25,7 @@
#include "condvar.h"
#include <stdexcept>
+#include <string>
#if defined WIN32 && defined _MSC_VER
// win32 lacks stdint.h (thankfully SDL provides...)
@@ -53,7 +54,7 @@ class thread
struct SDL_Thread* thread_id;
bool thread_abort_request;
thread_state_t thread_state;
- mutex thread_state_mutex;
+ dd::mutex thread_state_mutex;
condvar thread_start_cond;
std::string thread_error_message; // to pass exception texts via thread boundaries
const char* myname;