Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2805
Modified Files: Tag: devel_0_38 m_sched.c Log Message: rewrote sys_timedlock to work on osx, too
Index: m_sched.c =================================================================== RCS file: /cvsroot/pure-data/pd/src/m_sched.c,v retrieving revision 1.5.4.33 retrieving revision 1.5.4.34 diff -C2 -d -r1.5.4.33 -r1.5.4.34 *** m_sched.c 15 May 2005 18:51:15 -0000 1.5.4.33 --- m_sched.c 15 May 2005 21:10:12 -0000 1.5.4.34 *************** *** 545,548 **** --- 545,549 ---- #ifdef THREAD_LOCKING static pthread_mutex_t sys_mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_cond_t sys_cond = PTHREAD_COND_INITIALIZER;
void sys_lock(void) *************** *** 554,557 **** --- 555,559 ---- { pthread_mutex_unlock(&sys_mutex); + pthread_cond_signal(&sys_cond); }
*************** *** 577,580 **** --- 579,616 ---- #endif
+ + #if 0 + /* osx doesn't define a pthread_mutex_timedlock ... maybe someday + it will ... */ + int sys_timedlock(int microsec) + { + struct timespec timeout; + int ret; + struct timeval now; + + /* timedlock seems to have a resolution of 1ms */ + if (microsec < 1e3) + microsec = 1e3; + + gettimeofday(&now,0); + + timeout.tv_sec = now.tv_sec; + timeout.tv_nsec = (now.tv_usec + microsec) * 1000; + + while (timeout.tv_nsec > 1e9) + { + timeout.tv_sec += 1; + timeout.tv_nsec -= 1e9; + } + + ret = pthread_mutex_timedlock(&sys_mutex, &timeout); + + if (ret) + post("timeout, %d", ret); + + return ret; + } + #else + int sys_timedlock(int microsec) { *************** *** 582,592 **** int ret; struct timeval now; ! ! /* timedlock seems to have a resolution of 1ms */ if (microsec < 1e3) microsec = 1e3; - gettimeofday(&now,0); - timeout.tv_sec = now.tv_sec; timeout.tv_nsec = (now.tv_usec + microsec) * 1000; --- 618,630 ---- int ret; struct timeval now; ! ! if (sys_trylock() == 0) ! return 0; ! if (microsec < 1e3) microsec = 1e3; + + gettimeofday(&now,0); timeout.tv_sec = now.tv_sec; timeout.tv_nsec = (now.tv_usec + microsec) * 1000; *************** *** 597,608 **** timeout.tv_nsec -= 1e9; } - - ret = pthread_mutex_timedlock(&sys_mutex, &timeout);
! if (ret) ! post("timeout"); return ret; } /* tb } */
--- 635,650 ---- timeout.tv_nsec -= 1e9; }
! ! /* in case the lock has been released during the system call, try ! again before waiting for the signal */ ! if (sys_trylock() == 0) ! return 0; ! ! ret = pthread_cond_timedwait(&sys_cond, &sys_mutex, &timeout); return ret; } + #endif /* tb } */