File: rw_lock.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 (57 lines) | stat: -rwxr-xr-x 754 bytes parent folder | download | duplicates (6)
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
57
#ifndef MT_RW_LOCK_H
#define MT_RW_LOCK_H

#include "base.h"

#include <pthread.h>

namespace mt
{

class rw_lock
{
	MT_PREVENT_COPY(rw_lock)

	public:

		typedef rw_lock this_type;
		typedef void    base_type;

		rw_lock(void)
		{
			pthread_rwlock_init(&(this->rw), 0);
		}

		~rw_lock(void)
		{
			pthread_rwlock_destroy(&(this->rw));
		}

		void lock_read(void)
		{
			pthread_rwlock_rdlock(&(this->rw));
		}

		void unlock_read(void)
		{
			pthread_rwlock_unlock(&(this->rw));
		}

		void lock_write(void)
		{
			pthread_rwlock_wrlock(&(this->rw));
		}

		void unlock_write(void)
		{
			pthread_rwlock_unlock(&(this->rw));
		}

	private:

		pthread_rwlock_t rw;
};

}

#endif // MT_RW_LOCK_H