File: mutex.h

package info (click to toggle)
meshlab 2020.09%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 45,132 kB
  • sloc: cpp: 400,238; ansic: 31,952; javascript: 1,578; sh: 387; yacc: 238; lex: 139; python: 86; makefile: 30
file content (56 lines) | stat: -rwxr-xr-x 882 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef MT_MUTEX_H
#define MT_MUTEX_H

#include "base.h"

#include <pthread.h>

namespace mt
{

class condition;

class mutex
{
    MT_PREVENT_COPY(mutex)

    public:

        typedef mutex this_type;
        typedef void  base_type;

        mutex(void)
        {
            pthread_mutex_init(&(this->m), 0);
        }

        ~mutex(void)
        {
            pthread_mutex_destroy(&(this->m));
        }

        void lock(void)
        {
            pthread_mutex_lock(&(this->m));
        }

        void unlock(void)
        {
            pthread_mutex_unlock(&(this->m));
        }
        bool tryLock(void)
        {
            int a = pthread_mutex_trylock(&(this->m));
            return a == 0;
        }

    private:

        friend class condition;

        pthread_mutex_t m;
};

}

#endif // MT_MUTEX_H