@@ -104,13 +104,17 @@ namespace Gecode { namespace Support {
104104 */
105105 class Mutex {
106106 private:
107- #ifdef GECODE_THREADS_WINDOWS
107+ #if defined( GECODE_THREADS_WINDOWS)
108108 // / Use a simple but more efficient critical section on Windows
109109 CRITICAL_SECTION w_cs;
110- #endif
111- #ifdef GECODE_THREADS_PTHREADS
110+ #elif defined(GECODE_THREADS_OSX_UNFAIR)
111+ // / Use unfair lock on macOS
112+ os_unfair_lock lck;
113+ #elif defined(GECODE_THREADS_PTHREADS)
112114 // / The Pthread mutex
113115 pthread_mutex_t p_m;
116+ #else
117+ #error No suitable mutex implementation found
114118#endif
115119 public:
116120 // / Initialize mutex
@@ -134,15 +138,11 @@ namespace Gecode { namespace Support {
134138 void operator =(const Mutex&) {}
135139 };
136140
137- #if defined(GECODE_THREADS_WINDOWS) || !defined(GECODE_THREADS_PTHREADS)
141+ #ifndef GECODE_THREADS_PTHREADS_SPINLOCK
138142
139143 typedef Mutex FastMutex;
140144
141- #endif
142-
143- #ifdef GECODE_THREADS_PTHREADS
144-
145- #if defined(GECODE_THREADS_OSX) || defined(GECODE_THREADS_OSX_UNFAIR) || defined(GECODE_THREADS_PTHREADS_SPINLOCK)
145+ #else
146146
147147 /* *
148148 * \brief A fast mutex for mutual exclausion among several threads
@@ -160,16 +160,8 @@ namespace Gecode { namespace Support {
160160 */
161161 class FastMutex {
162162 private:
163- #ifdef GECODE_THREADS_OSX
164- // / The OSX spin lock
165- OSSpinLock lck;
166- #elif defined(GECODE_THREADS_OSX_UNFAIR)
167- // / The OSX spin lock
168- os_unfair_lock lck;
169- #else
170163 // / The Pthread spinlock
171164 pthread_spinlock_t p_s;
172- #endif
173165 public:
174166 // / Initialize mutex
175167 FastMutex (void );
@@ -192,12 +184,6 @@ namespace Gecode { namespace Support {
192184 void operator =(const FastMutex&) {}
193185 };
194186
195- #else
196-
197- typedef Mutex FastMutex;
198-
199- #endif
200-
201187#endif
202188
203189 /* *
@@ -259,6 +245,20 @@ namespace Gecode { namespace Support {
259245 void operator =(const Event&) {}
260246 };
261247
248+ /* *
249+ * \brief An interface for objects that can be called after a
250+ * thread has terminated (after running the thread's destructor)
251+ *
252+ * \ingroup FuncSupportThread
253+ */
254+ class Terminator {
255+ public:
256+ // / Destructor
257+ virtual ~Terminator () {}
258+ // / The function that is called when the thread has terminated
259+ virtual void terminated (void ) = 0;
260+ };
261+
262262 /* *
263263 * \brief An interface for objects that can be run by a thread
264264 *
@@ -275,6 +275,8 @@ namespace Gecode { namespace Support {
275275 void todelete (bool d);
276276 // / Return whether to be deleted upon termination
277277 bool todelete (void ) const ;
278+ // / Return terminator object
279+ virtual Terminator* terminator (void ) const { return NULL ; }
278280 // / The function that is executed when the thread starts
279281 virtual void run (void ) = 0;
280282 // / Destructor
0 commit comments