Титульная страница | Пространства имен | Алфавитный указатель | Классы | Файлы | Члены пространства имен | Члены классов | Описания | Примеры

threads_1/h/threads.hpp

См. документацию.
00001 /* 00002 00003 threads_1: Multithreading support library 00004 Yauheni A. Akhotnikau (C) 2002-2003 00005 eao197@yahoo.com 00006 ------------------------------------------------- 00007 00008 Permission is granted to anyone to use this software for any purpose on any 00009 computer system, and to redistribute it freely, subject to the following 00010 restrictions: 00011 00012 1. This software is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00015 00016 2. The origin of this software must not be misrepresented, either by 00017 explicit claim or by omission. 00018 00019 3. Altered versions must be plainly marked as such, and must not be 00020 misrepresented as being the original software. 00021 00022 ------------------------------------------------- 00023 00024 */ 00025 /* 00026 Threads 1 00027 */ 00028 00034 #ifndef _THREADS_1__THREADS_HPP_ 00035 #define _THREADS_1__THREADS_HPP_ 00036 00037 #include <cpp_util_2/h/nocopy.hpp> 00038 00039 #include <threads_1/h/declspec.hpp> 00040 00041 namespace threads_1 00042 { 00043 00044 class _os_mutex_sem_t; 00045 class _os_cond_var_t; 00046 class _os_thread_t; 00047 class _os_thread_id_t; 00048 00049 // 00050 // mutex_sem_t 00051 // 00052 00058 class THREADS_1__TYPE mutex_sem_t : 00059 private cpp_util_2::nocopy_t 00060 { 00061 // Для реализации condition variable. 00062 friend class _os_cond_var_t; 00063 friend class cond_var_t; 00064 protected : 00066 _os_mutex_sem_t * m_sem; 00067 00068 public : 00069 mutex_sem_t(); 00070 ~mutex_sem_t(); 00071 00073 void 00074 lock() const; 00075 00077 void 00078 release() const; 00079 00081 00085 class THREADS_1__TYPE lock_t : 00086 private cpp_util_2::nocopy_t 00087 { 00088 // Для реализации condition variable. 00089 friend class _os_cond_var_t; 00090 private : 00091 const mutex_sem_t & m_sem; 00092 public : 00094 inline 00095 lock_t( const mutex_sem_t & sem ) 00096 : 00097 m_sem( sem ) 00098 { 00099 m_sem.lock(); 00100 } 00101 inline 00102 ~lock_t() 00103 { 00104 m_sem.release(); 00105 } 00106 }; 00107 }; 00108 00109 // 00110 // cond_var_t 00111 // 00112 00209 class THREADS_1__TYPE cond_var_t : 00210 public cpp_util_2::nocopy_t 00211 { 00212 protected : 00215 00220 mutex_sem_t * m_sem; 00221 _os_cond_var_t * m_cv; 00223 00224 bool m_is_own_mutex; 00225 00226 public : 00228 00233 cond_var_t(); 00236 00241 cond_var_t( 00244 mutex_sem_t * (*mutex_creator)() ); 00245 cond_var_t( 00248 mutex_sem_t & sem ); 00249 ~cond_var_t(); 00250 00252 00257 void 00258 wait() const; 00259 00261 00265 void 00266 wait( const mutex_sem_t & ) const; 00267 00271 00276 operator const mutex_sem_t &() const; 00277 00279 00283 void 00284 lock() const; 00285 00287 00291 void 00292 release() const; 00293 00296 00300 void 00301 notify_one(); 00302 00305 00309 void 00310 notify_all(); 00311 00313 00320 static mutex_sem_t * 00321 own_mutex(); 00322 }; 00323 00324 // 00325 // mrd_sem_t 00326 // 00327 00329 00351 class THREADS_1__TYPE mrd_sem_t : 00352 public cpp_util_2::nocopy_t 00353 { 00354 public : 00355 mrd_sem_t(); 00356 ~mrd_sem_t(); 00357 00359 void 00360 rd_lock(); 00361 00363 void 00364 wr_lock(); 00365 00367 void 00368 release(); 00369 00371 00375 class THREADS_1__TYPE rd_lock_t : 00376 private cpp_util_2::nocopy_t 00377 { 00378 private : 00379 mrd_sem_t & m_sem; 00380 public : 00382 inline 00383 rd_lock_t( mrd_sem_t & sem ) 00384 : 00385 m_sem( sem ) 00386 { 00387 m_sem.rd_lock(); 00388 } 00389 inline 00390 ~rd_lock_t() 00391 { 00392 m_sem.release(); 00393 } 00394 }; 00395 00397 00401 class THREADS_1__TYPE wr_lock_t : 00402 private cpp_util_2::nocopy_t 00403 { 00404 private : 00405 mrd_sem_t & m_sem; 00406 public : 00408 inline 00409 wr_lock_t( mrd_sem_t & sem ) 00410 : 00411 m_sem( sem ) 00412 { 00413 m_sem.wr_lock(); 00414 } 00415 inline 00416 ~wr_lock_t() 00417 { 00418 m_sem.release(); 00419 } 00420 }; 00421 00422 private : 00424 00426 mutex_sem_t m_lock; 00428 cond_var_t m_unlocked_event; 00429 00431 00433 unsigned long m_lock_count; 00436 00438 bool m_is_lock_enabled; 00439 }; 00440 00441 // 00442 // thread_t 00443 // 00444 00459 class THREADS_1__TYPE thread_t : 00460 private cpp_util_2::nocopy_t 00461 { 00462 friend class _os_thread_t; 00463 protected : 00465 _os_thread_t * m_t; 00466 00467 public : 00468 thread_t(); 00469 virtual ~thread_t(); 00470 00472 00476 void 00477 start(); 00478 00480 void 00481 wait(); 00482 00483 protected : 00486 00493 void 00494 sleep( unsigned long msec ); 00495 00497 virtual void 00498 body( void ) = 0; 00499 }; 00500 00503 00510 THREADS_1__FUNC(void) 00511 sleep_thread( unsigned long msec ); 00512 00513 // 00514 // osthread_id_t 00515 // 00516 00526 class THREADS_1__TYPE osthread_id_t 00527 { 00528 public : 00530 00533 osthread_id_t(); 00535 osthread_id_t( 00536 const osthread_id_t & o ); 00537 ~osthread_id_t(); 00538 00540 osthread_id_t & 00541 operator=( 00542 const osthread_id_t & o ); 00543 00545 bool 00546 operator==( const osthread_id_t & o ) const; 00547 00549 bool 00550 operator!=( const osthread_id_t & o ) const; 00551 00553 bool 00554 operator<( const osthread_id_t & o ) const; 00555 00556 private : 00557 _os_thread_id_t * m_id; 00558 }; 00559 00563 THREADS_1__FUNC(osthread_id_t) 00564 query_current_thread_id(); 00565 00570 typedef void (*pfn_thread_proc_t)( void * p_params ); 00571 00575 THREADS_1__FUNC(void) 00576 begin_thread( pfn_thread_proc_t proc, 00577 void * p_params ); 00578 00579 } /* namespace threads_1 */ 00580 00581 #endif

Документация по threads_1. Последние изменения: Wed Aug 4 06:46:01 2004. Создано системой doxygen 1.3.7
Hosted by uCoz