第3月第2天 find symbolicatecrash 生产者-消费者 ice 引用计数
1.linux find export
find /Applications/Xcode.app/ -name symbolicatecrash -type f
export DEVELOPER_DIR="/Applications/Xcode.app/Contents/Developer"
2.symbolicatecrash
http://www.cnblogs.com/ningxu-ios/p/4141783.html
3.AURenderCallbackStruct
AURenderCallbackStruct callbackStruct;
callbackStruct.inputProc = AudioPlayUnit_context::playbackCallback;
callbackStruct.inputProcRefCon = this;
4.生产者-消费者
1)缓冲区,缓冲区写满需等待,消费者消费后需通知
class BytesBuffer : public IceUtil::Shared
{
public:
BytesBuffer(size_t bufferSize);
void feed(size_t size, BufferChunkRef cbChunk);
void eat(size_t size, BufferChunkRef cbChunk);
等待
void BytesBuffer_context::feed(size_t size, BufferChunkRef cbChunk)
{
{
Monitor<RecMutex>::Lock lock(_monitor);
if (_feedTerminated) return; while( size > _feedCapacity && !_eatTerminated) {
_currentFeedRequestSize = size;
// SP::printf("\nwait feeding, eatting %s\n", _eatTerminated ? "terminated" : "not terminated");
_monitor.wait();
}
_currentFeedRequestSize = ;
}
通知
Monitor<RecMutex>::Lock lock(_monitor);
//check and notify, if _feedTerminated then _currentFeedRequestSize=0, verify already included
if (_feedCapacity < _currentFeedRequestSize && _feedCapacity + size >= _currentFeedRequestSize)
_monitor.notify();
2)生产者
DecoderFileThread::DecoderFileThread(const char* path, BytesBufferPtr buffer)
: filepath(path)
, _buffer(buffer)
, _destroy(false)
, _decodeState() , file()
{
_cbChunk._userData = this;
_cbChunk._callback = DecoderFileThread::feedCallback;
} void DecoderFileThread::run()
{
_decodeState = Decoder_Interface_init();
file = fopen(filepath.c_str(), "rb");
fseek(file, , );
do {
_buffer->feed(*, &_cbChunk);
} while (!_destroy);
Decoder_Interface_exit(_decodeState);
fclose(file);
//SP::printf("\nfinish decode file\n");
}
3)消费者
OSStatus AudioPlayUnit_context::playbackCallback(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData) {
#if !TEST
// Notes: ioData contains buffers (may be more than one!)
// Fill them up as much as you can. Remember to set the size value in each buffer to match how
// much data is in the buffer.
AudioPlayUnit_context* This = (AudioPlayUnit_context*)inRefCon; RenderChunk cbchunk = {};
cbchunk.inRefCon = This;
cbchunk.ioActionFlags = ioActionFlags;
cbchunk.inTimeStamp = inTimeStamp;
cbchunk.inBusNumber = inBusNumber;
cbchunk.inNumberFrames = inNumberFrames;
cbchunk.ioData = ioData; BufferChunk chunk;
chunk._callback = AudioPlayUnit_context::eatCallback;
chunk._userData = &cbchunk;
This->_buffer->eat(inNumberFrames*This->_audioFormat.mBytesPerFrame, &chunk); static size_t expired = ;
static IceUtil::Time lasttime;
if(This->_renderstartTimestamp == )
{
This->_renderstartTimestamp = IceUtil::Time::now().toMilliSeconds();
expired = ;
}
else
expired = IceUtil::Time::now().toMilliSeconds() - This->_renderstartTimestamp; if (This->_listenerPtr.get()) This->_listenerPtr->progress(This->_listenerPtr->userData, expired);
return noErr;
#else AudioPlayUnit_context* This = (AudioPlayUnit_context*)inRefCon;
static size_t pos = ;
ioData->mBuffers[].mData = This->_filebuffer + pos;
pos += inNumberFrames*;
//bytes2HexS((unsigned char*)ioData->mBuffers[0].mData, inNumberFrames*2);
return noErr;
#endif
}
5.ice
unix网络编程(卷2)7.3小节描述了生产者-消费者问题,7.5小节描述了条件变量
iceutil的monitor就是cpp的封装实现。
//
// This monitor implements the Mesa monitor semantics. That is any
// calls to notify() or notifyAll() are delayed until the monitor is
// unlocked.
//
template <class T>
class Monitor
{
6.引用计数
objective-c的引用计数很好理解,[[xx alloc] init]引用计数为1,retain引用计数加1,release引用计数减1,当引用计数为0时销毁内存。
ice的IceUtil::Shared包含了引用计数加1减1,但IceUtil::Shared在构造函数和析构函数并不会改变引用计数。使用时是使用IceUtil::Handle对象,IceUtil::Handle包含一个_ptr,构造函数如果参数为空,_prt置为null。如果构造函数的参数不为空,就会将_prt的引用计数加1,this->_ptr->__incRef(),析构函数会将_ptr的引用计数减1,this->_ptr->__decRef()。decRef函数判断引用计数为0时销毁内存。
IceUtril::Handle的拷贝构造函数和赋值函数也是将_ptr引用计数加1.因此有多个IceHandle包含同一个IceUtil::Shared,将IceUtil::Shared的引用计数加加减减。
IceUtil::Shared是用户自己new出来的,默认的引用计数为0,使用IceUtil::Handle时才会改变_ptr引用计数的值。
ace的ACE_Refcounted_Auto_Ptr_Rep包含了引用计数,内部包括一个auto_ptr的ptr_对象,构造函数会创建ptr_对象,析构时ptr_对象也会自动销毁,auto_ptr对象销毁时会释放new出来的内存。通过static函数attach,detach将引用计数加1减1,detach函数判断引用计数为0时销毁ACE_Refcounted_Auto_Ptr_Rep对象。
ace使用时是使用 ACE_Refcounted_Auto_Ptr,ACE_Refcounted_Auto_Ptr对象构造函数会创建ACE_Refcounted_Auto_Ptr_Rep对象rep_,析构函数会调用detach函数将rep_的引用计数减1.ACE_Refcounted_Auto_Ptr对象的拷贝构造函数和赋值函数也是将rep_引用计数加1.
因此有多个ACE_Refcounted_Auto_Ptr包含同一个ACE_Refcounted_Auto_Ptr_Rep,将ACE_Refcounted_Auto_Ptr_Rep的引用计数加加减减。
ACE_Refcounted_Auto_Ptr_Rep对象是ACE_Refcounted_Auto_Ptr对象构造函数创建的。使用ACE_Refcounted_Auto_Ptr时会改变rep_引用计数的值。
总结:
ace的ACE_Refcounted_Auto_Ptr不是很好理解,因为X *p并没有引用计数,所以需要封装一个ACE_Refcounted_Auto_Ptr_Rep对象,但ACE_Refcounted_Auto_Ptr_Rep对象又不是用户自己创建的,是构造函数自己创建的。 而构造函数中又没有通过ACE_Refcounted_Auto_Ptr_Rep对象来创建,这样就隐藏了ACE_Refcounted_Auto_Ptr_Rep对象的存在,让人不好理解。
第一步,创建ACE_Refcounted_Auto_Ptr_Rep对象,第二步使用ACE_Refcounted_Auto_Ptr。ace不让用户一步步完成。构造函数是通过X *p创建ACE_Refcounted_Auto_Ptr_Rep对象,拷贝构造函数和赋值函数是通过const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r的rep_引用计数加1。
而ice 因此如果需要将一个对象申明智能指针,必须让其继承至IceUtil::Shared,就好理解一点。
iceutil::Shared
class ICE_UTIL_API Shared
{
public: Shared();
Shared(const Shared&); virtual ~Shared()
{
} Shared& operator=(const Shared&)
{
return *this;
} virtual void __incRef();
virtual void __decRef();
virtual int __getRef() const;
virtual void __setNoDelete(bool); protected: #if defined(_WIN32)
LONG _ref;
#elif defined(ICE_HAS_ATOMIC_FUNCTIONS) || defined(ICE_HAS_GCC_BUILTINS)
volatile int _ref;
#else
int _ref;
Mutex _mutex;
#endif
bool _noDelete;
}; }
ace
template <class X, class ACE_LOCK> inline
ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr (X *p)
: rep_ (AUTO_REFCOUNTED_PTR_REP::create (p))
{
} template <class X, class ACE_LOCK> inline
ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::ACE_Refcounted_Auto_Ptr (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &r)
: rep_ (AUTO_REFCOUNTED_PTR_REP::attach (((ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &) r).rep_))
{
} template <class X, class ACE_LOCK> inline void
ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::operator = (const ACE_Refcounted_Auto_Ptr<X, ACE_LOCK> &rhs)
{
// bind <this> to the same <ACE_Refcounted_Auto_Ptr_Rep> as <r>.
AUTO_REFCOUNTED_PTR_REP *old_rep = this->rep_;
if (rhs.rep_ != )
{
this->rep_ = AUTO_REFCOUNTED_PTR_REP::attach
(const_cast<ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>& > (rhs).rep_);
if (this->rep_ != )
AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
}
else // Assign a 0 rep to this
{
AUTO_REFCOUNTED_PTR_REP::detach (old_rep);
this->rep_ = ;
}
} template <class X, class ACE_LOCK>
ACE_Refcounted_Auto_Ptr<X, ACE_LOCK>::~ACE_Refcounted_Auto_Ptr (void)
{
AUTO_REFCOUNTED_PTR_REP::detach (rep_);
}
7.书籍
http://bestcbooks.com/recommended-cpp-books/
第3月第2天 find symbolicatecrash 生产者-消费者 ice 引用计数的更多相关文章
- 2017年5月11日17:43:06 rabbitmq 消费者队列
从昨天开始发现个问题,一个接口在本地调用时大部分正常,一旦在生成者打一个断点调试,并且在promotion也打断点的时候会出现没有返回channel的异常,然后消费者就再也消费不了了 16:57:45 ...
- 4月25日 python学习总结 互斥锁 IPC通信 和 生产者消费者模型
一.守护进程 import random import time from multiprocessing import Process def task(): print('name: egon') ...
- 第21月第4天 leetcode codinginterview c++
1.leetcode Implement strStr(). Returns the index of the first occurrence of needle in haystack, or - ...
- 半个月使用rust语言的体验
从第一次下载rust语言的编译器到今天刚好第14天. 简单说一下对这个语言的感觉吧. 一.性能 把以前用java写的一个中文地址切分的算法,用rust重新实现了一下(https://github.co ...
- 本周MySQL官方verified/open的bug列表(11月8日至11月14日)
本周MySQL verified的bug列表(11月8日至11月14日) 1. Bug #70859-DWITH_EXAMPLE_STORAGE_ENGINE=1 is ignored URL ...
- java_面试_01_一个月的面试总结(java)
重点知识 由于我面试的JAVA开发工程师,针对于JAVA,需要理解的重点内容有: JVM内存管理机制和垃圾回收机制(基本每次面试都会问,一定要搞得透彻) JVM内存调优(了解是怎么回事,一般做项目过程 ...
- Android SDK 与API版本对应关系
Android SDK版本号 与 API Level 对应关系如下表: Code name Version API level (no code name) 1.0 API level 1 ( ...
- Linux基础介绍【第四篇】
Linux文件和目录的属性及权限 命令: [root@oldboy ~]# ls -lhi total 40K 24973 -rw-------. 1 root root 1.1K Dec 10 16 ...
- 转职成为TypeScript程序员的参考手册
写在前面 作者并没有任何可以作为背书的履历来证明自己写作这份手册的分量. 其内容大都来自于TypeScript官方资料或者搜索引擎获得,期间掺杂少量作者的私见,并会标明. 大部分内容来自于http:/ ...
随机推荐
- js事件绑定及深入
学习要点: 1.传统事件绑定的问题2.W3C事件处理函数3.IE事件处理函数4.事件对象的其他补充 事件绑定分为两种:一种是传统事件绑定(内联模型,脚本模型),一种是现代事件绑定(DOM2级模型).现 ...
- 3D游戏常用技巧Normal Mapping (法线贴图)原理解析——基础篇
http://www.cnblogs.com/wangchengfeng/p/3470310.html
- Oracle 中的伪列
昨天做了一个Oracle PL/SQL 相关的测试,其中有一道这样的题目: 下列那些是Oracle的伪列(ACD) A.ROWID B.ROW_NUMBER() C.LEVEL D.RO ...
- 关于包含pom.xml的开源项目如何导入
1. 开源项目导入eclipse的一般步骤 2. 使用Eclipse构建Maven项目 (step-by-step) 3. 第一次安装和使用maven
- Java里String.split需要注意的用法
我们常常用String的split()方法去分割字符串,有两个地方值得注意: 1. 当分隔符是句号时("."),需要转义: 由于String.split是基于正则表达式来分割字符串 ...
- JavaScript中的this陷阱的最全收集 没有之一
当有人问起你JavaScript有什么特点的时候,你可能立马就想到了单线程.事件驱动.面向对象等一堆词语,但是如果真的让你解释一下这些概 念,可能真解释不清楚.有句话这么说:如果你不能向一个6岁小孩解 ...
- MVC5 + EF6 + Bootstrap3 (16) 客户端验证
Slark.NET-博客园 http://www.cnblogs.com/slark/p/mvc5-ef6-bs3-get-started-client-side-validation.html 系列 ...
- node.js的安装环境搭建
.header { cursor: pointer } p { margin: 3px 6px } th { background: lightblue; width: 20% } table { t ...
- 跟我从零基础学习Unity3D开发--初识U3D
首先声明,我也是才开始学,把自己学的记录下来也供一些想要学习的朋友参考,一起努力.希望大家能给我指点一下.切莫喷我. 什么是Unity3d呢? 百度百科------Unity是由Unity Techn ...
- 建模算法(七)——排队论模型
(一)基本概念 一.排队过程的一般表示 凡是要求服务的对象称为顾客,凡是为顾客服务的称为服务员 二.排队系统的组成和特征 主要由输入过程.排队规则.服务过程三部分组成 三.排队模型的符号表示 1.X: ...