Changeset 2164
- Timestamp:
- 06/12/12 06:11:28 (9 years ago)
- Files:
-
- trunk/libffado/src/libieee1394/ieee1394service.cpp (modified) (1 diff)
- trunk/libffado/src/libutil/PosixThread.cpp (modified) (4 diffs)
- trunk/libffado/src/libutil/PosixThread.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libffado/src/libieee1394/ieee1394service.cpp
r2162 r2164 403 403 return false; 404 404 } 405 406 // Give time for all threads to start. Otherwise it can happen that407 // some FFADO threads are ready to run before others. If the former408 // then go ahead and use the latter on the assumption that they're409 // running, race conditions can occur. The delay here has been410 // determined experimentally.411 usleep(500);412 405 413 406 // make sure that the thread parameters of all our helper threads are OK trunk/libffado/src/libutil/PosixThread.cpp
r1971 r2164 67 67 obj->m_lock.Lock(); 68 68 69 // Signal that ThreadHandler has acquired its initial lock 70 pthread_mutex_lock(&obj->handler_active_lock); 71 obj->handler_active = 1; 72 pthread_cond_signal(&obj->handler_active_cond); 73 pthread_mutex_unlock(&obj->handler_active_lock); 74 69 75 if ((err = pthread_setcanceltype(obj->fCancellation, NULL)) != 0) { 70 76 debugError("pthread_setcanceltype err = %s\n", strerror(err)); … … 74 80 if (!runnable->Init()) { 75 81 debugError("Thread init fails: thread quits\n"); 82 obj->m_lock.Unlock(); 76 83 return 0; 77 84 } … … 156 163 return -1; 157 164 } 158 159 return 0;160 165 } else { 161 166 debugOutput( DEBUG_LEVEL_VERBOSE, "(%s) Create non RT thread %p\n", m_id.c_str(), this); … … 168 173 return -1; 169 174 } 170 171 return 0; 172 } 175 } 176 177 // Wait for ThreadHandler() to acquire the thread lock (m_lock) before 178 // continuing, thereby ensuring that ThreadHandler() acquires a lock on 179 // m_lock before anything else tries. 180 pthread_mutex_lock(&handler_active_lock); 181 while (handler_active == 0) 182 pthread_cond_wait(&handler_active_cond, &handler_active_lock); 183 pthread_mutex_unlock(&handler_active_lock); 184 185 return 0; 173 186 } 174 187 trunk/libffado/src/libutil/PosixThread.h
r1550 r2164 74 74 int fCancellation; 75 75 76 pthread_mutex_t handler_active_lock; 77 pthread_cond_t handler_active_cond; 78 int handler_active; 79 76 80 static void* ThreadHandler(void* arg); 77 81 Util::Mutex &m_lock; … … 80 84 PosixThread(RunnableInterface* runnable, bool real_time, int priority, int cancellation) 81 85 : Thread(runnable), fThread((pthread_t)NULL), fPriority(priority), fRealTime(real_time), fRunning(false), fCancellation(cancellation) 86 , handler_active(0) 82 87 , m_lock(*(new Util::PosixMutex("THREAD"))) 83 {} 88 { pthread_mutex_init(&handler_active_lock, NULL); 89 pthread_cond_init(&handler_active_cond, NULL); 90 } 84 91 PosixThread(RunnableInterface* runnable) 85 92 : Thread(runnable), fThread((pthread_t)NULL), fPriority(0), fRealTime(false), fRunning(false), fCancellation(PTHREAD_CANCEL_DEFERRED) 93 , handler_active(0) 86 94 , m_lock(*(new Util::PosixMutex("THREAD"))) 87 {} 95 { pthread_mutex_init(&handler_active_lock, NULL); 96 pthread_cond_init(&handler_active_cond, NULL); 97 } 88 98 PosixThread(RunnableInterface* runnable, int cancellation) 89 99 : Thread(runnable), fThread((pthread_t)NULL), fPriority(0), fRealTime(false), fRunning(false), fCancellation(cancellation) 100 , handler_active(0) 90 101 , m_lock(*(new Util::PosixMutex("THREAD"))) 91 {} 102 { pthread_mutex_init(&handler_active_lock, NULL); 103 pthread_cond_init(&handler_active_cond, NULL); 104 } 92 105 93 106 PosixThread(RunnableInterface* runnable, std::string id, bool real_time, int priority, int cancellation) 94 107 : Thread(runnable, id), fThread((pthread_t)NULL), fPriority(priority), fRealTime(real_time), fRunning(false), fCancellation(cancellation) 108 , handler_active(0) 95 109 , m_lock(*(new Util::PosixMutex(id))) 96 {} 110 { pthread_mutex_init(&handler_active_lock, NULL); 111 pthread_cond_init(&handler_active_cond, NULL); 112 } 97 113 PosixThread(RunnableInterface* runnable, std::string id) 98 114 : Thread(runnable, id), fThread((pthread_t)NULL), fPriority(0), fRealTime(false), fRunning(false), fCancellation(PTHREAD_CANCEL_DEFERRED) 115 , handler_active(0) 99 116 , m_lock(*(new Util::PosixMutex(id))) 100 {} 117 { pthread_mutex_init(&handler_active_lock, NULL); 118 pthread_cond_init(&handler_active_cond, NULL); 119 } 101 120 PosixThread(RunnableInterface* runnable, std::string id, int cancellation) 102 121 : Thread(runnable, id), fThread((pthread_t)NULL), fPriority(0), fRealTime(false), fRunning(false), fCancellation(cancellation) 122 , handler_active(0) 103 123 , m_lock(*(new Util::PosixMutex(id))) 104 {} 124 { pthread_mutex_init(&handler_active_lock, NULL); 125 pthread_cond_init(&handler_active_cond, NULL); 126 } 105 127 106 128 virtual ~PosixThread() 107 { delete &m_lock; } 129 { delete &m_lock; 130 pthread_mutex_destroy(&handler_active_lock); 131 pthread_cond_destroy(&handler_active_cond); 132 } 108 133 109 134 virtual int Start();