android_device_samsung_msm8.../sensors/SensorEventQueue.cpp

92 lines
2.5 KiB
C++
Raw Normal View History

/*
* Copyright (C) 2013 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.
*/
[SQUASH]: initial bringup of samsung msm8226-common repo from msm8974-common * Rename msm8974-common -> msm8226-common * Import the old msm8226-common camera wrapper and apply : - https://github.com/LineageOS/android_device_samsung_klte-common/commit/45e3438b260dba2d08ad9a83ea95fa27595c8f8a#diff-dd6d2dcc679d12b9430a9787bab45b33 - https://github.com/LineageOS/android_device_samsung_klte-common/commit/737bd8c3960c43ab846a3320856d966a02dea898#diff-dd6d2dcc679d12b9430a9787bab45b33 - https://github.com/LineageOS/android_device_samsung_klte-common/commit/a79e72b246801dbd8cf031361834965d17ab1a01#diff-dd6d2dcc679d12b9430a9787bab45b33 - https://github.com/LineageOS/android_device_samsung_klte-common/commit/d4dadbaff0acc18a5482325e148f7581b0118845#diff-dd6d2dcc679d12b9430a9787bab45b33 - https://github.com/LineageOS/android_device_samsung_klte-common/commit/c2eb30c314e45e7f244f131d5483148ee8f1e22d#diff-dd6d2dcc679d12b9430a9787bab45b33 - https://github.com/LineageOS/android_device_samsung_klte-common/commit/9ac995b9019be031468f857e795b6bd0b6ae24b4#diff-dd6d2dcc679d12b9430a9787bab45b33 * Remove msm8974 keylayout in favour of msm8226 ones * Add wifi/prima relate configs for Qualcomm WIFI * Import libwncss from our old msm8226-common branch * Remove AvancedDisplay overlay as our panel does not support mDNIe * Import rootdir files from stock SM-G800H release, rework it taking as example klte one and import stock ondemand governor parameters * Adapt seccomp policy for msm8226 * Adapt sensor multihal for msm8226 * Adapt sepolicy for msm8226-common
2019-10-07 08:07:36 +00:00
#include <hardware/sensors.h>
#include <algorithm>
[SQUASH]: initial bringup of samsung msm8226-common repo from msm8974-common * Rename msm8974-common -> msm8226-common * Import the old msm8226-common camera wrapper and apply : - https://github.com/LineageOS/android_device_samsung_klte-common/commit/45e3438b260dba2d08ad9a83ea95fa27595c8f8a#diff-dd6d2dcc679d12b9430a9787bab45b33 - https://github.com/LineageOS/android_device_samsung_klte-common/commit/737bd8c3960c43ab846a3320856d966a02dea898#diff-dd6d2dcc679d12b9430a9787bab45b33 - https://github.com/LineageOS/android_device_samsung_klte-common/commit/a79e72b246801dbd8cf031361834965d17ab1a01#diff-dd6d2dcc679d12b9430a9787bab45b33 - https://github.com/LineageOS/android_device_samsung_klte-common/commit/d4dadbaff0acc18a5482325e148f7581b0118845#diff-dd6d2dcc679d12b9430a9787bab45b33 - https://github.com/LineageOS/android_device_samsung_klte-common/commit/c2eb30c314e45e7f244f131d5483148ee8f1e22d#diff-dd6d2dcc679d12b9430a9787bab45b33 - https://github.com/LineageOS/android_device_samsung_klte-common/commit/9ac995b9019be031468f857e795b6bd0b6ae24b4#diff-dd6d2dcc679d12b9430a9787bab45b33 * Remove msm8974 keylayout in favour of msm8226 ones * Add wifi/prima relate configs for Qualcomm WIFI * Import libwncss from our old msm8226-common branch * Remove AvancedDisplay overlay as our panel does not support mDNIe * Import rootdir files from stock SM-G800H release, rework it taking as example klte one and import stock ondemand governor parameters * Adapt seccomp policy for msm8226 * Adapt sensor multihal for msm8226 * Adapt sepolicy for msm8226-common
2019-10-07 08:07:36 +00:00
#include <pthread.h>
#include <log/log.h>
#include "SensorEventQueue.h"
SensorEventQueue::SensorEventQueue(int capacity) {
mCapacity = capacity;
mStart = 0;
mSize = 0;
mData = new sensors_event_t[mCapacity];
pthread_cond_init(&mSpaceAvailableCondition, NULL);
}
SensorEventQueue::~SensorEventQueue() {
delete[] mData;
mData = NULL;
pthread_cond_destroy(&mSpaceAvailableCondition);
}
int SensorEventQueue::getWritableRegion(int requestedLength, sensors_event_t** out) {
if (mSize == mCapacity || requestedLength <= 0) {
*out = NULL;
return 0;
}
// Start writing after the last readable record.
int firstWritable = (mStart + mSize) % mCapacity;
int lastWritable = firstWritable + requestedLength - 1;
// Don't go past the end of the data array.
if (lastWritable > mCapacity - 1) {
lastWritable = mCapacity - 1;
}
// Don't go into the readable region.
if (firstWritable < mStart && lastWritable >= mStart) {
lastWritable = mStart - 1;
}
*out = &mData[firstWritable];
return lastWritable - firstWritable + 1;
}
void SensorEventQueue::markAsWritten(int count) {
mSize += count;
}
int SensorEventQueue::getSize() {
return mSize;
}
sensors_event_t* SensorEventQueue::peek() {
if (mSize == 0) return NULL;
return &mData[mStart];
}
void SensorEventQueue::dequeue() {
if (mSize == 0) return;
if (mSize == mCapacity) {
pthread_cond_broadcast(&mSpaceAvailableCondition);
}
mSize--;
mStart = (mStart + 1) % mCapacity;
}
// returns true if it waited, or false if it was a no-op.
bool SensorEventQueue::waitForSpace(pthread_mutex_t* mutex) {
bool waited = false;
while (mSize == mCapacity) {
waited = true;
pthread_cond_wait(&mSpaceAvailableCondition, mutex);
}
return waited;
}