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