Xmipp  v3.23.11-Nereus
Public Member Functions | List of all members
Condition Class Reference

#include <xmipp_threads.h>

Public Member Functions

 Condition ()
 
 ~Condition ()
 
void lock ()
 
void unlock ()
 
void wait ()
 
void signal ()
 
void broadcast ()
 

Detailed Description

Class wrapping around the pthreads condition. This class will provide a more object oriented implementation of a condition variable to achieve synchronization between threads.

Definition at line 88 of file xmipp_threads.h.

Constructor & Destructor Documentation

◆ Condition()

Condition::Condition ( )

Default constructor. This constructor just initialize the pthread_mutex_t structure with its defaults values, just like static initialization with PTHREAD_MUTEX_INITIALIZER

Definition at line 58 of file xmipp_threads.cpp.

59 {
60  mutex = new Mutex();
61  pthread_cond_init(&cond, NULL);
62 }
Mutex mutex

◆ ~Condition()

Condition::~Condition ( )

Destructor.

Definition at line 64 of file xmipp_threads.cpp.

65 {
66  delete mutex;
67  pthread_cond_destroy(&cond);
68 }
Mutex mutex

Member Function Documentation

◆ broadcast()

void Condition::broadcast ( )

Send the signal to all waiting threads.

Definition at line 90 of file xmipp_threads.cpp.

91 {
92  pthread_cond_broadcast(&cond);
93 }

◆ lock()

void Condition::lock ( )

Function to get the access to the mutex.

Definition at line 70 of file xmipp_threads.cpp.

71 {
72  mutex->lock();
73 }
Mutex mutex
virtual void lock()

◆ signal()

void Condition::signal ( )

Function to notify the condition was met. Thread that can be waiting in the condition will be awaked.

Definition at line 85 of file xmipp_threads.cpp.

86 {
87  pthread_cond_signal(&cond);
88 }

◆ unlock()

void Condition::unlock ( )

Function to release the mutex.

Definition at line 75 of file xmipp_threads.cpp.

76 {
77  mutex->unlock();
78 }
Mutex mutex
virtual void unlock()

◆ wait()

void Condition::wait ( )

Function to be call from a thread to wait on the condition. This function should be called after acquiring the Condition lock...after that, will block the threads until the condition be signaled.

Definition at line 80 of file xmipp_threads.cpp.

81 {
82  pthread_cond_wait(&cond, &(mutex->mutex));
83 }
Mutex mutex

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