Changeset 15 in flair-src for trunk/lib/FlairCore/src/Mutex_impl.cpp
- Timestamp:
- 04/08/16 15:40:57 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/Mutex_impl.cpp
r2 r15 23 23 using namespace flair::core; 24 24 25 Mutex_impl::Mutex_impl(Mutex *self) 26 { 27 this->self=self; 25 Mutex_impl::Mutex_impl(Mutex *self) { 26 this->self = self; 28 27 #ifdef __XENO__ 29 int status=rt_mutex_create(&mutex,NULL); 30 if(status!=0) self->Err("rt_mutex_create error (%s)\n",strerror(-status)); 28 int status = rt_mutex_create(&mutex, NULL); 29 if (status != 0) 30 self->Err("rt_mutex_create error (%s)\n", strerror(-status)); 31 31 #else 32 //flag_locked=false;//revoir l'implementation nrt du is_locked 33 pthread_mutexattr_t attr; 34 if(pthread_mutexattr_init(&attr)!=0) 35 { 36 self->Err("pthread_mutexattr_init error\n"); 37 } 38 if(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) 39 { 40 self->Err("pthread_mutexattr_settype error\n"); 41 } 42 if(pthread_mutex_init(&mutex, &attr)!=0) 43 { 44 self->Err("pthread_mutex_init error\n"); 45 } 46 if(pthread_mutexattr_destroy(&attr)!=0) 47 { 48 self->Err("pthread_mutexattr_destroy error\n"); 49 } 32 // flag_locked=false;//revoir l'implementation nrt du is_locked 33 pthread_mutexattr_t attr; 34 if (pthread_mutexattr_init(&attr) != 0) { 35 self->Err("pthread_mutexattr_init error\n"); 36 } 37 if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) { 38 self->Err("pthread_mutexattr_settype error\n"); 39 } 40 if (pthread_mutex_init(&mutex, &attr) != 0) { 41 self->Err("pthread_mutex_init error\n"); 42 } 43 if (pthread_mutexattr_destroy(&attr) != 0) { 44 self->Err("pthread_mutexattr_destroy error\n"); 45 } 50 46 #endif 51 47 } 52 48 53 Mutex_impl::~Mutex_impl() 54 { 55 int status; 49 Mutex_impl::~Mutex_impl() { 50 int status; 56 51 #ifdef __XENO__ 57 status=rt_mutex_delete(&mutex);52 status = rt_mutex_delete(&mutex); 58 53 #else 59 status=pthread_mutex_destroy(&mutex);54 status = pthread_mutex_destroy(&mutex); 60 55 #endif 61 if(status!=0) self->Err("error destroying mutex (%s)\n",strerror(-status)); 56 if (status != 0) 57 self->Err("error destroying mutex (%s)\n", strerror(-status)); 62 58 } 63 59 64 void Mutex_impl::GetMutex(void) 65 { 66 int status; 60 void Mutex_impl::GetMutex(void) { 61 int status; 67 62 #ifdef __XENO__ 68 status=rt_mutex_acquire(&mutex,TM_INFINITE);63 status = rt_mutex_acquire(&mutex, TM_INFINITE); 69 64 #else 70 //flag_locked=true;71 status=pthread_mutex_lock(&mutex);65 // flag_locked=true; 66 status = pthread_mutex_lock(&mutex); 72 67 #endif 73 if(status!=0) self->Err("error (%s)\n",strerror(-status)); 68 if (status != 0) 69 self->Err("error (%s)\n", strerror(-status)); 74 70 } 75 71 76 void Mutex_impl::ReleaseMutex(void) 77 { 78 int status; 72 void Mutex_impl::ReleaseMutex(void) { 73 int status; 79 74 #ifdef __XENO__ 80 status=rt_mutex_release(&mutex);75 status = rt_mutex_release(&mutex); 81 76 #else 82 status=pthread_mutex_unlock(&mutex);83 //flag_locked=false;77 status = pthread_mutex_unlock(&mutex); 78 // flag_locked=false; 84 79 #endif 85 if(status!=0) self->Err("error (%s)\n",strerror(-status)); 80 if (status != 0) 81 self->Err("error (%s)\n", strerror(-status)); 86 82 } 87 83 … … 92 88 RT_MUTEX_INFO info; 93 89 int status=rt_mutex_inquire(&mutex_rt,&info); 94 if(status!=0) mutex->Err("erreur rt_mutex_inquire (%s)\n",strerror(-status)); 90 if(status!=0) mutex->Err("erreur rt_mutex_inquire 91 (%s)\n",strerror(-status)); 95 92 if(info.locked>0) return true; 96 93 return false;
Note:
See TracChangeset
for help on using the changeset viewer.