git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@3716 0c269be4-1314-0410-8aa9-9f06e86f4224tags/v1.9.4
| @@ -25,6 +25,10 @@ Paul Davis | |||
| Jackdmp changes log | |||
| --------------------------- | |||
| 2009-11-07 Stephane Letz <letz@grame.fr> | |||
| * Fix AcquireRealTime and DropRealTime: now distinguish when called from another thread (AcquireRealTime/DropRealTime) and from the thread itself (AcquireSelfRealTime/DropSelfRealTime). | |||
| 2009-11-06 Stephane Letz <letz@grame.fr> | |||
| * Correctly save and restore RT mode state in freewheel mode. | |||
| @@ -170,47 +170,54 @@ int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync, | |||
| case kAddClient: | |||
| jack_log("JackClient::kAddClient fName = %s name = %s", GetClientControl()->fName, name); | |||
| if (fClientRegistration && strcmp(GetClientControl()->fName, name) != 0) // Don't call the callback for the registering client itself | |||
| if (fClientRegistration && strcmp(GetClientControl()->fName, name) != 0) { // Don't call the callback for the registering client itself | |||
| fClientRegistration(name, 1, fClientRegistrationArg); | |||
| } | |||
| break; | |||
| case kRemoveClient: | |||
| jack_log("JackClient::kRemoveClient fName = %s name = %s", GetClientControl()->fName, name); | |||
| if (fClientRegistration && strcmp(GetClientControl()->fName, name) != 0) // Don't call the callback for the registering client itself | |||
| if (fClientRegistration && strcmp(GetClientControl()->fName, name) != 0) { // Don't call the callback for the registering client itself | |||
| fClientRegistration(name, 0, fClientRegistrationArg); | |||
| } | |||
| break; | |||
| case kBufferSizeCallback: | |||
| jack_log("JackClient::kBufferSizeCallback buffer_size = %ld", value1); | |||
| if (fBufferSize) | |||
| if (fBufferSize) { | |||
| res = fBufferSize(value1, fBufferSizeArg); | |||
| } | |||
| break; | |||
| case kSampleRateCallback: | |||
| jack_log("JackClient::kSampleRateCallback sample_rate = %ld", value1); | |||
| if (fSampleRate) | |||
| if (fSampleRate) { | |||
| res = fSampleRate(value1, fSampleRateArg); | |||
| } | |||
| break; | |||
| case kGraphOrderCallback: | |||
| jack_log("JackClient::kGraphOrderCallback"); | |||
| if (fGraphOrder) | |||
| if (fGraphOrder) { | |||
| res = fGraphOrder(fGraphOrderArg); | |||
| } | |||
| break; | |||
| case kStartFreewheelCallback: | |||
| jack_log("JackClient::kStartFreewheel"); | |||
| SetupDriverSync(true); | |||
| fThread.DropRealTime(); | |||
| if (fFreewheel) | |||
| fThread.DropRealTime(); // Always done (JACK server in RT mode or not...) | |||
| if (fFreewheel) { | |||
| fFreewheel(1, fFreewheelArg); | |||
| } | |||
| break; | |||
| case kStopFreewheelCallback: | |||
| jack_log("JackClient::kStopFreewheel"); | |||
| SetupDriverSync(false); | |||
| if (fFreewheel) | |||
| if (fFreewheel) { | |||
| fFreewheel(0, fFreewheelArg); | |||
| } | |||
| if (GetEngineControl()->fRealTime) { | |||
| fThread.AcquireRealTime(); | |||
| } | |||
| @@ -218,38 +225,44 @@ int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync, | |||
| case kPortRegistrationOnCallback: | |||
| jack_log("JackClient::kPortRegistrationOn port_index = %ld", value1); | |||
| if (fPortRegistration) | |||
| if (fPortRegistration) { | |||
| fPortRegistration(value1, 1, fPortRegistrationArg); | |||
| } | |||
| break; | |||
| case kPortRegistrationOffCallback: | |||
| jack_log("JackClient::kPortRegistrationOff port_index = %ld ", value1); | |||
| if (fPortRegistration) | |||
| if (fPortRegistration) { | |||
| fPortRegistration(value1, 0, fPortRegistrationArg); | |||
| } | |||
| break; | |||
| case kPortConnectCallback: | |||
| jack_log("JackClient::kPortConnectCallback src = %ld dst = %ld", value1, value2); | |||
| if (fPortConnect) | |||
| if (fPortConnect) { | |||
| fPortConnect(value1, value2, 1, fPortConnectArg); | |||
| } | |||
| break; | |||
| case kPortDisconnectCallback: | |||
| jack_log("JackClient::kPortDisconnectCallback src = %ld dst = %ld", value1, value2); | |||
| if (fPortConnect) | |||
| if (fPortConnect) { | |||
| fPortConnect(value1, value2, 0, fPortConnectArg); | |||
| } | |||
| break; | |||
| case kPortRenameCallback: | |||
| jack_log("JackClient::kPortRenameCallback port = %ld"); | |||
| if (fPortRename) | |||
| if (fPortRename) { | |||
| fPortRename(value1, GetGraphManager()->GetPort(value1)->GetName(), fPortRenameArg); | |||
| } | |||
| break; | |||
| case kXRunCallback: | |||
| jack_log("JackClient::kXRunCallback"); | |||
| if (fXrun) | |||
| if (fXrun) { | |||
| res = fXrun(fXrunArg); | |||
| } | |||
| break; | |||
| case kShutDownCallback: | |||
| @@ -456,7 +469,7 @@ inline void JackClient::End() | |||
| jack_log("JackClient::Execute end name = %s", GetClientControl()->fName); | |||
| // Hum... not sure about this, the following "close" code is called in the RT thread... | |||
| int result; | |||
| fThread.DropRealTime(); | |||
| fThread.DropSelfRealTime(); | |||
| GetClientControl()->fActive = false; | |||
| fChannel->ClientDeactivate(GetClientControl()->fRefNum, &result); | |||
| fThread.Terminate(); | |||
| @@ -467,7 +480,7 @@ inline void JackClient::Error() | |||
| jack_error("JackClient::Execute error name = %s", GetClientControl()->fName); | |||
| // Hum... not sure about this, the following "close" code is called in the RT thread... | |||
| int result; | |||
| fThread.DropRealTime(); | |||
| fThread.DropSelfRealTime(); | |||
| GetClientControl()->fActive = false; | |||
| fChannel->ClientDeactivate(GetClientControl()->fRefNum, &result); | |||
| ShutDown(); | |||
| @@ -228,8 +228,8 @@ namespace Jack | |||
| // Will do "something" on OSX only... | |||
| fThread.SetParams(GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint); | |||
| if (fThread.AcquireRealTime(GetEngineControl()->fClientPriority) < 0) { | |||
| jack_error("AcquireRealTime error"); | |||
| if (fThread.AcquireSelfRealTime(GetEngineControl()->fClientPriority) < 0) { | |||
| jack_error("AcquireSelfRealTime error"); | |||
| } else { | |||
| set_threaded_log_function(); | |||
| } | |||
| @@ -251,7 +251,7 @@ namespace Jack | |||
| e.PrintMessage(); | |||
| jack_info("NetAdapter is restarted."); | |||
| Reset(); | |||
| fThread.DropRealTime(); | |||
| fThread.DropSelfRealTime(); | |||
| fThread.SetStatus(JackThread::kIniting); | |||
| if (Init()) { | |||
| fThread.SetStatus(JackThread::kRunning); | |||
| @@ -36,7 +36,7 @@ bool JackRestartThreadedDriver::Execute() | |||
| } catch (JackNetException& e) { | |||
| e.PrintMessage(); | |||
| jack_log("Driver is restarted"); | |||
| fThread.DropRealTime(); | |||
| fThread.DropSelfRealTime(); | |||
| // Thread in kIniting status again... | |||
| fThread.SetStatus(JackThread::kIniting); | |||
| if (Init()) { | |||
| @@ -96,9 +96,14 @@ class SERVER_EXPORT JackThreadInterface | |||
| int Stop(); | |||
| void Terminate(); | |||
| int AcquireRealTime(); | |||
| int AcquireRealTime(int priority); | |||
| int DropRealTime(); | |||
| int AcquireRealTime(); // Used when called from another thread | |||
| int AcquireSelfRealTime(); // Used when called from thread itself | |||
| int AcquireRealTime(int priority); // Used when called from another thread | |||
| int AcquireSelfRealTime(int priority); // Used when called from thread itself | |||
| int DropRealTime(); // Used when called from another thread | |||
| int DropSelfRealTime(); // Used when called from thread itself | |||
| pthread_t GetThreadID(); | |||
| @@ -215,8 +215,8 @@ bool JackThreadedDriver::Init() | |||
| // Will do "something" on OSX only... | |||
| GetEngineControl()->fPeriod = GetEngineControl()->fConstraint = GetEngineControl()->fPeriodUsecs * 1000; | |||
| fThread.SetParams(GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint); | |||
| if (fThread.AcquireRealTime(GetEngineControl()->fServerPriority) < 0) { | |||
| jack_error("AcquireRealTime error"); | |||
| if (fThread.AcquireSelfRealTime(GetEngineControl()->fServerPriority) < 0) { | |||
| jack_error("AcquireSelfRealTime error"); | |||
| } else { | |||
| set_threaded_log_function(); | |||
| } | |||
| @@ -48,8 +48,8 @@ bool JackWaitThreadedDriver::Execute() | |||
| // Will do "something" on OSX only... | |||
| GetEngineControl()->fPeriod = GetEngineControl()->fConstraint = GetEngineControl()->fPeriodUsecs * 1000; | |||
| fThread.SetParams(GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint); | |||
| if (fThread.AcquireRealTime(GetEngineControl()->fServerPriority) < 0) { | |||
| jack_error("AcquireRealTime error"); | |||
| if (fThread.AcquireSelfRealTime(GetEngineControl()->fServerPriority) < 0) { | |||
| jack_error("AcquireSelfRealTime error"); | |||
| } else { | |||
| set_threaded_log_function(); | |||
| } | |||
| @@ -63,7 +63,7 @@ bool JackWaitThreadedDriver::Execute() | |||
| } catch (JackNetException& e) { | |||
| e.PrintMessage(); | |||
| jack_info("Driver is restarted"); | |||
| fThread.DropRealTime(); | |||
| fThread.DropSelfRealTime(); | |||
| // Thread in kIniting status again... | |||
| fThread.SetStatus(JackThread::kIniting); | |||
| if (Init()) { | |||
| @@ -156,6 +156,13 @@ int JackMachThread::Kill() | |||
| } | |||
| int JackMachThread::AcquireRealTime() | |||
| { | |||
| jack_log("JackMachThread::AcquireRealTime fPeriod = %ld fComputation = %ld fConstraint = %ld", | |||
| long(fPeriod / 1000), long(fComputation / 1000), long(fConstraint / 1000)); | |||
| return (fThread) ? AcquireRealTimeImp(fThread, fPeriod, fComputation, fConstraint) : -1; | |||
| } | |||
| int JackMachThread::AcquireSelfRealTime() | |||
| { | |||
| jack_log("JackMachThread::AcquireRealTime fPeriod = %ld fComputation = %ld fConstraint = %ld", | |||
| long(fPeriod / 1000), long(fComputation / 1000), long(fConstraint / 1000)); | |||
| @@ -168,6 +175,12 @@ int JackMachThread::AcquireRealTime(int priority) | |||
| return AcquireRealTime(); | |||
| } | |||
| int JackMachThread::AcquireSelfRealTime(int priority) | |||
| { | |||
| fPriority = priority; | |||
| return AcquireSelfRealTime(); | |||
| } | |||
| int JackMachThread::AcquireRealTimeImp(pthread_t thread, UInt64 period, UInt64 computation, UInt64 constraint) | |||
| { | |||
| SetThreadToPriority(thread, 96, true, period, computation, constraint); | |||
| @@ -179,6 +192,11 @@ int JackMachThread::AcquireRealTimeImp(pthread_t thread, UInt64 period, UInt64 c | |||
| } | |||
| int JackMachThread::DropRealTime() | |||
| { | |||
| return (fThread) ? DropRealTimeImp(fThread) : -1; | |||
| } | |||
| int JackMachThread::DropSelfRealTime() | |||
| { | |||
| return DropRealTimeImp(pthread_self()); | |||
| } | |||
| @@ -103,9 +103,15 @@ class SERVER_EXPORT JackMachThread : public JackPosixThread | |||
| int Kill(); | |||
| int AcquireRealTime(); | |||
| int AcquireRealTime(int priority); | |||
| int DropRealTime(); | |||
| int AcquireRealTime(); // Used when called from another thread | |||
| int AcquireSelfRealTime(); // Used when called from thread itself | |||
| int AcquireRealTime(int priority); // Used when called from another thread | |||
| int AcquireSelfRealTime(int priority); // Used when called from thread itself | |||
| int DropRealTime(); // Used when called from another thread | |||
| int DropSelfRealTime(); // Used when called from thread itself | |||
| void SetParams(UInt64 period, UInt64 computation, UInt64 constraint); | |||
| static int GetParams(pthread_t thread, UInt64* period, UInt64* computation, UInt64* constraint); | |||
| static int SetThreadToPriority(pthread_t thread, UInt32 inPriority, Boolean inIsFixed, UInt64 period, UInt64 computation, UInt64 constraint); | |||
| @@ -706,35 +706,35 @@ | |||
| isa = PBXContainerItemProxy; | |||
| containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */; | |||
| proxyType = 1; | |||
| remoteGlobalIDString = 4B3224D710A3156800838A8E /* jack_netone Universal */; | |||
| remoteGlobalIDString = 4B3224D710A3156800838A8E; | |||
| remoteInfo = "jack_netone Universal"; | |||
| }; | |||
| 4B32258A10A31A9000838A8E /* PBXContainerItemProxy */ = { | |||
| isa = PBXContainerItemProxy; | |||
| containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */; | |||
| proxyType = 1; | |||
| remoteGlobalIDString = 4B32255710A3187800838A8E /* jack_netsource Universal */; | |||
| remoteGlobalIDString = 4B32255710A3187800838A8E; | |||
| remoteInfo = "jack_netsource Universal"; | |||
| }; | |||
| 4B32258C10A31A9D00838A8E /* PBXContainerItemProxy */ = { | |||
| isa = PBXContainerItemProxy; | |||
| containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */; | |||
| proxyType = 1; | |||
| remoteGlobalIDString = 4B3224D710A3156800838A8E /* jack_netone Universal */; | |||
| remoteGlobalIDString = 4B3224D710A3156800838A8E; | |||
| remoteInfo = "jack_netone Universal"; | |||
| }; | |||
| 4B32258E10A31AB400838A8E /* PBXContainerItemProxy */ = { | |||
| isa = PBXContainerItemProxy; | |||
| containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */; | |||
| proxyType = 1; | |||
| remoteGlobalIDString = 4B32257110A3190C00838A8E /* jack_netsource 64 bits */; | |||
| remoteGlobalIDString = 4B32257110A3190C00838A8E; | |||
| remoteInfo = "jack_netsource 64 bits"; | |||
| }; | |||
| 4B32259010A31ABA00838A8E /* PBXContainerItemProxy */ = { | |||
| isa = PBXContainerItemProxy; | |||
| containerPortal = 08FB7793FE84155DC02AAC07 /* Project object */; | |||
| proxyType = 1; | |||
| remoteGlobalIDString = 4B32251D10A316B200838A8E /* jack_netone 64 bits */; | |||
| remoteGlobalIDString = 4B32251D10A316B200838A8E; | |||
| remoteInfo = "jack_netone 64 bits"; | |||
| }; | |||
| 4B35C5540D4731D2000DE7AE /* PBXContainerItemProxy */ = { | |||
| @@ -204,6 +204,11 @@ int JackPosixThread::StopImp(pthread_t thread) | |||
| } | |||
| int JackPosixThread::AcquireRealTime() | |||
| { | |||
| return (fThread != (pthread_t)NULL) ? AcquireRealTimeImp(fThread, fPriority) : -1; | |||
| } | |||
| int JackPosixThread::AcquireSelfRealTime() | |||
| { | |||
| return AcquireRealTimeImp(pthread_self(), fPriority); | |||
| } | |||
| @@ -214,6 +219,11 @@ int JackPosixThread::AcquireRealTime(int priority) | |||
| return AcquireRealTime(); | |||
| } | |||
| int JackPosixThread::AcquireSelfRealTime(int priority) | |||
| { | |||
| fPriority = priority; | |||
| return AcquireSelfRealTime(); | |||
| } | |||
| int JackPosixThread::AcquireRealTimeImp(pthread_t thread, int priority) | |||
| { | |||
| struct sched_param rtparam; | |||
| @@ -231,6 +241,11 @@ int JackPosixThread::AcquireRealTimeImp(pthread_t thread, int priority) | |||
| } | |||
| int JackPosixThread::DropRealTime() | |||
| { | |||
| return (fThread != (pthread_t)NULL) ? DropRealTimeImp(fThread) : -1; | |||
| } | |||
| int JackPosixThread::DropSelfRealTime() | |||
| { | |||
| return DropRealTimeImp(pthread_self()); | |||
| } | |||
| @@ -58,9 +58,14 @@ class SERVER_EXPORT JackPosixThread : public detail::JackThreadInterface | |||
| int Stop(); | |||
| void Terminate(); | |||
| int AcquireRealTime(); | |||
| int AcquireRealTime(int priority); | |||
| int DropRealTime(); | |||
| int AcquireRealTime(); // Used when called from another thread | |||
| int AcquireSelfRealTime(); // Used when called from thread itself | |||
| int AcquireRealTime(int priority); // Used when called from another thread | |||
| int AcquireSelfRealTime(int priority); // Used when called from thread itself | |||
| int DropRealTime(); // Used when called from another thread | |||
| int DropSelfRealTime(); // Used when called from thread itself | |||
| pthread_t GetThreadID(); | |||
| @@ -177,6 +177,11 @@ int JackWinThread::StopImp(pthread_t thread) | |||
| } | |||
| int JackWinThread::AcquireRealTime() | |||
| { | |||
| return (fThread) ? AcquireRealTimeImp(fThread, fPriority) : -1; | |||
| } | |||
| int JackWinThread::AcquireSelfRealTime() | |||
| { | |||
| return AcquireRealTimeImp(GetCurrentThread(), fPriority); | |||
| } | |||
| @@ -187,6 +192,12 @@ int JackWinThread::AcquireRealTime(int priority) | |||
| return AcquireRealTime(); | |||
| } | |||
| int JackWinThread::AcquireSelfRealTime(int priority) | |||
| { | |||
| fPriority = priority; | |||
| return AcquireSelfRealTime(); | |||
| } | |||
| int JackWinThread::AcquireRealTimeImp(pthread_t thread, int priority) | |||
| { | |||
| jack_log("JackWinThread::AcquireRealTime"); | |||
| @@ -198,7 +209,13 @@ int JackWinThread::AcquireRealTimeImp(pthread_t thread, int priority) | |||
| return -1; | |||
| } | |||
| } | |||
| int JackWinThread::DropRealTime() | |||
| { | |||
| return DropRealTimeImp(fThread); | |||
| } | |||
| int JackWinThread::DropSelfRealTime() | |||
| { | |||
| return DropRealTimeImp(GetCurrentThread()); | |||
| } | |||
| @@ -57,10 +57,15 @@ class SERVER_EXPORT JackWinThread : public detail::JackThreadInterface | |||
| int Stop(); | |||
| void Terminate(); | |||
| int AcquireRealTime(); | |||
| int AcquireRealTime(int priority) ; | |||
| int DropRealTime(); | |||
| int AcquireRealTime(); // Used when called from another thread | |||
| int AcquireSelfRealTime(); // Used when called from thread itself | |||
| int AcquireRealTime(int priority); // Used when called from another thread | |||
| int AcquireSelfRealTime(int priority); // Used when called from thread itself | |||
| int DropRealTime(); // Used when called from another thread | |||
| int DropSelfRealTime(); // Used when called from thread itself | |||
| pthread_t GetThreadID(); | |||
| static int AcquireRealTimeImp(pthread_t thread, int priority); | |||