[ 
https://issues.apache.org/jira/browse/GEODE-2494?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15886164#comment-15886164
 ] 

ASF GitHub Bot commented on GEODE-2494:
---------------------------------------

Github user dgkimura commented on a diff in the pull request:

    https://github.com/apache/geode-native/pull/36#discussion_r103252978
  
    --- Diff: src/cppcache/integration-test/testSpinLock.cpp ---
    @@ -20,48 +20,44 @@
     #include "fw_dunit.hpp"
     #include <geode/GeodeCppCache.hpp>
     
    +#include <mutex>
    +#include <util/concurrent/spinlock_mutex.hpp>
    +
     #include <Condition.hpp>
     
     #include <ace/Task.h>
     #include <ace/Time_Value.h>
     #include <ace/Guard_T.h>
     
    -namespace apache {
    -namespace geode {
    -namespace client {
    +namespace {
     
    -CPPCACHE_EXPORT void* testSpinLockCreate();
    -CPPCACHE_EXPORT void testSpinLockAcquire(void* lock);
    -CPPCACHE_EXPORT void testSpinLockRelease(void* lock);
    -}  // namespace client
    -}  // namespace geode
    -}  // namespace apache
    +using apache::geode::util::concurrent::spinlock_mutex;
     
     DUNIT_TASK(s1p1, Basic)
       {
    -    void* lock = apache::geode::client::testSpinLockCreate();
    -    apache::geode::client::testSpinLockAcquire(lock);
    -    apache::geode::client::testSpinLockRelease(lock);
    +    spinlock_mutex s;
    +    { std::lock_guard<spinlock_mutex> lk(s); }
       }
     END_TASK(Basic)
     
     perf::Semaphore* triggerA;
     perf::Semaphore* triggerB;
     perf::Semaphore* triggerM;
     
    -void* lock;
    +spinlock_mutex lock;
     ACE_Time_Value* btime;
     
     class ThreadA : public ACE_Task_Base {
      public:
       ThreadA() : ACE_Task_Base() {}
     
       int svc() {
    -    apache::geode::client::testSpinLockAcquire(lock);
    -    LOG("ThreadA: Acquired lock x.");
    -    triggerM->release();
    -    triggerA->acquire();
    -    apache::geode::client::testSpinLockRelease(lock);
    +    {
    +      std::lock_guard<spinlock_mutex> lk(lock);
    +      LOG("ThreadA: Acquired lock x.");
    +      triggerM->release();
    +      triggerA->acquire();
    +    }
    --- End diff --
    
    So this has to be inside its own block scope so that 
`std::lock_guard<spinlock_mutex> lk` will go out of scope and release the 
`spinlock_mutex`?


> Replace SpinLock class with C++11 style BasicLockable class, spinlock_mutex.
> ----------------------------------------------------------------------------
>
>                 Key: GEODE-2494
>                 URL: https://issues.apache.org/jira/browse/GEODE-2494
>             Project: Geode
>          Issue Type: Sub-task
>          Components: native client
>            Reporter: Jacob S. Barrett
>            Assignee: Jacob S. Barrett
>
> Replace {{SpinLock}} class with C++11 style 
> {{[BasicLockable|http://en.cppreference.com/w/cpp/concept/BasicLockable]}} 
> class, {{spinlock_mutex}}. You can find several public domain examples of how 
> to implement a {{spinlock_mutex}} that can be used with 
> {{[std::lock_guard|http://en.cppreference.com/w/cpp/thread/lock_guard]}}.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to