Statistics
| Branch: | Revision:

root / include / cpthreadlock.h @ master

History | View | Annotate | Download (1.28 KB)

1 2c43d39b Simon Tenbusch
//==========================================================================
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 e118c57b Simon Tenbusch
 Copyright (C) 2011 Simon Tenbusch
15 b781545c Georg Kunz
 Copyright (C) 2012 Georg Kunz
16 2c43d39b Simon Tenbusch

17 e118c57b Simon Tenbusch
 This file is distributed WITHOUT ANY WARRANTY. See the file
18
 `license' for details on this and other legal matters.
19 2c43d39b Simon Tenbusch
 *--------------------------------------------------------------*/
20
21
#ifndef CPTHREADLOCK_H_
22
#define CPTHREADLOCK_H_
23
24
#include <pthread.h>
25
26 b781545c Georg Kunz
class cPThreadLock
27 e118c57b Simon Tenbusch
{
28 2c43d39b Simon Tenbusch
private:
29 93d0d4d3 Simon Tenbusch
    pthread_mutex_t mutex;
30 b781545c Georg Kunz
31 2c43d39b Simon Tenbusch
public:
32 e118c57b Simon Tenbusch
    /**
33
     * Constructor.
34
     */
35 b781545c Georg Kunz
    cPThreadLock()
36
    {
37
        pthread_mutex_init(&mutex, NULL);
38
    }
39 e118c57b Simon Tenbusch
40
    /**
41
     * Destructor.
42
     */
43 b781545c Georg Kunz
    virtual ~cPThreadLock()
44
    {
45
        pthread_mutex_destroy(&mutex);
46
    }
47 e118c57b Simon Tenbusch
48
    /*
49
     * Locks the lock
50
     */
51 b781545c Georg Kunz
    inline void lock()
52
    {
53
        pthread_mutex_lock(&mutex);
54
    }
55 e118c57b Simon Tenbusch
56
    /*
57
     * Unlocks the lock
58
     */
59 b781545c Georg Kunz
    inline void unlock()
60
    {
61
        pthread_mutex_unlock(&mutex);
62
    }
63 2c43d39b Simon Tenbusch
};
64
65
#endif /* CPHTREADLOCK_H_ */