<commit_before>#ifndef MUTEXWRAPPER_H
#define MUTEXWRAPPER_H
#include <wx/thread.h>
#include <wx/log.h>

template<class T>
class MutexWrapper;

class AbstractMutexWrapper{
  public:
  virtual ~AbstractMutexWrapper(){}
  virtual void Lock()=0;
  virtual void UnLock()=0;
};

template<class T>
class ScopedLocker
{
  private:
  MutexWrapper<T> &mw;
  ScopedLocker(const ScopedLocker<T> &/*other*/){}/// prevent copying
  ScopedLocker&  operator= (const ScopedLocker& /*other*/){}/// and assignment
  public:
  explicit ScopedLocker(MutexWrapper<T> &mw_):mw(mw_){
    mw.Lock();
  }
  ~ScopedLocker(){
    mw.UnLock();
  }
  T &Get(){
    return mw.GetData();
  }
};
/*
class ScopedLocker
{
  private:
  AbstractMutexWrapper *mw;
  ScopedLocker(const ScopedLocker<T> &other){}/// prevent copying
  ScopedLocker&  operator= (const ScopedLocker& other){}/// and assignment
  public:
  explicit ScopedLocker(AbstractMutexWrapper &mw_):mw(*mw_){
    mw.Lock();
  }
  ~ScopedLocker(){
    mw.UnLock();
  }
};*/


template<class T>
class MutexWrapper: public AbstractMutexWrapper
{
  wxCriticalSection mutex;/// critical section is same as mutex except on windows it only works within one process (i.e. program). I'm gonna call it mutex.
  T data;
  bool locked;
  public:
    MutexWrapper():locked(false){
    }
    virtual ~MutexWrapper(){
    }
    virtual void Lock(){
      mutex.Enter();
      locked=true;
    }
    virtual void UnLock(){
      locked=false;
      mutex.Leave();
    }
    protected:
    T &GetData(){
      if(!locked) {
            wxLogError(_T("serious error in MutexWrapper usage : not locked, but Get() is called!"));
      }
      return data;
    }
    friend class ScopedLocker<T>;
};

#endif // MUTEXWRAPPER_H

/**
    This file is part of SpringLobby,
    Copyright (C) 2007-2011

    SpringLobby is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 2 as published by
    the Free Software Foundation.

    SpringLobby is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with SpringLobby.  If not, see <http://www.gnu.org/licenses/>.
**/
<commit_msg>adapt mutexwrapper<commit_after>#ifndef MUTEXWRAPPER_H
#define MUTEXWRAPPER_H

#include <boost/thread/mutex.hpp>
#include "logging.h"

template<class T>
class MutexWrapper;

class AbstractMutexWrapper{
  public:
  virtual ~AbstractMutexWrapper(){}
  virtual void Lock()=0;
  virtual void UnLock()=0;
};

template<class T>
class ScopedLocker
{
  private:
  MutexWrapper<T> &mw;
  ScopedLocker(const ScopedLocker<T> &/*other*/){}/// prevent copying
  ScopedLocker&  operator= (const ScopedLocker& /*other*/){}/// and assignment
  public:
  explicit ScopedLocker(MutexWrapper<T> &mw_):mw(mw_){
    mw.Lock();
  }
  ~ScopedLocker(){
    mw.UnLock();
  }
  T &Get(){
    return mw.GetData();
  }
};
/*
class ScopedLocker
{
  private:
  AbstractMutexWrapper *mw;
  ScopedLocker(const ScopedLocker<T> &other){}/// prevent copying
  ScopedLocker&  operator= (const ScopedLocker& other){}/// and assignment
  public:
  explicit ScopedLocker(AbstractMutexWrapper &mw_):mw(*mw_){
    mw.Lock();
  }
  ~ScopedLocker(){
    mw.UnLock();
  }
};*/


template<class T>
class MutexWrapper: public AbstractMutexWrapper
{
  boost::mutex mutex;/// critical section is same as mutex except on windows it only works within one process (i.e. program). I'm gonna call it mutex.
  T data;
  bool locked;
  public:
    MutexWrapper():locked(false){
    }
    virtual ~MutexWrapper(){
    }
    virtual void Lock(){
      mutex.lock();
      locked=true;
    }
    virtual void UnLock(){
      locked=false;
      mutex.unlock();
    }
    protected:
    T &GetData(){
      if(!locked) {
            LslError("serious error in MutexWrapper usage : not locked, but Get() is called!");
      }
      return data;
    }
    friend class ScopedLocker<T>;
};

#endif // MUTEXWRAPPER_H

/**
    This file is part of SpringLobby,
    Copyright (C) 2007-2011

    SpringLobby is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 2 as published by
    the Free Software Foundation.

    SpringLobby is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with SpringLobby.  If not, see <http://www.gnu.org/licenses/>.
**/

{'fraction_non_alphanumeric': 0.11205644324548661, 'fraction_numerical': 0.004565262502593899, 'mean_word_length': 3.3384338433843386, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3361938', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1529, 'n_words': 485}