|
Last change
on this file since 3382 was 3208, checked in by ansari, 19 years ago |
|
Ajout classe ThSafeOp (thsafeop.h) pour rendre NDataBlock<T> (et SegDataBlock) thread-safe, ajout methode DataTypeInfo::getTypeId() , implementation ThSafeOp ds ndatablock.cc (.h), Reza 10/04/2007
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | #ifndef THSAFEOP_H_SEEN
|
|---|
| 2 | #define THSAFEOP_H_SEEN
|
|---|
| 3 |
|
|---|
| 4 | // Classe ThSafeOp : pour permettre l'execution d'operations atomiques en
|
|---|
| 5 | // multithread, lors de gestion de comptage de reference en particulier.
|
|---|
| 6 | //
|
|---|
| 7 | // R. Ansari UPS+LAL IN2P3/CNRS 2007
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 | #include "machdefs.h"
|
|---|
| 11 | #include "pexceptions.h"
|
|---|
| 12 |
|
|---|
| 13 | #ifndef SO_NOTHSAFE
|
|---|
| 14 | #include <pthread.h>
|
|---|
| 15 | #endif
|
|---|
| 16 |
|
|---|
| 17 | namespace SOPHYA {
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 | /*! \brief
|
|---|
| 21 | Auxiliary class for insuring thread safe operations in SOPHYA, for reference
|
|---|
| 22 | counting operations
|
|---|
| 23 | */
|
|---|
| 24 | class ThSafeOp {
|
|---|
| 25 | public:
|
|---|
| 26 | #if defined(SO_NOTHSAFE)
|
|---|
| 27 | explicit ThSafeOp() { }
|
|---|
| 28 | ~ThSafeOp() { }
|
|---|
| 29 | inline void lock() { return; }
|
|---|
| 30 | inline void unlock() { return; }
|
|---|
| 31 | #else
|
|---|
| 32 | explicit ThSafeOp()
|
|---|
| 33 | {
|
|---|
| 34 | int rc;
|
|---|
| 35 | rc = pthread_mutex_init(&_mutx, NULL);
|
|---|
| 36 | if (rc != 0) throw PException("ThSafeOp::ThSafeOp() / Error pthread_mutex_init");
|
|---|
| 37 | }
|
|---|
| 38 | ~ThSafeOp()
|
|---|
| 39 | {
|
|---|
| 40 | int rc;
|
|---|
| 41 | rc = pthread_mutex_destroy(&_mutx);
|
|---|
| 42 | if (rc != 0) throw PException("ThSafeOp::~ThSafeOp() / Error pthread_mutex_destroy");
|
|---|
| 43 | }
|
|---|
| 44 | //! Locks the mutex object
|
|---|
| 45 | inline void lock()
|
|---|
| 46 | { pthread_mutex_lock(&_mutx); }
|
|---|
| 47 | //! Unlocks the mutex object
|
|---|
| 48 | inline void unlock()
|
|---|
| 49 | { pthread_mutex_unlock(&_mutx); }
|
|---|
| 50 | protected:
|
|---|
| 51 | pthread_mutex_t _mutx;
|
|---|
| 52 | #endif
|
|---|
| 53 | };
|
|---|
| 54 | } // namespace SOPHYA
|
|---|
| 55 |
|
|---|
| 56 | #endif
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.