My Project
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | Friends
Lock Class Reference

#include <thread.h>

Public Member Functions

 Lock (bool rec=false)
 
 ~Lock ()
 
void lock ()
 
void unlock ()
 
bool is_locked ()
 

Private Member Functions

void resume_lock (int l)
 
int break_lock ()
 

Private Attributes

pthread_mutex_t mutex
 
Thread owner
 
int locked
 
bool recursive
 

Friends

class ConditionVariable
 

Detailed Description

Definition at line 17 of file thread.h.

Constructor & Destructor Documentation

◆ Lock()

Lock::Lock ( bool  rec = false)
inline

Definition at line 36 of file thread.h.

36 {
37 extern pthread_t no_thread;
38 pthread_mutex_init(&mutex, NULL);
39 locked = 0;
40 recursive = rec;
42 }
Thread owner
Definition: thread.h:21
pthread_mutex_t mutex
Definition: thread.h:19
int locked
Definition: thread.h:22
bool recursive
Definition: thread.h:23
#define NULL
Definition: omList.c:12
pthread_t no_thread
Definition: thread.cc:16

◆ ~Lock()

Lock::~Lock ( )
inline

Definition at line 43 of file thread.h.

43 {
44 pthread_mutex_destroy(&mutex);
45 }

Member Function Documentation

◆ break_lock()

int Lock::break_lock ( )
inlineprivate

Definition at line 28 of file thread.h.

28 {
29 extern pthread_t no_thread;
30 int result = locked;
32 locked = 0;
33 return result;
34 }
return result
Definition: facAbsBiFact.cc:75

◆ is_locked()

bool Lock::is_locked ( )
inline

Definition at line 68 of file thread.h.

68 {
69 return locked != 0 && owner == pthread_self();
70 }

◆ lock()

void Lock::lock ( )
inline

Definition at line 46 of file thread.h.

46 {
47 Thread self = pthread_self();
48 if (owner == self) {
49 if (locked && !recursive)
50 ThreadError("locking mutex twice");
51 }
52 else
53 pthread_mutex_lock(&mutex);
54 owner = self;
55 locked++;
56 }
void ThreadError(const char *message)
Definition: thread.cc:18
pthread_t Thread
Definition: thread.h:11

◆ resume_lock()

void Lock::resume_lock ( int  l)
inlineprivate

Definition at line 24 of file thread.h.

24 {
25 owner = pthread_self();
26 locked = l;
27 }
int l
Definition: cfEzgcd.cc:100

◆ unlock()

void Lock::unlock ( )
inline

Definition at line 57 of file thread.h.

57 {
58 extern pthread_t no_thread;
59 Thread self = pthread_self();
60 if (owner != self)
61 ThreadError("unlocking unowned lock");
62 locked--;
63 if (locked == 0) {
65 pthread_mutex_unlock(&mutex);
66 }
67 }

Friends And Related Function Documentation

◆ ConditionVariable

friend class ConditionVariable
friend

Definition at line 20 of file thread.h.

Field Documentation

◆ locked

int Lock::locked
private

Definition at line 22 of file thread.h.

◆ mutex

pthread_mutex_t Lock::mutex
private

Definition at line 19 of file thread.h.

◆ owner

Thread Lock::owner
private

Definition at line 21 of file thread.h.

◆ recursive

bool Lock::recursive
private

Definition at line 23 of file thread.h.


The documentation for this class was generated from the following file: