* style cleanup

* DefaultManager: added a lock around rescan thread start and exit:
this should fix the possible race condition spotted by Ingo.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36588 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2010-05-02 22:35:18 +00:00
parent 7b63fd1c11
commit 4da0916c58
5 changed files with 122 additions and 82 deletions
+3 -1
View File
@@ -3,7 +3,8 @@
* Copyright 2009, Axel Dörfler, [email protected]. * Copyright 2009, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _BUFFER_MANAGER_H
#define _BUFFER_MANAGER_H
#include <set> #include <set>
@@ -110,3 +111,4 @@ private:
SourceInfoMap fSourceInfoMap; SourceInfoMap fSourceInfoMap;
}; };
#endif // _BUFFER_MANAGER_H
+31 -23
View File
@@ -55,8 +55,9 @@ DefaultManager::DefaultManager()
fTimeSource(-1), fTimeSource(-1),
fAudioMixer(-1), fAudioMixer(-1),
fPhysicalAudioOutInputID(0), fPhysicalAudioOutInputID(0),
fThreadId(-1), fRescanThread(-1),
fRescanRequested(0) fRescanRequested(0),
fRescanLock("rescan default manager")
{ {
strcpy(fPhysicalAudioOutInputName, "default"); strcpy(fPhysicalAudioOutInputName, "default");
fBeginHeader[0] = 0xab00150b; fBeginHeader[0] = 0xab00150b;
@@ -328,11 +329,12 @@ DefaultManager::Get(media_node_id *nodeid, char *input_name, int32 *inputid,
status_t status_t
DefaultManager::Rescan() DefaultManager::Rescan()
{ {
BAutolock locker(fRescanLock);
atomic_add(&fRescanRequested, 1); atomic_add(&fRescanRequested, 1);
if (fThreadId < 0) { if (fRescanThread < 0) {
fThreadId = spawn_thread(rescan_thread, "rescan defaults", fRescanThread = spawn_thread(rescan_thread, "rescan defaults",
B_NORMAL_PRIORITY - 2, this); B_NORMAL_PRIORITY - 2, this);
resume_thread(fThreadId); resume_thread(fRescanThread);
} }
return B_OK; return B_OK;
@@ -342,50 +344,54 @@ DefaultManager::Rescan()
int32 int32
DefaultManager::rescan_thread(void *arg) DefaultManager::rescan_thread(void *arg)
{ {
reinterpret_cast<DefaultManager *>(arg)->RescanThread(); reinterpret_cast<DefaultManager *>(arg)->_RescanThread();
return 0; return 0;
} }
void void
DefaultManager::RescanThread() DefaultManager::_RescanThread()
{ {
TRACE("DefaultManager::RescanThread() enter\n"); TRACE("DefaultManager::_RescanThread() enter\n");
BAutolock locker(fRescanLock);
while (atomic_and(&fRescanRequested, 0) != 0) { while (atomic_and(&fRescanRequested, 0) != 0) {
locker.Unlock();
// We do not search for the system time source, // We do not search for the system time source,
// it should already exist // it should already exist
ASSERT(fSystemTimeSource != -1); ASSERT(fSystemTimeSource != -1);
if (fPhysicalVideoOut == -1) { if (fPhysicalVideoOut == -1) {
FindPhysical(&fPhysicalVideoOut, kMsgTypeVideoOut, false, _FindPhysical(&fPhysicalVideoOut, kMsgTypeVideoOut, false,
B_MEDIA_RAW_VIDEO); B_MEDIA_RAW_VIDEO);
FindPhysical(&fPhysicalVideoOut, kMsgTypeVideoOut, false, _FindPhysical(&fPhysicalVideoOut, kMsgTypeVideoOut, false,
B_MEDIA_ENCODED_VIDEO); B_MEDIA_ENCODED_VIDEO);
} }
if (fPhysicalVideoIn == -1) { if (fPhysicalVideoIn == -1) {
FindPhysical(&fPhysicalVideoIn, kMsgTypeVideoIn, true, _FindPhysical(&fPhysicalVideoIn, kMsgTypeVideoIn, true,
B_MEDIA_RAW_VIDEO); B_MEDIA_RAW_VIDEO);
FindPhysical(&fPhysicalVideoIn, kMsgTypeVideoIn, true, _FindPhysical(&fPhysicalVideoIn, kMsgTypeVideoIn, true,
B_MEDIA_ENCODED_VIDEO); B_MEDIA_ENCODED_VIDEO);
} }
if (fPhysicalAudioOut == -1) if (fPhysicalAudioOut == -1)
FindPhysical(&fPhysicalAudioOut, kMsgTypeAudioOut, false, _FindPhysical(&fPhysicalAudioOut, kMsgTypeAudioOut, false,
B_MEDIA_RAW_AUDIO); B_MEDIA_RAW_AUDIO);
if (fPhysicalAudioIn == -1) if (fPhysicalAudioIn == -1)
FindPhysical(&fPhysicalAudioIn, kMsgTypeAudioIn, true, _FindPhysical(&fPhysicalAudioIn, kMsgTypeAudioIn, true,
B_MEDIA_RAW_AUDIO); B_MEDIA_RAW_AUDIO);
if (fAudioMixer == -1) if (fAudioMixer == -1)
FindAudioMixer(); _FindAudioMixer();
// The normal time source is searched for after the // The normal time source is searched for after the
// Physical Audio Out has been created. // Physical Audio Out has been created.
if (fTimeSource == -1) if (fTimeSource == -1)
FindTimeSource(); _FindTimeSource();
// Connect the mixer and physical audio out (soundcard) // Connect the mixer and physical audio out (soundcard)
if (!fMixerConnected && fAudioMixer != -1 && fPhysicalAudioOut != -1) { if (!fMixerConnected && fAudioMixer != -1 && fPhysicalAudioOut != -1) {
fMixerConnected = B_OK == ConnectMixerToOutput(); fMixerConnected = B_OK == _ConnectMixerToOutput();
if (!fMixerConnected) if (!fMixerConnected)
ERROR("DefaultManager: failed to connect mixer and" ERROR("DefaultManager: failed to connect mixer and"
"soundcard\n"); "soundcard\n");
@@ -399,16 +405,18 @@ DefaultManager::RescanThread()
SendToAddOnServer(ADD_ON_SERVER_RESCAN_FINISHED_NOTIFY, &cmd, SendToAddOnServer(ADD_ON_SERVER_RESCAN_FINISHED_NOTIFY, &cmd,
sizeof(cmd)); sizeof(cmd));
} }
locker.Lock();
} }
fThreadId = -1; fRescanThread = -1;
TRACE("DefaultManager::RescanThread() leave\n"); TRACE("DefaultManager::_RescanThread() leave\n");
} }
void void
DefaultManager::FindPhysical(volatile media_node_id *id, uint32 default_type, DefaultManager::_FindPhysical(volatile media_node_id *id, uint32 default_type,
bool isInput, media_type type) bool isInput, media_type type)
{ {
live_node_info info[MAX_NODE_INFOS]; live_node_info info[MAX_NODE_INFOS];
@@ -512,7 +520,7 @@ DefaultManager::FindPhysical(volatile media_node_id *id, uint32 default_type,
void void
DefaultManager::FindTimeSource() DefaultManager::_FindTimeSource()
{ {
live_node_info info[MAX_NODE_INFOS]; live_node_info info[MAX_NODE_INFOS];
media_format input; /* a physical audio output has a logical data input (DAC)*/ media_format input; /* a physical audio output has a logical data input (DAC)*/
@@ -577,7 +585,7 @@ DefaultManager::FindTimeSource()
void void
DefaultManager::FindAudioMixer() DefaultManager::_FindAudioMixer()
{ {
live_node_info info; live_node_info info;
int32 count; int32 count;
@@ -596,7 +604,7 @@ DefaultManager::FindAudioMixer()
status_t status_t
DefaultManager::ConnectMixerToOutput() DefaultManager::_ConnectMixerToOutput()
{ {
BMediaRoster *roster; BMediaRoster *roster;
media_node timesource; media_node timesource;
+35 -10
View File
@@ -1,15 +1,32 @@
/*
* Copyright 2010, Haiku. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* Marcus Overhagen
* Jérôme Duval
*/
/* /*
* Copyright 2002, Marcus Overhagen. All rights reserved. * Copyright 2002, Marcus Overhagen. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _DEFAULT_MANAGER_H
#define _DEFAULT_MANAGER_H
/*! Manager for defaults (audio and video, input and output)
*/
#include "DataExchange.h" #include "DataExchange.h"
#include <Autolock.h>
#include <Message.h> #include <Message.h>
class NodeManager; class NodeManager;
class DefaultManager
{ class DefaultManager {
public: public:
DefaultManager(); DefaultManager();
~DefaultManager(); ~DefaultManager();
@@ -17,8 +34,11 @@ public:
status_t LoadState(); status_t LoadState();
status_t SaveState(NodeManager *node_manager); status_t SaveState(NodeManager *node_manager);
status_t Set(media_node_id nodeid, const char *input_name, int32 input_id, node_type type); status_t Set(media_node_id nodeid,
status_t Get(media_node_id *nodeid, char *input_name, int32 *input_id, node_type type); const char *input_name, int32 input_id,
node_type type);
status_t Get(media_node_id *nodeid, char *input_name,
int32 *input_id, node_type type);
status_t Rescan(); status_t Rescan();
void Dump(); void Dump();
@@ -27,13 +47,15 @@ public:
private: private:
static int32 rescan_thread(void *arg); static int32 rescan_thread(void *arg);
void RescanThread(); void _RescanThread();
void FindPhysical(volatile media_node_id *id, uint32 default_type, bool isInput, media_type type); void _FindPhysical(volatile media_node_id *id,
void FindAudioMixer(); uint32 default_type, bool isInput,
void FindTimeSource(); media_type type);
void _FindAudioMixer();
void _FindTimeSource();
status_t ConnectMixerToOutput(); status_t _ConnectMixerToOutput();
private: private:
volatile bool fMixerConnected; volatile bool fMixerConnected;
@@ -51,6 +73,9 @@ private:
uint32 fBeginHeader[3]; uint32 fBeginHeader[3];
uint32 fEndHeader[3]; uint32 fEndHeader[3];
thread_id fThreadId; thread_id fRescanThread;
vint32 fRescanRequested; vint32 fRescanRequested;
BLocker fRescanLock;
}; };
#endif // _DEFAULT_MANAGER_H
+5 -1
View File
@@ -2,6 +2,8 @@
* Copyright 2003, Jérôme Duval. All rights reserved. * Copyright 2003, Jérôme Duval. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _MEDIA_FILES_MANAGER_H
#define _MEDIA_FILES_MANAGER_H
#include <map> #include <map>
@@ -12,7 +14,7 @@
#include <MessageRunner.h> #include <MessageRunner.h>
#include <String.h> #include <String.h>
#include <DataExchange.h> #include "DataExchange.h"
#define MEDIA_FILES_MANAGER_SAVE_TIMER 'mmst' #define MEDIA_FILES_MANAGER_SAVE_TIMER 'mmst'
@@ -70,3 +72,5 @@ private:
TypeMap fMap; TypeMap fMap;
BMessageRunner* fSaveTimerRunner; BMessageRunner* fSaveTimerRunner;
}; };
#endif // _MEDIA_FILES_MANAGER_H
+1
View File
@@ -5,6 +5,7 @@
#ifndef NOTIFICATION_MANAGER_H #ifndef NOTIFICATION_MANAGER_H
#define NOTIFICATION_MANAGER_H #define NOTIFICATION_MANAGER_H
#include <Locker.h> #include <Locker.h>
#include <MediaNode.h> #include <MediaNode.h>
#include <Messenger.h> #include <Messenger.h>