const char RPC_PORT_SIGNAL_NEW[] = "New";
} // namespace
+std::atomic<DebugPort*> DebugPort::inst_;
+std::mutex DebugPort::mutex_;
+
DebugPort::~DebugPort() {
if (!disposed_)
Dispose();
}
+DebugPort* DebugPort::GetInst() {
+ DebugPort* inst = inst_.load(std::memory_order_acquire);
+ if (inst == nullptr) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ inst = inst_.load(std::memory_order_relaxed);
+ if (inst == nullptr) {
+ inst = new DebugPort();
+ inst_.store(inst, std::memory_order_release);
+ }
+ }
+
+ std::lock_guard<std::recursive_mutex> rec_lock(inst->GetMutex());
+ if (inst->disposed_)
+ inst->Init();
+
+ return inst;
+}
+
void DebugPort::Dispose() {
Unwatch();
Unsubscribe();
int delegate_port_;
};
- static DebugPort& GetInst() {
- static DebugPort inst;
-
- std::lock_guard<std::recursive_mutex> lock(inst.GetMutex());
- if (inst.disposed_)
- inst.Init();
- return inst;
- }
+ static DebugPort* GetInst();
void Dispose();
bool IsConnected();
const void* buf, unsigned int size);
private:
+ static std::atomic<DebugPort*> inst_;
+ static std::mutex mutex_;
+
std::recursive_mutex& GetMutex() const {
- return mutex_;
+ return rec_mutex_;
}
void Init();
std::thread thread_;
std::atomic<bool> is_running_;
SharedQueue<std::shared_ptr<tizen_base::Parcel>> queue_;
- mutable std::recursive_mutex mutex_;
+ mutable std::recursive_mutex rec_mutex_;
};
} // namespace internal
main_port_.reset(new ProxyPort(this, fds_[0], target_appid_, false));
delegate_port_.reset(new ProxyPort(this, fds_[1], target_appid_));
listener_->OnConnected(target_appid_, main_port_.get());
- DebugPort::GetInst().AddSession(port_name, target_appid_, fds_[0], fds_[1]);
+ DebugPort::GetInst()->AddSession(port_name, target_appid_, fds_[0], fds_[1]);
return RPC_PORT_ERROR_NONE;
}
void Proxy::DisconnectPort() {
std::lock_guard<std::recursive_mutex> lock(GetMutex());
if (main_port_.get() != nullptr) {
- DebugPort::GetInst().RemoveSession(main_port_->GetFd());
+ DebugPort::GetInst()->RemoveSession(main_port_->GetFd());
main_port_.reset();
}
}
proxy->delegate_port_.reset();
proxy->listener_ = nullptr;
listener->OnDisconnected(proxy->target_appid_);
- DebugPort::GetInst().RemoveSession(fd);
+ DebugPort::GetInst()->RemoveSession(fd);
return G_SOURCE_REMOVE;;
}
proxy->listener_ = nullptr;
proxy->delegate_port_->SetSource(0);
if (proxy->main_port_.get() != nullptr) {
- DebugPort::GetInst().RemoveSession(proxy->main_port_->GetFd());
+ DebugPort::GetInst()->RemoveSession(proxy->main_port_->GetFd());
proxy->main_port_.reset();
}
proxy->delegate_port_.reset();
proxy->delegate_port_.reset(
new ProxyPort(proxy, proxy->fds_[1], proxy->target_appid_));
listener->OnConnected(proxy->target_appid_, proxy->main_port_.get());
- DebugPort::GetInst().AddSession(proxy->port_name_, proxy->target_appid_,
+ DebugPort::GetInst()->AddSession(proxy->port_name_, proxy->target_appid_,
proxy->fds_[0], proxy->fds_[1]);
_W("target_appid(%s), port_name(%s), main_fd(%d), delegate_fd(%d)",
proxy->target_appid_.c_str(), proxy->port_name_.c_str(),
return ret;
}
- auto& debug_port = DebugPort::GetInst();
- debug_port.Send(port->GetFd(), true, seq, buf, size);
+ auto* debug_port = DebugPort::GetInst();
+ debug_port->Send(port->GetFd(), true, seq, buf, size);
return RPC_PORT_ERROR_NONE;
}
if (ret < 0)
return ret;
- auto& debug_port = DebugPort::GetInst();
- debug_port.Send(port->GetFd(), false, seq, buf, size);
+ auto* debug_port = DebugPort::GetInst();
+ debug_port->Send(port->GetFd(), false, seq, buf, size);
return RPC_PORT_ERROR_NONE;
}
while (iter != ports_.end()) {
if ((*iter)->GetInstance().compare(instance) == 0) {
LOGI("Close: fd(%d)", (*iter)->GetFd());
- DebugPort::GetInst().RemoveSession((*iter)->GetFd());
+ DebugPort::GetInst()->RemoveSession((*iter)->GetFd());
iter = ports_.erase(iter);
} else {
iter++;
_W("sender_appid(%s), instance(%s), main_fd(%d), delegate_fd(%d)",
sender_appid.c_str(), instance.c_str(), main_fd, fd);
listener_->OnConnected(sender_appid, instance);
- DebugPort::GetInst().AddSession(port_name_, sender_appid, main_fd, fd);
+ DebugPort::GetInst()->AddSession(port_name_, sender_appid, main_fd, fd);
}
std::recursive_mutex& Stub::GetMutex() const {