哇小明 2014-08-11 03:26 采纳率: 0%
浏览 2070

Fence?android中的东西 你们有听说过吗?进来一起讨论下

fence,看过源代码的人肯定不会陌生,中文是栅栏的意思,用在android里好像是为了解决cpu调度时乱序的问题,也就是串行操作?? 我不清楚,有大神出来一起讨论下吗,小弟在研究surfaceflinger,里面太多fence 至今没搞清楚它的机制。。。。。而且网上一点资料都没有!!!让这个问答成为第一份资料吧,日后要是我研究有所结果定会分享!!

下面贴出它类的定义 :
在frameworks/native/include/ui 下

class Fence
: public LightRefBase, public Flattenable
{
public:
static const sp NO_FENCE;

// TIMEOUT_NEVER may be passed to the wait method to indicate that it
// should wait indefinitely for the fence to signal.
enum { TIMEOUT_NEVER = -1 };

// Construct a new Fence object with an invalid file descriptor.  This
// should be done when the Fence object will be set up by unflattening
// serialized data.
Fence();

// Construct a new Fence object to manage a given fence file descriptor.
// When the new Fence object is destructed the file descriptor will be
// closed.
Fence(int fenceFd);

// Check whether the Fence has an open fence file descriptor. Most Fence
// methods treat an invalid file descriptor just like a valid fence that
// is already signalled, so using this is usually not necessary.
bool isValid() const { return mFenceFd != -1; }

// wait waits for up to timeout milliseconds for the fence to signal.  If
// the fence signals then NO_ERROR is returned. If the timeout expires
// before the fence signals then -ETIME is returned.  A timeout of
// TIMEOUT_NEVER may be used to indicate that the call should wait
// indefinitely for the fence to signal.
status_t wait(unsigned int timeout);

// waitForever is a convenience function for waiting forever for a fence to
// signal (just like wait(TIMEOUT_NEVER)), but issuing an error to the
// system log and fence state to the kernel log if the wait lasts longer
// than a warning timeout.
// The logname argument should be a string identifying
// the caller and will be included in the log message.
status_t waitForever(const char* logname);

// merge combines two Fence objects, creating a new Fence object that
// becomes signaled when both f1 and f2 are signaled (even if f1 or f2 is
// destroyed before it becomes signaled).  The name argument specifies the
// human-readable name to associated with the new Fence object.
static sp<Fence> merge(const String8& name, const sp<Fence>& f1,
        const sp<Fence>& f2);

// Return a duplicate of the fence file descriptor. The caller is
// responsible for closing the returned file descriptor. On error, -1 will
// be returned and errno will indicate the problem.
int dup() const;

// getSignalTime returns the system monotonic clock time at which the
// fence transitioned to the signaled state.  If the fence is not signaled
// then INT64_MAX is returned.  If the fence is invalid or if an error
// occurs then -1 is returned.
nsecs_t getSignalTime() const;

// Flattenable interface
size_t getFlattenedSize() const;
size_t getFdCount() const;
status_t flatten(void*& buffer, size_t& size, int*& fds, size_t& count) const;
status_t unflatten(void const*& buffer, size_t& size, int const*& fds, size_t& count);

private:
// Only allow instantiation using ref counting.
friend class LightRefBase;
~Fence();

// Disallow copying
Fence(const Fence& rhs);
Fence& operator = (const Fence& rhs);
const Fence& operator = (const Fence& rhs) const;

int mFenceFd;

};

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?