Loading...
Searching...
No Matches
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.

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

## ~Lock()

Lock::~Lock | ( |  | ) |

inline

Definition at line 43 of file thread.h.

{
pthread_mutex_destroy(&mutex);
}

## Member Function Documentation

## break_lock()

int Lock::break_lock | ( |  | ) |

inline private

Definition at line 28 of file thread.h.

{
extern pthread_t no_thread;
int result = locked;
owner = no_thread;
locked = 0;
return result;
}
result
return result
Definition facAbsBiFact.cc:76

## is_locked()

bool Lock::is_locked | ( |  | ) |

inline

Definition at line 68 of file thread.h.

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

## lock()

void Lock::lock | ( |  | ) |

inline

Definition at line 46 of file thread.h.

{
Thread self = pthread_self();
if (owner == self) {
if (locked && !recursive)
ThreadError("locking mutex twice");
}
else
pthread_mutex_lock(&mutex);
owner = self;
locked++;
}
ThreadError
void ThreadError(const char *message)
Definition thread.cc:18
Thread
pthread_t Thread
Definition thread.h:11

## resume_lock()

void Lock::resume_lock | ( | int | l | ) |

inline private

Definition at line 24 of file thread.h.

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

## unlock()

void Lock::unlock | ( |  | ) |

inline

Definition at line 57 of file thread.h.

{
extern pthread_t no_thread;
Thread self = pthread_self();
if (owner != self)
ThreadError("unlocking unowned lock");
locked--;
if (locked == 0) {
owner = no_thread;
pthread_mutex_unlock(&mutex);
}
}

## Friends And Related Symbol 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:

- Singular/dyn_modules/systhreads/thread.h