<commit_before>/*  LibMary - C++ library for high-performance network servers
    Copyright (C) 2011 <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/


#ifndef __LIBMARY__MUTEX__H__
#define __LIBMARY__MUTEX__H__


#include <libmary/libmary_config.h>

#include <libmary/types.h>
#ifdef LIBMARY_MT_SAFE
#include <glib/gthread.h>
#endif


namespace M {

/*c */
class Mutex
{
private:
#ifdef LIBMARY_MT_SAFE
    GStaticMutex mutex;
#endif

public:
    /*m Locks the mutex. */
    void lock ()
    {
#ifdef LIBMARY_MT_SAFE
	g_static_mutex_lock (&mutex);
#endif
    }

    /*m Unlocks the mutex. */
    void unlock ()
    {
#ifdef LIBMARY_MT_SAFE
	g_static_mutex_unlock (&mutex);
#endif
    }

#ifdef LIBMARY_MT_SAFE
    /* For internal use only:
     * should not be expected to be present in future versions. */
    GMutex* get_glib_mutex ()
    {
	return g_static_mutex_get_mutex (&mutex);
    }
#endif

#ifdef LIBMARY_MT_SAFE
    Mutex ()
    {
	g_static_mutex_init (&mutex);
    }
#endif

#ifdef LIBMARY_MT_SAFE
    ~Mutex ()
    {
	g_static_mutex_free (&mutex);
    }
#endif
};

class MutexLock
{
private:
#ifdef LIBMARY_MT_SAFE
    Mutex * const mutex;
#endif

    MutexLock& operator = (MutexLock const &);
    MutexLock (MutexLock const &);

public:
#ifdef LIBMARY_MT_SAFE
    MutexLock (Mutex * const mutex)
	: mutex (mutex)
    {
	mutex->lock ();
    }
#else
    MutexLock (Mutex * const /* mutex */)
    {
    }
#endif

    ~MutexLock ()
    {
#ifdef LIBMARY_MT_SAFE
	mutex->unlock ();
#endif
    }
};

class MutexUnlock
{
private:
#ifdef LIBMARY_MT_SAFE
    Mutex * const mutex;
#endif

    MutexUnlock& operator = (MutexUnlock const &);
    MutexUnlock (MutexUnlock const &);

public:
#ifdef LIBMARY_MT_SAFE
    MutexUnlock (Mutex * const mutex)
	: mutex (mutex)
    {
	mutex->unlock ();
    }
#else
    MutexUnlock (Mutex * const /* mutex */)
    {
    }
#endif

    ~MutexUnlock ()
    {
#ifdef LIBMARY_MT_SAFE
	mutex->lock ();
#endif
    }
};

}


#endif /* __LIBMARY__MUTEX__H__ */
<commit_msg>Mutex destructors are not needed in mt-unsafe mode.<commit_after>/*  LibMary - C++ library for high-performance network servers
    Copyright (C) 2011 <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/


#ifndef __LIBMARY__MUTEX__H__
#define __LIBMARY__MUTEX__H__


#include <libmary/libmary_config.h>

#include <libmary/types.h>
#ifdef LIBMARY_MT_SAFE
#include <glib/gthread.h>
#endif


namespace M {

/*c */
class Mutex
{
private:
#ifdef LIBMARY_MT_SAFE
    GStaticMutex mutex;
#endif

public:
    /*m Locks the mutex. */
    void lock ()
    {
#ifdef LIBMARY_MT_SAFE
	g_static_mutex_lock (&mutex);
#endif
    }

    /*m Unlocks the mutex. */
    void unlock ()
    {
#ifdef LIBMARY_MT_SAFE
	g_static_mutex_unlock (&mutex);
#endif
    }

#ifdef LIBMARY_MT_SAFE
    /* For internal use only:
     * should not be expected to be present in future versions. */
    GMutex* get_glib_mutex ()
    {
	return g_static_mutex_get_mutex (&mutex);
    }
#endif

#ifdef LIBMARY_MT_SAFE
    Mutex ()
    {
	g_static_mutex_init (&mutex);
    }
#endif

#ifdef LIBMARY_MT_SAFE
    ~Mutex ()
    {
	g_static_mutex_free (&mutex);
    }
#endif
};

class MutexLock
{
private:
#ifdef LIBMARY_MT_SAFE
    Mutex * const mutex;
#endif

    MutexLock& operator = (MutexLock const &);
    MutexLock (MutexLock const &);

public:
#ifdef LIBMARY_MT_SAFE
    MutexLock (Mutex * const mutex)
	: mutex (mutex)
    {
	mutex->lock ();
    }
#else
    MutexLock (Mutex * const /* mutex */)
    {
    }
#endif

#ifdef LIBMARY_MT_SAFE
    ~MutexLock ()
    {
	mutex->unlock ();
    }
#endif
};

class MutexUnlock
{
private:
#ifdef LIBMARY_MT_SAFE
    Mutex * const mutex;
#endif

    MutexUnlock& operator = (MutexUnlock const &);
    MutexUnlock (MutexUnlock const &);

public:
#ifdef LIBMARY_MT_SAFE
    MutexUnlock (Mutex * const mutex)
	: mutex (mutex)
    {
	mutex->unlock ();
    }
#else
    MutexUnlock (Mutex * const /* mutex */)
    {
    }
#endif

#ifdef LIBMARY_MT_SAFE
    ~MutexUnlock ()
    {
	mutex->lock ();
    }
#endif
};

}


#endif /* __LIBMARY__MUTEX__H__ */

{'fraction_non_alphanumeric': 0.09373855730501647, 'fraction_numerical': 0.006224826071036251, 'mean_word_length': 3.1137048192771086, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6367968', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1861, 'n_words': 577}