Magick++ 6.9.13
Loading...
Searching...
No Matches
Magick::MutexLock Class Reference
Collaboration diagram for Magick::MutexLock:

Public Member Functions

void lock (void)
 
void unlock (void)
 

Private Member Functions

 MutexLock (const MutexLock &original_)
 
MutexLockoperator= (const MutexLock &original_)
 

Detailed Description

Definition at line 34 of file Thread.h.

Constructor & Destructor Documentation

◆ MutexLock()

Magick::MutexLock::MutexLock ( void )

Definition at line 18 of file Thread.cpp.

21 : _mutex()
22{
23 ::pthread_mutexattr_t attr;
24 int sysError;
25 if ( (sysError = ::pthread_mutexattr_init( &attr )) == 0 )
26 if ( (sysError = ::pthread_mutex_init( &_mutex, &attr )) == 0 )
27 {
28 ::pthread_mutexattr_destroy( &attr );
29 return;
30 }
31 throwExceptionExplicit( OptionError, "mutex initialization failed",
32 strerror(sysError) );
33}
34#else
35#if defined(_VISUALC_) && defined(_MT)
36// Win32 threads
37 : _mutex()
38{
39 SECURITY_ATTRIBUTES security;
40
41 /* Allow the semaphore to be inherited */
42 security.nLength = sizeof(security);
43 security.lpSecurityDescriptor = NULL;
44 security.bInheritHandle = TRUE;
45
46 /* Create the semaphore, with initial value signaled */
47 _mutex.id = ::CreateSemaphore(&security, 1, MAXSEMLEN, NULL);
48 if ( _mutex.id != NULL )
49 return;
50 throwExceptionExplicit( OptionError, "mutex initialization failed" );
51}
52#else
53// Threads not supported
54{
55}

◆ ~MutexLock()

Magick::MutexLock::~MutexLock ( void )

Definition at line 60 of file Thread.cpp.

61{
62#if defined(MAGICKCORE_HAVE_PTHREAD)
63 (void) ::pthread_mutex_destroy(&_mutex);
64#endif
65#if defined(_MT) && defined(_VISUALC_)
66 (void) ::CloseHandle(_mutex.id);
67#endif
68}

Member Function Documentation

◆ lock()

void Magick::MutexLock::lock ( void )

Definition at line 71 of file Thread.cpp.

72{
73#if defined(MAGICKCORE_HAVE_PTHREAD)
74 int sysError;
75 if ( (sysError = ::pthread_mutex_lock( &_mutex )) == 0)
76 return;
77 throwExceptionExplicit( OptionError, "mutex lock failed",
78 strerror(sysError));
79#endif
80#if defined(_MT) && defined(_VISUALC_)
81 if (WaitForSingleObject(_mutex.id,INFINITE) != WAIT_FAILED)
82 return;
83 throwExceptionExplicit( OptionError, "mutex lock failed" );
84#endif
85}

◆ unlock()

void Magick::MutexLock::unlock ( void )

Definition at line 88 of file Thread.cpp.

89{
90#if defined(MAGICKCORE_HAVE_PTHREAD)
91 int sysError;
92 if ( (sysError = ::pthread_mutex_unlock( &_mutex )) == 0)
93 return;
94 throwExceptionExplicit( OptionError, "mutex unlock failed",
95 strerror(sysError) );
96#endif
97#if defined(_MT) && defined(_VISUALC_)
98 if ( ReleaseSemaphore(_mutex.id, 1, NULL) == TRUE )
99 return;
100 throwExceptionExplicit( OptionError, "mutex unlock failed" );
101#endif
102}

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