* 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].
* Distributed under the terms of the MIT License.
*/
#ifndef _BUFFER_MANAGER_H
#define _BUFFER_MANAGER_H
#include <set>
@@ -110,3 +111,4 @@ private:
SourceInfoMap fSourceInfoMap;
};
#endif // _BUFFER_MANAGER_H
+31 -23
View File
@@ -55,8 +55,9 @@ DefaultManager::DefaultManager()
fTimeSource(-1),
fAudioMixer(-1),
fPhysicalAudioOutInputID(0),
fThreadId(-1),
fRescanRequested(0)
fRescanThread(-1),
fRescanRequested(0),
fRescanLock("rescan default manager")
{
strcpy(fPhysicalAudioOutInputName, "default");
fBeginHeader[0] = 0xab00150b;
@@ -328,11 +329,12 @@ DefaultManager::Get(media_node_id *nodeid, char *input_name, int32 *inputid,
status_t
DefaultManager::Rescan()
{
BAutolock locker(fRescanLock);
atomic_add(&fRescanRequested, 1);
if (fThreadId < 0) {
fThreadId = spawn_thread(rescan_thread, "rescan defaults",
if (fRescanThread < 0) {
fRescanThread = spawn_thread(rescan_thread, "rescan defaults",
B_NORMAL_PRIORITY - 2, this);
resume_thread(fThreadId);
resume_thread(fRescanThread);
}
return B_OK;
@@ -342,50 +344,54 @@ DefaultManager::Rescan()
int32
DefaultManager::rescan_thread(void *arg)
{
reinterpret_cast<DefaultManager *>(arg)->RescanThread();
reinterpret_cast<DefaultManager *>(arg)->_RescanThread();
return 0;
}
void
DefaultManager::RescanThread()
DefaultManager::_RescanThread()
{
TRACE("DefaultManager::RescanThread() enter\n");
TRACE("DefaultManager::_RescanThread() enter\n");
BAutolock locker(fRescanLock);
while (atomic_and(&fRescanRequested, 0) != 0) {
locker.Unlock();
// We do not search for the system time source,
// it should already exist
ASSERT(fSystemTimeSource != -1);
if (fPhysicalVideoOut == -1) {
FindPhysical(&fPhysicalVideoOut, kMsgTypeVideoOut, false,
_FindPhysical(&fPhysicalVideoOut, kMsgTypeVideoOut, false,
B_MEDIA_RAW_VIDEO);
FindPhysical(&fPhysicalVideoOut, kMsgTypeVideoOut, false,
_FindPhysical(&fPhysicalVideoOut, kMsgTypeVideoOut, false,
B_MEDIA_ENCODED_VIDEO);
}
if (fPhysicalVideoIn == -1) {
FindPhysical(&fPhysicalVideoIn, kMsgTypeVideoIn, true,
_FindPhysical(&fPhysicalVideoIn, kMsgTypeVideoIn, true,
B_MEDIA_RAW_VIDEO);
FindPhysical(&fPhysicalVideoIn, kMsgTypeVideoIn, true,
_FindPhysical(&fPhysicalVideoIn, kMsgTypeVideoIn, true,
B_MEDIA_ENCODED_VIDEO);
}
if (fPhysicalAudioOut == -1)
FindPhysical(&fPhysicalAudioOut, kMsgTypeAudioOut, false,
_FindPhysical(&fPhysicalAudioOut, kMsgTypeAudioOut, false,
B_MEDIA_RAW_AUDIO);
if (fPhysicalAudioIn == -1)
FindPhysical(&fPhysicalAudioIn, kMsgTypeAudioIn, true,
_FindPhysical(&fPhysicalAudioIn, kMsgTypeAudioIn, true,
B_MEDIA_RAW_AUDIO);
if (fAudioMixer == -1)
FindAudioMixer();
_FindAudioMixer();
// The normal time source is searched for after the
// Physical Audio Out has been created.
if (fTimeSource == -1)
FindTimeSource();
_FindTimeSource();
// Connect the mixer and physical audio out (soundcard)
if (!fMixerConnected && fAudioMixer != -1 && fPhysicalAudioOut != -1) {
fMixerConnected = B_OK == ConnectMixerToOutput();
fMixerConnected = B_OK == _ConnectMixerToOutput();
if (!fMixerConnected)
ERROR("DefaultManager: failed to connect mixer and"
"soundcard\n");
@@ -399,16 +405,18 @@ DefaultManager::RescanThread()
SendToAddOnServer(ADD_ON_SERVER_RESCAN_FINISHED_NOTIFY, &cmd,
sizeof(cmd));
}
locker.Lock();
}
fThreadId = -1;
fRescanThread = -1;
TRACE("DefaultManager::RescanThread() leave\n");
TRACE("DefaultManager::_RescanThread() leave\n");
}
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)
{
live_node_info info[MAX_NODE_INFOS];
@@ -512,7 +520,7 @@ DefaultManager::FindPhysical(volatile media_node_id *id, uint32 default_type,
void
DefaultManager::FindTimeSource()
DefaultManager::_FindTimeSource()
{
live_node_info info[MAX_NODE_INFOS];
media_format input; /* a physical audio output has a logical data input (DAC)*/
@@ -577,7 +585,7 @@ DefaultManager::FindTimeSource()
void
DefaultManager::FindAudioMixer()
DefaultManager::_FindAudioMixer()
{
live_node_info info;
int32 count;
@@ -596,7 +604,7 @@ DefaultManager::FindAudioMixer()
status_t
DefaultManager::ConnectMixerToOutput()
DefaultManager::_ConnectMixerToOutput()
{
BMediaRoster *roster;
media_node timesource;
+57 -32
View File
@@ -1,56 +1,81 @@
/*
* 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.
* 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 <Autolock.h>
#include <Message.h>
class NodeManager;
class DefaultManager
{
class DefaultManager {
public:
DefaultManager();
~DefaultManager();
DefaultManager();
~DefaultManager();
status_t LoadState();
status_t SaveState(NodeManager *node_manager);
status_t LoadState();
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 Get(media_node_id *nodeid, char *input_name, int32 *input_id, node_type type);
status_t Rescan();
status_t Set(media_node_id nodeid,
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();
void Dump();
void Dump();
void CleanupTeam(team_id team);
void CleanupTeam(team_id team);
private:
static int32 rescan_thread(void *arg);
void RescanThread();
static int32 rescan_thread(void *arg);
void _RescanThread();
void FindPhysical(volatile media_node_id *id, uint32 default_type, bool isInput, media_type type);
void FindAudioMixer();
void FindTimeSource();
void _FindPhysical(volatile media_node_id *id,
uint32 default_type, bool isInput,
media_type type);
void _FindAudioMixer();
void _FindTimeSource();
status_t ConnectMixerToOutput();
status_t _ConnectMixerToOutput();
private:
volatile bool fMixerConnected;
volatile media_node_id fPhysicalVideoOut;
volatile media_node_id fPhysicalVideoIn;
volatile media_node_id fPhysicalAudioOut;
volatile media_node_id fPhysicalAudioIn;
volatile media_node_id fSystemTimeSource;
volatile media_node_id fTimeSource;
volatile media_node_id fAudioMixer;
volatile int32 fPhysicalAudioOutInputID;
char fPhysicalAudioOutInputName[B_MEDIA_NAME_LENGTH];
volatile bool fMixerConnected;
volatile media_node_id fPhysicalVideoOut;
volatile media_node_id fPhysicalVideoIn;
volatile media_node_id fPhysicalAudioOut;
volatile media_node_id fPhysicalAudioIn;
volatile media_node_id fSystemTimeSource;
volatile media_node_id fTimeSource;
volatile media_node_id fAudioMixer;
volatile int32 fPhysicalAudioOutInputID;
char fPhysicalAudioOutInputName[B_MEDIA_NAME_LENGTH];
BList fMsgList;
BList fMsgList;
uint32 fBeginHeader[3];
uint32 fEndHeader[3];
thread_id fThreadId;
vint32 fRescanRequested;
uint32 fBeginHeader[3];
uint32 fEndHeader[3];
thread_id fRescanThread;
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.
* Distributed under the terms of the MIT License.
*/
#ifndef _MEDIA_FILES_MANAGER_H
#define _MEDIA_FILES_MANAGER_H
#include <map>
@@ -12,7 +14,7 @@
#include <MessageRunner.h>
#include <String.h>
#include <DataExchange.h>
#include "DataExchange.h"
#define MEDIA_FILES_MANAGER_SAVE_TIMER 'mmst'
@@ -70,3 +72,5 @@ private:
TypeMap fMap;
BMessageRunner* fSaveTimerRunner;
};
#endif // _MEDIA_FILES_MANAGER_H
+1
View File
@@ -5,6 +5,7 @@
#ifndef NOTIFICATION_MANAGER_H
#define NOTIFICATION_MANAGER_H
#include <Locker.h>
#include <MediaNode.h>
#include <Messenger.h>