lemon/bits/lock.h
changeset 1066 b208de044477
child 1092 dceba191c00d
equal deleted inserted replaced
-1:000000000000 0:1f20ebf25a91
       
     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-2012
       
     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