Project

General

Profile

Bug #1270 » cpp11-mt.diff

multithreading changes - Ben Touchette, 17 Feb 2017 18:03

View differences:

exiv2-0.26-svn-1/Makefile 2017-01-13 12:42:37.000000000 -0500
90 90
bugfixes-test.sh   crw-test.sh     curliotest.sh       eps-preview-test.sh    eps-test.sh       exifdata-test.sh \
91 91
exiv2-test.sh      httpiotest.sh   icc-test.sh         imagetest.sh           iotest.sh         iptctest.sh      \
92 92
modify-test.sh     path-test.sh    preview-test.sh     sshiotest.sh           stringto-test.sh  tiff-test.sh     \
93
video-test.sh      write-test.sh   write-video-test.sh write2-test.sh         xmpparser-test.sh webp-test.sh:
93
video-test.sh      write-test.sh   write-video-test.sh write2-test.sh         xmpparser-test.sh webp-test.sh     \
94
mt-test.sh:
94 95
	cd test && ./$@
95 96

  
96 97
# convenience targets for running selected test scripts
exiv2-0.26-svn-1/include/exiv2/image.hpp 2017-01-13 12:42:37.000000000 -0500
36 36
// + standard includes
37 37
#include <string>
38 38
#include <vector>
39
#ifdef EXV_USING_CPP_ELEVEN
40
#include <mutex>
41
#endif
39 42

  
40 43
// *****************************************************************************
41 44
// namespace extensions
......
476 483

  
477 484
        int imageType() const { return imageType_; }
478 485

  
486
#ifdef EXV_USING_CPP_ELEVEN
487
        static std::mutex mutex_;
488
#endif
489

  
479 490
    protected:
480 491
        // DATA
481 492
        BasicIo::AutoPtr  io_;                //!< Image data IO pointer
exiv2-0.26-svn-1/include/exiv2/properties.hpp 2017-01-13 12:42:37.000000000 -0500
45 45
#include <string>
46 46
#include <iosfwd>
47 47
#include <memory>
48
#ifdef EXV_USING_CPP_ELEVEN
49
#include <mutex>
50
#endif
48 51

  
49 52
// *****************************************************************************
50 53
// namespace extensions
......
238 241
          @brief Get all registered namespaces (for both Exiv2 and XMPsdk)
239 242
         */
240 243
        static void registeredNamespaces(Exiv2::Dictionary& nsDict);
244
#ifdef EXV_USING_CPP_ELEVEN
245
        static std::mutex mutex_;
246
#endif
241 247

  
242 248
    }; // class XmpProperties
243 249

  
exiv2-0.26-svn-1/samples/CMakeLists.txt 2017-01-13 13:03:43.000000000 -0500
82 82
TARGET_LINK_LIBRARIES( geotag    ${PRIVATE_VAR} exiv2lib Threads::Threads ${EXPAT_LIBRARIES} ${ZLIB_LIBRARIES})
83 83
INSTALL( TARGETS       geotag    ${INSTALL_TARGET_STANDARD_ARGS} )
84 84

  
85
IF ( ${EXIV2_CPP_STANDARD} LESS 98 AND ${EXIV2_CPP_STANDARD} GREATER 10  )
86
    SET( MULTITHREAD_SRC   mt-test.cpp )
87
    ADD_EXECUTABLE(        mt-test   ${MULTITHREAD_SRC} )
88
    SET_PROPERTY(   TARGET mt-test   PROPERTY CXX_STANDARD 11)
89
    SET_TARGET_PROPERTIES( mt-test   PROPERTIES OUTPUT_NAME mt-test )
90
    TARGET_LINK_LIBRARIES( mt-test   ${PRIVATE_VAR} exiv2lib Threads::Threads ${EXPAT_LIBRARIES} ${ZLIB_LIBRARIES})
91
    INSTALL( TARGETS       mt-test   ${INSTALL_TARGET_STANDARD_ARGS} )
92
ENDIF()
93

  
85 94
# ******************************************************************************
86 95
# Man page
87 96
INSTALL( FILES exiv2samples.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 )
exiv2-0.26-svn-1/samples/Makefile 2017-01-13 12:42:37.000000000 -0500
70 70
         key-test.cpp         \
71 71
         largeiptc-test.cpp   \
72 72
         mmap-test.cpp        \
73
         mt-test.cpp          \
73 74
         prevtest.cpp         \
74 75
         remotetest.cpp       \
75 76
         stringto-test.cpp    \
exiv2-0.26-svn-1/samples/mt-test.cpp 2017-01-13 12:42:37.000000000 -0500
17 17

  
18 18
// WARNING:             auto_ptr is not supported in C++11 implemented by gcc 4.9/C++11 and later
19 19

  
20
// Addendum:            Builds with gcc v6.2.0 with c++11 works on Linux and with MinGW64.
21

  
20 22
#include <exiv2/exiv2.hpp>
21 23
#include <iostream>
22 24
#include <iomanip>
exiv2-0.26-svn-1/src/image.cpp 2017-01-13 12:42:37.000000000 -0500
72 72
#include <cstring>
73 73
#include <cassert>
74 74
#include <iostream>
75
#ifdef EXV_USING_CPP_ELEVEN
76
#include <mutex>
77
#endif
75 78

  
76 79
#include <sys/types.h>
77 80
#include <sys/stat.h>
......
281 288
        static std::map<int,std::string> tags;
282 289
        static bool init  = true;
283 290
        static char buffer[80];
291
#ifdef EXV_USING_CPP_ELEVEN
292
        static std::mutex tagNameInitMutex;
293
#endif
284 294

  
285 295
        if ( init ) {
296
#ifdef EXV_USING_CPP_ELEVEN
297
            std::lock_guard<std::mutex> guard(tagNameInitMutex);
298
#endif
286 299
            int idx;
287 300
            const TagInfo* ti ;
288 301
            for (ti = Internal::  mnTagList(), idx = 0; ti[idx].tag_ != 0xffff; ++idx) tags[ti[idx].tag_] = ti[idx].name_;
......
293 306
            for (ti = Internal:: mpfTagList(), idx = 0; ti[idx].tag_ != 0xffff; ++idx) tags[ti[idx].tag_] = ti[idx].name_;
294 307
            for (ti = Internal::Nikon1MakerNote::tagList(), idx = 0
295 308
                                                      ; ti[idx].tag_ != 0xffff; ++idx) tags[ti[idx].tag_] = ti[idx].name_;
309
#ifdef EXV_USING_CPP_ELEVEN
310
            init = false;
311
#endif
296 312
        }
313
#ifndef EXV_USING_CPP_ELEVEN
297 314
        init = false;
315
#endif
298 316

  
299 317
        try {
300 318
            result = tags[tag].c_str();
exiv2-0.26-svn-1/src/properties.cpp 2017-01-13 12:42:37.000000000 -0500
47 47
#include <cstring>
48 48
#include <cstdlib>
49 49
#include <cctype>
50
#ifdef EXV_USING_CPP_ELEVEN
51
#include <mutex>
52
#endif
50 53

  
51 54
// *****************************************************************************
52 55
namespace {
......
2488 2491
    }
2489 2492

  
2490 2493
    XmpProperties::NsRegistry XmpProperties::nsRegistry_;
2494
#ifdef EXV_USING_CPP_ELEVEN
2495
    std::mutex XmpProperties::mutex_;
2496
#endif
2491 2497
    Internal::RWLock XmpProperties::rwLock_;
2492 2498

  
2493 2499
    const XmpNsInfo* XmpProperties::lookupNsRegistry(const XmpNsInfo::Prefix& prefix)
2494 2500
    {
2501
#ifdef EXV_USING_CPP_ELEVEN
2502
        std::lock_guard<std::mutex> guard(mutex_);
2503
#endif
2495 2504
        Internal::ScopedReadLock srl(rwLock_);
2496 2505
        return lookupNsRegistryUnsafe(prefix);
2497 2506
    }
......
2515 2524
            && ns2.substr(ns2.size() - 1, 1) != "#") ns2 += "/";
2516 2525
        // Check if there is already a registered namespace with this prefix
2517 2526
        const XmpNsInfo* xnp = lookupNsRegistryUnsafe(XmpNsInfo::Prefix(prefix));
2527
#ifdef EXV_USING_CPP_ELEVEN
2528
        std::lock_guard<std::mutex> guard(mutex_);
2529
#endif
2518 2530
        if (xnp) {
2519 2531
#ifndef SUPPRESS_WARNINGS
2520 2532
            if (strcmp(xnp->ns_, ns2.c_str()) != 0) {
(6-6/6)