Finer grained locking
git-svn-id: http://voip.null.ro/svn/yate@359 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
d463967300
commit
f1522b51b4
|
@ -39,7 +39,7 @@ class ConfRoom : public DataSource
|
|||
public:
|
||||
ConfRoom(const String& name);
|
||||
~ConfRoom();
|
||||
static ConfRoom* create(const String& name);
|
||||
static ConfRoom* get(const String& name, bool create = false);
|
||||
virtual const String& toString() const
|
||||
{ return m_name; }
|
||||
inline ObjList& channels()
|
||||
|
@ -83,7 +83,7 @@ public:
|
|||
|
||||
INIT_PLUGIN(ConferenceDriver);
|
||||
|
||||
ConfRoom* ConfRoom::create(const String& name)
|
||||
ConfRoom* ConfRoom::get(const String& name, bool create)
|
||||
{
|
||||
if (name.null())
|
||||
return 0;
|
||||
|
@ -91,7 +91,7 @@ ConfRoom* ConfRoom::create(const String& name)
|
|||
ConfRoom* room = l ? static_cast<ConfRoom*>(l->get()) : 0;
|
||||
if (room)
|
||||
room->ref();
|
||||
else
|
||||
else if (create)
|
||||
room = new ConfRoom(name);
|
||||
return room;
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ void ConfConsumer::Consume(const DataBlock& data, unsigned long timeDelta)
|
|||
{
|
||||
if (data.null() || !m_room)
|
||||
return;
|
||||
Lock lock(&__plugin);
|
||||
Lock lock(m_room->mutex());
|
||||
if (m_buffer.length()+data.length() < MAX_BUFFER)
|
||||
m_buffer += data;
|
||||
if (m_buffer.length() >= MIN_BUFFER)
|
||||
|
@ -175,7 +175,7 @@ ConfChan::ConfChan(const String& name)
|
|||
{
|
||||
Debug(this,DebugAll,"ConfChan::ConfChan(%s) %s [%p]",name.c_str(),id().c_str(),this);
|
||||
Lock lock(&__plugin);
|
||||
ConfRoom* room = ConfRoom::create(name);
|
||||
ConfRoom* room = ConfRoom::get(name,true);
|
||||
if (room) {
|
||||
setSource(room);
|
||||
room->deref();
|
||||
|
@ -198,6 +198,8 @@ ConfChan::~ConfChan()
|
|||
|
||||
bool ConferenceDriver::msgExecute(Message& msg, String& dest)
|
||||
{
|
||||
if (msg.getBoolValue("existing") && !ConfRoom::get(dest))
|
||||
return false;
|
||||
if (dest.null())
|
||||
dest << "x-" << (unsigned int)::random();
|
||||
CallEndpoint* ch = static_cast<CallEndpoint*>(msg.userData());
|
||||
|
|
|
@ -213,9 +213,9 @@ bool DSoundPlay::init()
|
|||
fmt.wFormatTag,fmt.nChannels,fmt.nSamplesPerSec,fmt.wBitsPerSample);
|
||||
return false;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
DSBCAPS caps;
|
||||
caps.dwSize = sizeof(caps);
|
||||
#ifdef DEBUG
|
||||
if (SUCCEEDED(m_dsb->GetCaps(&caps)))
|
||||
Debug(DebugInfo,"DirectSound buffer size %u",caps.dwBufferBytes);
|
||||
#endif
|
||||
|
|
|
@ -221,7 +221,8 @@ unsigned char Fifo::get()
|
|||
}
|
||||
|
||||
PriSpan::PriSpan(struct pri *_pri, PriDriver* driver, int span, int first, int chans, int dchan, Configuration& cfg, const String& sect)
|
||||
: m_driver(driver), m_span(span), m_offs(first), m_nchans(chans), m_bchans(0),
|
||||
: Mutex(true),
|
||||
m_driver(driver), m_span(span), m_offs(first), m_nchans(chans), m_bchans(0),
|
||||
m_pri(_pri), m_restart(0), m_chans(0), m_ok(false)
|
||||
{
|
||||
Debug(m_driver,DebugAll,"PriSpan::PriSpan() [%p]",this);
|
||||
|
@ -276,8 +277,8 @@ PriSpan::~PriSpan()
|
|||
|
||||
void PriSpan::runEvent(bool idleRun)
|
||||
{
|
||||
Lock lock(m_driver);
|
||||
pri_event *ev = 0;
|
||||
lock();
|
||||
if (idleRun) {
|
||||
ev = ::pri_schedule_run(m_pri);
|
||||
idle();
|
||||
|
@ -289,6 +290,7 @@ void PriSpan::runEvent(bool idleRun)
|
|||
::pri_dump_event(m_pri, ev);
|
||||
handleEvent(*ev);
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
|
||||
void PriSpan::idle()
|
||||
|
@ -553,9 +555,9 @@ void PriChan::disconnected(bool final, const char *reason)
|
|||
m->addParam("reason",reason);
|
||||
Engine::enqueue(m);
|
||||
}
|
||||
driver()->lock();
|
||||
m_span->lock();
|
||||
hangup(PRI_CAUSE_NORMAL_CLEARING);
|
||||
driver()->unlock();
|
||||
m_span->unlock();
|
||||
}
|
||||
|
||||
bool PriChan::nativeConnect(DataEndpoint *peer)
|
||||
|
@ -592,10 +594,10 @@ void PriChan::restart(bool outgoing)
|
|||
|
||||
void PriChan::closeData()
|
||||
{
|
||||
driver()->lock();
|
||||
m_span->lock();
|
||||
setSource();
|
||||
setConsumer();
|
||||
driver()->unlock();
|
||||
m_span->unlock();
|
||||
}
|
||||
|
||||
bool PriChan::answer()
|
||||
|
|
|
@ -48,7 +48,7 @@ private:
|
|||
class PriChan;
|
||||
class PriDriver;
|
||||
|
||||
class PriSpan : public GenObject
|
||||
class PriSpan : public GenObject, public Mutex
|
||||
{
|
||||
public:
|
||||
virtual ~PriSpan();
|
||||
|
|
|
@ -106,7 +106,7 @@ class WpChan : public PriChan
|
|||
public:
|
||||
WpChan(const PriSpan *parent, int chan, unsigned int bufsize);
|
||||
virtual ~WpChan();
|
||||
bool openData(const char* format, int echoTaps);
|
||||
virtual bool openData(const char* format, int echoTaps);
|
||||
|
||||
private:
|
||||
WpSource* m_wp_s;
|
||||
|
@ -422,7 +422,7 @@ void WpData::run()
|
|||
if ((r > 0) && ((r % bchans) == 0)) {
|
||||
r /= bchans;
|
||||
const unsigned char* dat = m_buffer + WP_HEADER;
|
||||
m_span->driver()->lock();
|
||||
m_span->lock();
|
||||
for (int n = r; n > 0; n--)
|
||||
for (b = 0; b < bchans; b++) {
|
||||
WpSource *s = m_chans[b]->m_wp_s;
|
||||
|
@ -430,19 +430,19 @@ void WpData::run()
|
|||
s->put(PriDriver::bitswap(*dat));
|
||||
dat++;
|
||||
}
|
||||
m_span->driver()->unlock();
|
||||
m_span->unlock();
|
||||
}
|
||||
int w = samp;
|
||||
::memset(m_buffer,0,WP_HEADER);
|
||||
unsigned char* dat = m_buffer + WP_HEADER;
|
||||
m_span->driver()->lock();
|
||||
m_span->lock();
|
||||
for (int n = w; n > 0; n--) {
|
||||
for (b = 0; b < bchans; b++) {
|
||||
WpConsumer *c = m_chans[b]->m_wp_c;
|
||||
*dat++ = PriDriver::bitswap(c ? c->get() : 0xff);
|
||||
}
|
||||
}
|
||||
m_span->driver()->unlock();
|
||||
m_span->unlock();
|
||||
w = (w * bchans) + WP_HEADER;
|
||||
XDebug("wpdata_send",DebugAll,"pre buf=%p len=%d sz=%d",m_buffer,w,sz);
|
||||
w = wp_send(m_fd,m_buffer,w,MSG_DONTWAIT);
|
||||
|
@ -465,10 +465,12 @@ bool WpChan::openData(const char* format, int echoTaps)
|
|||
{
|
||||
if (echoTaps)
|
||||
Debug(DebugWarn,"Echo cancellation requested but not available in wanpipe");
|
||||
m_span->lock();
|
||||
setSource(new WpSource(this,format,m_bufsize));
|
||||
getSource()->deref();
|
||||
setConsumer(new WpConsumer(this,format,m_bufsize));
|
||||
getConsumer()->deref();
|
||||
m_span->unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -383,6 +383,13 @@ public:
|
|||
inline void clear()
|
||||
{ m_consumers.clear(); }
|
||||
|
||||
/**
|
||||
* Get the mutex that serializes access to this data source
|
||||
* @return Reference to DataSource's mutex object
|
||||
*/
|
||||
inline Mutex& mutex()
|
||||
{ return m_mutex; }
|
||||
|
||||
/**
|
||||
* Get the master translator object if this source is part of a translator
|
||||
* @return A pointer to the DataTranslator object or NULL
|
||||
|
|
Loading…
Reference in New Issue