Statistics
| Branch: | Revision:

root / include / cpthreadlock.h @ master

History | View | Annotate | Download (1.28 KB)

1
//==========================================================================
2
//  CPTHREADLOCK.H - part of
3
//
4
//                     Horizon/OMNeT++/OMNEST
5
//            Discrete System Simulation in C++
6
//
7
//
8
//  Declaration of the following classes:
9
//    cPThreadLock: Encapsulating pThread lock
10
//
11
//==========================================================================
12

    
13
/*--------------------------------------------------------------*
14
 Copyright (C) 2011 Simon Tenbusch
15
 Copyright (C) 2012 Georg Kunz
16

17
 This file is distributed WITHOUT ANY WARRANTY. See the file
18
 `license' for details on this and other legal matters.
19
 *--------------------------------------------------------------*/
20

    
21
#ifndef CPTHREADLOCK_H_
22
#define CPTHREADLOCK_H_
23

    
24
#include <pthread.h>
25

    
26
class cPThreadLock
27
{
28
private:
29
    pthread_mutex_t mutex;
30

    
31
public:
32
    /**
33
     * Constructor.
34
     */
35
    cPThreadLock()
36
    {
37
        pthread_mutex_init(&mutex, NULL);
38
    }
39

    
40
    /**
41
     * Destructor.
42
     */
43
    virtual ~cPThreadLock()
44
    {
45
        pthread_mutex_destroy(&mutex);
46
    }
47

    
48
    /*
49
     * Locks the lock
50
     */
51
    inline void lock()
52
    {
53
        pthread_mutex_lock(&mutex);
54
    }
55

    
56
    /*
57
     * Unlocks the lock
58
     */
59
    inline void unlock()
60
    {
61
        pthread_mutex_unlock(&mutex);
62
    }
63
};
64

    
65
#endif /* CPHTREADLOCK_H_ */