lemon/bits/lock.h
author Alpar Juttner <alpar@cs.elte.hu>
Wed, 17 Oct 2018 18:56:39 +0200
changeset 1177 f425c93848fa
parent 979 43a91b33f374
permissions -rw-r--r--
Merge #1.3 related bugfix heads
deba@979
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@979
     2
 *
deba@979
     3
 * This file is a part of LEMON, a generic C++ optimization library.
deba@979
     4
 *
alpar@1092
     5
 * Copyright (C) 2003-2013
deba@979
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@979
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@979
     8
 *
deba@979
     9
 * Permission to use, modify and distribute this software is granted
deba@979
    10
 * provided that this copyright notice appears in all copies. For
deba@979
    11
 * precise terms see the accompanying LICENSE file.
deba@979
    12
 *
deba@979
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@979
    14
 * express or implied, and with no claim as to its suitability for any
deba@979
    15
 * purpose.
deba@979
    16
 *
deba@979
    17
 */
deba@979
    18
deba@979
    19
#ifndef LEMON_BITS_LOCK_H
deba@979
    20
#define LEMON_BITS_LOCK_H
deba@979
    21
deba@979
    22
#include <lemon/config.h>
deba@979
    23
#if defined(LEMON_USE_PTHREAD)
deba@979
    24
#include <pthread.h>
deba@979
    25
#elif defined(LEMON_USE_WIN32_THREADS)
deba@979
    26
#include <lemon/bits/windows.h>
deba@979
    27
#endif
deba@979
    28
deba@979
    29
namespace lemon {
deba@979
    30
  namespace bits {
deba@979
    31
deba@979
    32
#if defined(LEMON_USE_PTHREAD)
deba@979
    33
    class Lock {
deba@979
    34
    public:
deba@979
    35
      Lock() {
alpar@1092
    36
        pthread_mutex_init(&_lock, 0);
deba@979
    37
      }
deba@979
    38
      ~Lock() {
alpar@1092
    39
        pthread_mutex_destroy(&_lock);
deba@979
    40
      }
deba@979
    41
      void lock() {
alpar@1092
    42
        pthread_mutex_lock(&_lock);
deba@979
    43
      }
deba@979
    44
      void unlock() {
alpar@1092
    45
        pthread_mutex_unlock(&_lock);
deba@979
    46
      }
deba@979
    47
deba@979
    48
    private:
deba@979
    49
      pthread_mutex_t _lock;
deba@979
    50
    };
deba@979
    51
#elif defined(LEMON_USE_WIN32_THREADS)
deba@979
    52
    class Lock : public WinLock {};
deba@979
    53
#else
deba@979
    54
    class Lock {
deba@979
    55
    public:
deba@979
    56
      Lock() {}
deba@979
    57
      ~Lock() {}
deba@979
    58
      void lock() {}
deba@979
    59
      void unlock() {}
alpar@1092
    60
    };
deba@979
    61
#endif
deba@979
    62
  }
deba@979
    63
}
deba@979
    64
deba@979
    65
#endif