geode-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GEODE-2525) Replace random number implementation with C++11 standards
Date Sat, 24 Jun 2017 01:04:00 GMT

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

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

Github user pivotal-jbarrett commented on a diff in the pull request:

    https://github.com/apache/geode-native/pull/103#discussion_r123866557
  
    --- Diff: src/tests/cpp/fwklib/GsRandom.cpp ---
    @@ -18,60 +18,16 @@
     #include "GsRandom.hpp"
     
     #include <cstring>
    -#include <mutex>
    -#include <util/concurrent/spinlock_mutex.hpp>
     
     namespace apache {
     namespace geode {
     namespace client {
     namespace testframework {
     
    -using util::concurrent::spinlock_mutex;
    -
    -GsRandom *GsRandom::singleton = 0;
    -MTRand GsRandom::gen;
    -int32_t GsRandom::seedUsed = -101;
    -spinlock_mutex GsRandom::lck;
    -
    -/**
    -  * Creates a new random number generator using a single
    -  * <code>int32_t</code> seed.
    -  *
    -  * @param   seed   the initial seed.
    -  * @see     java.util.Random#Random(int32_t)
    -  */
    -GsRandom *GsRandom::getInstance(int32_t seed) {
    -  if (singleton == 0) {
    -    setInstance(seed);
    -  } else {
    -    std::lock_guard<spinlock_mutex> guard(lck);
    -    setSeed(seed);
    -  }
    -  return singleton;
    -}
    -
    -void GsRandom::setInstance(int32_t seed) {
    -  std::lock_guard<spinlock_mutex> guard(lck);
    -  if (singleton == 0) {
    -    singleton = new GsRandom();
    -    if (seed != -1) {
    -      singleton->gen.seed(seed);
    -    } else {
    -      singleton->gen.seed();
    -    }
    -    seedUsed = seed;
    -  }
    -}
    -
    -void GsRandom::setSeed(int32_t seed) {
    -  if (seed != seedUsed) {
    -    if (seed != -1) {
    -      singleton->gen.seed(seed);
    -    } else {
    -      singleton->gen.seed();
    -    }
    -    seedUsed = seed;
    -  }
    +GsRandom &GsRandom::getInstance() {
    +  // C++11 initializes statics threads safe
    --- End diff --
    
    Yeah probably not. I can kill it.


> Replace random number implementation with C++11 standards
> ---------------------------------------------------------
>
>                 Key: GEODE-2525
>                 URL: https://issues.apache.org/jira/browse/GEODE-2525
>             Project: Geode
>          Issue Type: Task
>          Components: native client
>            Reporter: Jacob S. Barrett
>            Assignee: Jacob S. Barrett
>
> Remove Mersenne Twister implementation from source. Use C++11 random where appropriate.
Refactor random usage to be thread safe as applicable. GsRansom uses spin lock to protect.
Consider thread local random.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message