Files
android_device_google_conte…/util/common/ring.h
Peng Xu cf5df9cf40 Implement sensor direct report mode
This change implements direct report for accel, gyro and mag at normal
and fast rate level. It supports ashmem shared memory.

The direct report and traditional sensor subscription are still
tangled up in this implementation.

Bug: 30985702
Bug: 33588372
Test: tested via demo app

Change-Id: Idc4f626dfe624558718c1b04f16898a0ea247e62
2017-01-24 22:50:14 +00:00

64 lines
1.5 KiB
C++

/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef RING_BUFFER_H_
#define RING_BUFFER_H_
#include <media/stagefright/foundation/ABase.h>
#include <hardware/sensors.h>
#include <utils/threads.h>
namespace android {
struct RingBuffer {
explicit RingBuffer(size_t size);
~RingBuffer();
ssize_t write(const sensors_event_t *ev, size_t size);
ssize_t read(sensors_event_t *ev, size_t size);
private:
Mutex mLock;
Condition mNotEmptyCondition;
size_t mSize;
sensors_event_t *mData;
size_t mReadPos, mWritePos;
DISALLOW_EVIL_CONSTRUCTORS(RingBuffer);
};
struct LockfreeBuffer {
LockfreeBuffer(void* buf, size_t size);
~LockfreeBuffer();
// support single writer
void write(const sensors_event_t *ev, size_t size);
private:
sensors_event_t *mData;
size_t mSize;
size_t mWritePos;
int32_t mCounter;
DISALLOW_EVIL_CONSTRUCTORS(LockfreeBuffer);
};
} // namespace android
#endif // RING_BUFFER_H_