Debian Codegraph @

src/engine/component.cpp

raw symbols SCIP
1 /* fre:ac - free audio converter
2 * Copyright (C) 2001-2020 Robert Kausch <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation, either version 2 of
7 * the License, or (at your option) any later version.
8 *
9 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
10 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
11 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */
12
13 #include <engine/component.h>
14
15 using namespace BoCA;
16 using namespace BoCA::AS;
17
18 Array<Threads::Mutex *, Void *> freac::Component::mutexes;
19 Threads::Mutex freac::Component::managementMutex;
20
21 freac::Component::Component(const BoCA::Config *iConfiguration)
22 {
23 configuration = iConfiguration;
24
25 errorState = False;
26 }
27
28 freac::Component::~Component()
29 {
30 }
31
32 Void freac::Component::SetErrorInfo(Bool error, const String &message, const String &replace1, const String &replace2, const String &replace3)
33 {
34 BoCA::I18n *i18n = BoCA::I18n::Get();
35
36 errorState = error;
37 errorString = i18n->TranslateString(message, "Errors").Replace("%1", replace1)
38 .Replace("%2", replace2)
39 .Replace("%3", replace3);
40 }
41
42 Bool freac::Component::LockComponent(StreamComponent *component)
43 {
44 if (component->IsThreadSafe()) return True;
45
46 /* Lock component if it's not thread safe.
47 */
48 managementMutex.Lock();
49
50 if (mutexes.Get(component->GetID().ComputeCRC32()) == NIL) mutexes.Add(new Threads::Mutex(), component->GetID().ComputeCRC32());
51
52 managementMutex.Release();
53
54 mutexes.Get(component->GetID().ComputeCRC32())->Lock();
55
56 return True;
57 }
58
59 Bool freac::Component::UnlockComponent(StreamComponent *component)
60 {
61 if (component->IsThreadSafe()) return True;
62
63 /* Unlock component if it's not thread safe.
64 */
65 mutexes.Get(component->GetID().ComputeCRC32())->Release();
66
67 return True;
68 }
69
70 Void freac::Component::FreeLockObjects()
71 {
72 foreach (Threads::Mutex *mutex, mutexes) delete mutex;
73
74 mutexes.RemoveAll();
75 }