lemon/bits/lock.h
changeset 1177 3c00344f49c9
parent 979 43a91b33f374
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lemon/bits/lock.h	Wed Oct 17 19:14:07 2018 +0200
     1.3 @@ -0,0 +1,65 @@
     1.4 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library.
     1.7 + *
     1.8 + * Copyright (C) 2003-2013
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +#ifndef LEMON_BITS_LOCK_H
    1.23 +#define LEMON_BITS_LOCK_H
    1.24 +
    1.25 +#include <lemon/config.h>
    1.26 +#if defined(LEMON_USE_PTHREAD)
    1.27 +#include <pthread.h>
    1.28 +#elif defined(LEMON_USE_WIN32_THREADS)
    1.29 +#include <lemon/bits/windows.h>
    1.30 +#endif
    1.31 +
    1.32 +namespace lemon {
    1.33 +  namespace bits {
    1.34 +
    1.35 +#if defined(LEMON_USE_PTHREAD)
    1.36 +    class Lock {
    1.37 +    public:
    1.38 +      Lock() {
    1.39 +        pthread_mutex_init(&_lock, 0);
    1.40 +      }
    1.41 +      ~Lock() {
    1.42 +        pthread_mutex_destroy(&_lock);
    1.43 +      }
    1.44 +      void lock() {
    1.45 +        pthread_mutex_lock(&_lock);
    1.46 +      }
    1.47 +      void unlock() {
    1.48 +        pthread_mutex_unlock(&_lock);
    1.49 +      }
    1.50 +
    1.51 +    private:
    1.52 +      pthread_mutex_t _lock;
    1.53 +    };
    1.54 +#elif defined(LEMON_USE_WIN32_THREADS)
    1.55 +    class Lock : public WinLock {};
    1.56 +#else
    1.57 +    class Lock {
    1.58 +    public:
    1.59 +      Lock() {}
    1.60 +      ~Lock() {}
    1.61 +      void lock() {}
    1.62 +      void unlock() {}
    1.63 +    };
    1.64 +#endif
    1.65 +  }
    1.66 +}
    1.67 +
    1.68 +#endif