- Timestamp:
- Jul 20, 2006, 3:48:54 PM (18 years ago)
- Location:
- branches/proxy/src/lib/util/sigslot
- Files:
-
- 1 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/proxy/src/lib/util/sigslot/signal.h
r9358 r9359 102 102 #endif 103 103 104 #include "slot.h" 105 104 106 105 107 namespace sigslot 106 108 { 107 109 108 class single_threaded109 {110 public:111 single_threaded()112 {113 ;114 }115 116 virtual ~single_threaded()117 {118 ;119 }120 121 virtual void lock()122 {123 ;124 }125 126 virtual void unlock()127 {128 ;129 }130 };131 132 #ifdef _SIGSLOT_HAS_WIN32_THREADS133 // The multi threading policies only get compiled in if they are enabled.134 class multi_threaded_global135 {136 public:137 multi_threaded_global()138 {139 static bool isinitialised = false;140 141 if(!isinitialised)142 {143 InitializeCriticalSection(get_critsec());144 isinitialised = true;145 }146 }147 148 multi_threaded_global(const multi_threaded_global&)149 {150 ;151 }152 153 virtual ~multi_threaded_global()154 {155 ;156 }157 158 virtual void lock()159 {160 EnterCriticalSection(get_critsec());161 }162 163 virtual void unlock()164 {165 LeaveCriticalSection(get_critsec());166 }167 168 private:169 CRITICAL_SECTION* get_critsec()170 {171 static CRITICAL_SECTION g_critsec;172 return &g_critsec;173 }174 };175 176 class multi_threaded_local177 {178 public:179 multi_threaded_local()180 {181 InitializeCriticalSection(&m_critsec);182 }183 184 multi_threaded_local(const multi_threaded_local&)185 {186 InitializeCriticalSection(&m_critsec);187 }188 189 virtual ~multi_threaded_local()190 {191 DeleteCriticalSection(&m_critsec);192 }193 194 virtual void lock()195 {196 EnterCriticalSection(&m_critsec);197 }198 199 virtual void unlock()200 {201 LeaveCriticalSection(&m_critsec);202 }203 204 private:205 CRITICAL_SECTION m_critsec;206 };207 #endif // _SIGSLOT_HAS_WIN32_THREADS208 209 #ifdef _SIGSLOT_HAS_POSIX_THREADS210 // The multi threading policies only get compiled in if they are enabled.211 class multi_threaded_global212 {213 public:214 multi_threaded_global()215 {216 pthread_mutex_init(get_mutex(), NULL);217 }218 219 multi_threaded_global(const multi_threaded_global&)220 {221 ;222 }223 224 virtual ~multi_threaded_global()225 {226 ;227 }228 229 virtual void lock()230 {231 pthread_mutex_lock(get_mutex());232 }233 234 virtual void unlock()235 {236 pthread_mutex_unlock(get_mutex());237 }238 239 private:240 pthread_mutex_t* get_mutex()241 {242 static pthread_mutex_t g_mutex;243 return &g_mutex;244 }245 };246 247 class multi_threaded_local248 {249 public:250 multi_threaded_local()251 {252 pthread_mutex_init(&m_mutex, NULL);253 }254 255 multi_threaded_local(const multi_threaded_local&)256 {257 pthread_mutex_init(&m_mutex, NULL);258 }259 260 virtual ~multi_threaded_local()261 {262 pthread_mutex_destroy(&m_mutex);263 }264 265 virtual void lock()266 {267 pthread_mutex_lock(&m_mutex);268 }269 270 virtual void unlock()271 {272 pthread_mutex_unlock(&m_mutex);273 }274 275 private:276 pthread_mutex_t m_mutex;277 };278 #endif // _SIGSLOT_HAS_POSIX_THREADS279 280 template<class mt_policy>281 class lock_block282 {283 public:284 mt_policy *m_mutex;285 286 lock_block(mt_policy *mtx)287 : m_mutex(mtx)288 {289 m_mutex->lock();290 }291 292 ~lock_block()293 {294 m_mutex->unlock();295 }296 };297 298 template<class mt_policy>299 class has_slots;300 110 301 111 template<class mt_policy> … … 406 216 407 217 template<class mt_policy> 408 class _signal_base : public mt_policy409 {410 public:411 virtual void slot_disconnect(has_slots<mt_policy>* pslot) = 0;412 virtual void slot_duplicate(const has_slots<mt_policy>* poldslot, has_slots<mt_policy>* pnewslot) = 0;413 };414 415 template<class mt_policy = SIGSLOT_DEFAULT_MT_POLICY>416 class has_slots : public mt_policy417 {418 private:419 typedef std::set<_signal_base<mt_policy> *> sender_set;420 typedef typename sender_set::const_iterator const_iterator;421 422 public:423 has_slots()424 {425 ;426 }427 428 has_slots(const has_slots& hs)429 : mt_policy(hs)430 {431 lock_block<mt_policy> lock(this);432 const_iterator it = hs.m_senders.begin();433 const_iterator itEnd = hs.m_senders.end();434 435 while(it != itEnd)436 {437 (*it)->slot_duplicate(&hs, this);438 m_senders.insert(*it);439 ++it;440 }441 }442 443 void signal_connect(_signal_base<mt_policy>* sender)444 {445 lock_block<mt_policy> lock(this);446 m_senders.insert(sender);447 }448 449 void signal_disconnect(_signal_base<mt_policy>* sender)450 {451 lock_block<mt_policy> lock(this);452 m_senders.erase(sender);453 }454 455 virtual ~has_slots()456 {457 disconnect_all();458 }459 460 void disconnect_all()461 {462 lock_block<mt_policy> lock(this);463 const_iterator it = m_senders.begin();464 const_iterator itEnd = m_senders.end();465 466 while(it != itEnd)467 {468 (*it)->slot_disconnect(this);469 ++it;470 }471 472 m_senders.erase(m_senders.begin(), m_senders.end());473 }474 475 private:476 sender_set m_senders;477 };478 479 template<class mt_policy>480 218 class _signal_base0 : public _signal_base<mt_policy> 481 219 {
Note: See TracChangeset
for help on using the changeset viewer.