24 |
24 |
25 |
25 |
26 #ifndef _STLP_INTERNAL_THREADS_H |
26 #ifndef _STLP_INTERNAL_THREADS_H |
27 #define _STLP_INTERNAL_THREADS_H |
27 #define _STLP_INTERNAL_THREADS_H |
28 |
28 |
|
29 |
|
30 #ifdef __SYMBIAN32__ |
|
31 #include <e32atomics.h> // For atomic increment and decrement |
|
32 #endif |
|
33 |
|
34 |
29 // Supported threading models are native SGI, pthreads, uithreads |
35 // Supported threading models are native SGI, pthreads, uithreads |
30 // (similar to pthreads, but based on an earlier draft of the Posix |
36 // (similar to pthreads, but based on an earlier draft of the Posix |
31 // threads standard), and Win32 threads. Uithread support by Jochen |
37 // threads standard), and Win32 threads. Uithread support by Jochen |
32 // Schlick, 1999, and Solaris threads generalized to them. |
38 // Schlick, 1999, and Solaris threads generalized to them. |
33 |
39 |
462 class _STLP_CLASS_DECLSPEC _Refcount_Base { |
468 class _STLP_CLASS_DECLSPEC _Refcount_Base { |
463 // The data member _M_ref_count |
469 // The data member _M_ref_count |
464 #if defined (__DMC__) |
470 #if defined (__DMC__) |
465 public: |
471 public: |
466 #endif |
472 #endif |
467 _STLP_VOLATILE __stl_atomic_t _M_ref_count; |
473 _STLP_VOLATILE __stl_atomic_t _M_ref_count; |
468 |
474 |
469 #if defined (_STLP_THREADS) && \ |
475 #if defined (_STLP_THREADS) && \ |
470 (!defined (_STLP_ATOMIC_INCREMENT) || !defined (_STLP_ATOMIC_DECREMENT) || \ |
476 (!defined (_STLP_ATOMIC_INCREMENT) || !defined (_STLP_ATOMIC_DECREMENT) || \ |
471 (defined (_STLP_WIN32_VERSION) && (_STLP_WIN32_VERSION <= 0x0400))) |
477 (defined (_STLP_WIN32_VERSION) && (_STLP_WIN32_VERSION <= 0x0400))) |
472 # define _STLP_USE_MUTEX |
478 # define _STLP_USE_MUTEX |
473 _STLP_mutex _M_mutex; |
479 #ifndef __SYMBIAN32__ |
|
480 _STLP_mutex _M_mutex; |
|
481 #else |
|
482 #define KSizeofStlpMutex 12 |
|
483 /* |
|
484 * Padding in order to ensure compatability. |
|
485 * The pad size is the size of the _STLP_mutex structure |
|
486 */ |
|
487 char _pad[KSizeofStlpMutex]; |
|
488 #endif |
474 #endif |
489 #endif |
475 |
490 |
476 public: |
491 public: |
477 // Constructor |
492 // Constructor |
478 _Refcount_Base(__stl_atomic_t __n) : _M_ref_count(__n) {} |
493 _Refcount_Base(__stl_atomic_t __n) : _M_ref_count(__n) {} |
482 # if !defined (_STLP_USE_MUTEX) |
497 # if !defined (_STLP_USE_MUTEX) |
483 __stl_atomic_t _M_incr() { return _STLP_ATOMIC_INCREMENT(&_M_ref_count); } |
498 __stl_atomic_t _M_incr() { return _STLP_ATOMIC_INCREMENT(&_M_ref_count); } |
484 __stl_atomic_t _M_decr() { return _STLP_ATOMIC_DECREMENT(&_M_ref_count); } |
499 __stl_atomic_t _M_decr() { return _STLP_ATOMIC_DECREMENT(&_M_ref_count); } |
485 # else |
500 # else |
486 # undef _STLP_USE_MUTEX |
501 # undef _STLP_USE_MUTEX |
487 __stl_atomic_t _M_incr() { |
502 #ifndef __SYMBIAN32__ |
488 _STLP_auto_lock l(_M_mutex); |
503 __stl_atomic_t _M_incr() { |
489 return ++_M_ref_count; |
504 _STLP_auto_lock l(_M_mutex); |
490 } |
505 return ++_M_ref_count; |
491 __stl_atomic_t _M_decr() { |
506 } |
492 _STLP_auto_lock l(_M_mutex); |
507 __stl_atomic_t _M_decr() { |
493 return --_M_ref_count; |
508 _STLP_auto_lock l(_M_mutex); |
494 } |
509 return --_M_ref_count; |
|
510 } |
|
511 #else |
|
512 __stl_atomic_t _M_incr() { |
|
513 __e32_atomic_tas_ord32(&_M_ref_count, 0, 1, 1); |
|
514 return _M_ref_count; |
|
515 } |
|
516 __stl_atomic_t _M_decr() { |
|
517 __e32_atomic_tas_ord32(&_M_ref_count, 1, -1, 0); |
|
518 return _M_ref_count; |
|
519 } |
|
520 #endif |
495 # endif |
521 # endif |
496 #else /* No threads */ |
522 #else /* No threads */ |
497 __stl_atomic_t _M_incr() { return ++_M_ref_count; } |
523 __stl_atomic_t _M_incr() { return ++_M_ref_count; } |
498 __stl_atomic_t _M_decr() { return --_M_ref_count; } |
524 __stl_atomic_t _M_decr() { return --_M_ref_count; } |
499 #endif |
525 #endif |