summaryrefslogtreecommitdiffstats
path: root/fastos/src/vespa/fastos/unix_mutex.h
blob: ccf8af9d4eaed31bf9f4b619f151bec89c90e0d4 (plain) (blame)
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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
******************************************************************************
* @author  Oivind H. Danielsen
* @date    Creation date: 2000-02-02
* @file
* Class definition and implementation for FastOS_UNIX_Mutex
*****************************************************************************/



#pragma once


#include <vespa/fastos/mutex.h>


class FastOS_UNIX_Mutex : public FastOS_MutexInterface
{
private:
    FastOS_UNIX_Mutex(const FastOS_UNIX_Mutex &other);
    FastOS_UNIX_Mutex & operator = (const FastOS_UNIX_Mutex &other);
protected:
    pthread_mutex_t _mutex;

public:
    FastOS_UNIX_Mutex(void);

    ~FastOS_UNIX_Mutex(void);

    bool TryLock (void) {
        return pthread_mutex_trylock(&_mutex) == 0;
    }

    void Lock(void) {
        pthread_mutex_lock(&_mutex);
    }

    void Unlock(void) {
        pthread_mutex_unlock(&_mutex);
    }
};