哇小明 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条回答

    报告相同问题?

    悬赏问题

    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
    • ¥15 再不同版本的系统上,TCP传输速度不一致
    • ¥15 高德地图点聚合中Marker的位置无法实时更新
    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程