Magick++ 7.1.1
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 29 of file Thread.h.

Constructor & Destructor Documentation

◆ MutexLock()

Magick::MutexLock::MutexLock ( void  )

Definition at line 20 of file Thread.cpp.

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

◆ ~MutexLock()

Magick::MutexLock::~MutexLock ( void  )

Definition at line 67 of file Thread.cpp.

68{
69#if defined(MAGICKCORE_HAVE_PTHREAD)
70 (void) ::pthread_mutex_destroy(&_mutex);
71#endif
72#if defined(_MT) && defined(_VISUALC_)
73 (void) ::CloseHandle(_mutex);
74#endif
75}

Member Function Documentation

◆ lock()

void Magick::MutexLock::lock ( void  )

Definition at line 78 of file Thread.cpp.

79{
80#if defined(MAGICKCORE_HAVE_PTHREAD)
81 int
82 sysError;
83
84 if ((sysError=::pthread_mutex_lock(&_mutex)) == 0)
85 return;
86 throwExceptionExplicit(MagickCore::OptionError,"mutex lock failed",
87 strerror(sysError));
88#endif
89#if defined(_MT) && defined(_VISUALC_)
90 if (WaitForSingleObject(_mutex,INFINITE) != WAIT_FAILED)
91 return;
92 throwExceptionExplicit(MagickCore::OptionError,"mutex lock failed");
93#endif
94}

◆ unlock()

void Magick::MutexLock::unlock ( void  )

Definition at line 97 of file Thread.cpp.

98{
99#if defined(MAGICKCORE_HAVE_PTHREAD)
100 int
101 sysError;
102
103 if ((sysError=::pthread_mutex_unlock(&_mutex)) == 0)
104 return;
105 throwExceptionExplicit(MagickCore::OptionError,"mutex unlock failed",
106 strerror(sysError));
107#endif
108#if defined(_MT) && defined(_VISUALC_)
109 if (ReleaseSemaphore(_mutex,1,(LPLONG) NULL) == TRUE)
110 return;
111 throwExceptionExplicit(MagickCore::OptionError,"mutex unlock failed");
112#endif
113}

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