mirror of
https://github.com/openharmony/drivers_framework.git
synced 2026-08-27 20:49:55 -04:00
@@ -157,7 +157,7 @@ void HdfPmSetMode(struct HdfDeviceObject *deviceObject, uint32_t mode)
|
|||||||
|
|
||||||
bool HdfDeviceSetClass(struct HdfDeviceObject *deviceObject, DeviceClass deviceClass)
|
bool HdfDeviceSetClass(struct HdfDeviceObject *deviceObject, DeviceClass deviceClass)
|
||||||
{
|
{
|
||||||
if ((deviceObject == NULL) || (deviceClass >= DEVICE_CLASS_MAX) || (deviceClass >= DEVICE_CLASS_MAX)) {
|
if ((deviceObject == NULL) || (deviceClass >= DEVICE_CLASS_MAX)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
deviceObject->deviceClass = deviceClass;
|
deviceObject->deviceClass = deviceClass;
|
||||||
|
|||||||
@@ -884,11 +884,11 @@ std::shared_ptr<AstObject> AstObjectFactory::Build(std::shared_ptr<AstObject> ob
|
|||||||
{
|
{
|
||||||
switch (object->Type()) {
|
switch (object->Type()) {
|
||||||
case PARSEROP_CONFNODE:
|
case PARSEROP_CONFNODE:
|
||||||
return std::shared_ptr<AstObject>(new ConfigNode(*ConfigNode::CastFrom(object)));
|
return std::make_shared<ConfigNode>(*ConfigNode::CastFrom(object));
|
||||||
case PARSEROP_CONFTERM:
|
case PARSEROP_CONFTERM:
|
||||||
return std::shared_ptr<AstObject>(new ConfigTerm(*ConfigTerm::CastFrom(object)));
|
return std::make_shared<ConfigTerm>(*ConfigTerm::CastFrom(object));
|
||||||
case PARSEROP_ARRAY:
|
case PARSEROP_ARRAY:
|
||||||
return std::shared_ptr<AstObject>(new ConfigArray(*static_cast<ConfigArray *>(object.get())));
|
return std::make_shared<ConfigArray>(*ConfigArray::CastFrom(object));
|
||||||
default:
|
default:
|
||||||
return std::make_shared<AstObject>(*object);
|
return std::make_shared<AstObject>(*object);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ std::shared_ptr<Ast> Parser::ParseOne(const std::string &src, std::list<std::str
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Ast> oneAst = std::make_shared<Ast>(rootNode);
|
auto oneAst = std::make_shared<Ast>(rootNode);
|
||||||
oneAst->Dump(*lexer_.GetSourceName());
|
oneAst->Dump(*lexer_.GetSourceName());
|
||||||
|
|
||||||
return oneAst;
|
return oneAst;
|
||||||
@@ -145,7 +145,7 @@ std::shared_ptr<AstObject> Parser::ParseNode(Token &name, bool bracesStart)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto node = std::shared_ptr<AstObject>(new ConfigNode(name, NODE_NOREF, ""));
|
auto node = std::make_shared<ConfigNode>(name, NODE_NOREF, "");
|
||||||
std::shared_ptr<AstObject> child;
|
std::shared_ptr<AstObject> child;
|
||||||
while (lexer_.Lex(current_) && current_ != '}') {
|
while (lexer_.Lex(current_) && current_ != '}') {
|
||||||
switch (current_.type) {
|
switch (current_.type) {
|
||||||
@@ -171,7 +171,7 @@ std::shared_ptr<AstObject> Parser::ParseNode(Token &name, bool bracesStart)
|
|||||||
Logger().Error() << lexer_ << "syntax error, node miss '}'";
|
Logger().Error() << lexer_ << "syntax error, node miss '}'";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return std::shared_ptr<AstObject>(node);
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<AstObject> Parser::ParseTerm(Token &name)
|
std::shared_ptr<AstObject> Parser::ParseTerm(Token &name)
|
||||||
@@ -180,10 +180,7 @@ std::shared_ptr<AstObject> Parser::ParseTerm(Token &name)
|
|||||||
Logger().Error() << lexer_ << "syntax error, miss value of config term";
|
Logger().Error() << lexer_ << "syntax error, miss value of config term";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto term = std::shared_ptr<AstObject>(new (std::nothrow) ConfigTerm(name, nullptr));
|
auto term = std::make_shared<ConfigTerm>(name, nullptr);
|
||||||
if (term == nullptr) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
switch (current_.type) {
|
switch (current_.type) {
|
||||||
case STRING:
|
case STRING:
|
||||||
term->AddChild(std::make_shared<AstObject>("", PARSEROP_STRING, current_.strval, current_));
|
term->AddChild(std::make_shared<AstObject>("", PARSEROP_STRING, current_.strval, current_));
|
||||||
@@ -220,7 +217,7 @@ std::shared_ptr<AstObject> Parser::ParseTerm(Token &name)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::shared_ptr<AstObject>(term);
|
return term;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<AstObject> Parser::ParseTemplate()
|
std::shared_ptr<AstObject> Parser::ParseTemplate()
|
||||||
@@ -362,7 +359,7 @@ std::shared_ptr<AstObject> Parser::ParseNodeInherit(Token &name)
|
|||||||
|
|
||||||
std::shared_ptr<AstObject> Parser::ParseArray()
|
std::shared_ptr<AstObject> Parser::ParseArray()
|
||||||
{
|
{
|
||||||
auto array = std::shared_ptr<AstObject>(new ConfigArray(current_));
|
auto array = std::make_shared<ConfigArray>(current_);
|
||||||
int32_t arrayType = 0;
|
int32_t arrayType = 0;
|
||||||
|
|
||||||
while (lexer_.Lex(current_) && current_ != ']') {
|
while (lexer_.Lex(current_) && current_ != ']') {
|
||||||
@@ -400,7 +397,7 @@ std::shared_ptr<AstObject> Parser::ParseArray()
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::shared_ptr<AstObject>(array);
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Ast> Parser::GetAst()
|
std::shared_ptr<Ast> Parser::GetAst()
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ void AST::SetIdlFile(const String& idlFile)
|
|||||||
#else
|
#else
|
||||||
int index = idlFilePath_.LastIndexOf('/');
|
int index = idlFilePath_.LastIndexOf('/');
|
||||||
#endif
|
#endif
|
||||||
int end = (idlFilePath_.LastIndexOf(".idl") == -1) ?
|
int end = idlFilePath_.LastIndexOf(".idl");
|
||||||
(idlFilePath_.LastIndexOf(".idl")) : (idlFilePath_.LastIndexOf(".idl"));
|
|
||||||
name_ = idlFilePath_.Substring((index == -1) ? 0 : (index + 1), end);
|
name_ = idlFilePath_.Substring((index == -1) ? 0 : (index + 1), end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ void FileDetail::SetFilePath(const String& filePath)
|
|||||||
#else
|
#else
|
||||||
int index = idlFilePath_.LastIndexOf('/');
|
int index = idlFilePath_.LastIndexOf('/');
|
||||||
#endif
|
#endif
|
||||||
int end = ((idlFilePath_.LastIndexOf(".idl") == -1) ?
|
int end = idlFilePath_.LastIndexOf(".idl");
|
||||||
idlFilePath_.LastIndexOf(".idl") : idlFilePath_.LastIndexOf(".idl"));
|
|
||||||
idlName_ = idlFilePath_.Substring((index == -1) ? 0 : (index + 1), end);
|
idlName_ = idlFilePath_.Substring((index == -1) ? 0 : (index + 1), end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ static ParserObject *HcsLookupAstObject(const ParserObject *current, const char
|
|||||||
HCS_ERROR("oom");
|
HCS_ERROR("oom");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
char *nodeName = strtok(splitPath, ".");
|
char *buf = NULL;
|
||||||
|
char *nodeName = strtok_s(splitPath, ".", &buf);
|
||||||
|
|
||||||
/* path must start with "root" */
|
/* path must start with "root" */
|
||||||
if (nodeName == NULL || strcmp(nodeName, "root") != 0) {
|
if (nodeName == NULL || strcmp(nodeName, "root") != 0) {
|
||||||
@@ -34,14 +35,14 @@ static ParserObject *HcsLookupAstObject(const ParserObject *current, const char
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* skip root in path */
|
/* skip root in path */
|
||||||
nodeName = strtok(NULL, ".");
|
nodeName = strtok_s(NULL, ".", &buf);
|
||||||
ParserObject *object = HcsGetParserRoot();
|
ParserObject *object = HcsGetParserRoot();
|
||||||
while (nodeName != NULL) {
|
while (nodeName != NULL) {
|
||||||
object = HcsAstLookupObjectInChildren(object, nodeName);
|
object = HcsAstLookupObjectInChildren(object, nodeName);
|
||||||
if (object == NULL) {
|
if (object == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
nodeName = strtok(NULL, ".");
|
nodeName = strtok_s(NULL, ".", &buf);
|
||||||
}
|
}
|
||||||
HcsMemFree(splitPath);
|
HcsMemFree(splitPath);
|
||||||
|
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021-2021 Huawei Device Co., Ltd.
|
|
||||||
*
|
|
||||||
* HDF is dual licensed: you can use it either under the terms of
|
|
||||||
* the GPL, or the BSD license, at your option.
|
|
||||||
* See the LICENSE file in the root of this repository for complete details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef OBJECT_ALLOC_H
|
|
||||||
#define OBJECT_ALLOC_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct HdfObjectChunkConfig {
|
|
||||||
uint32_t chunkSize;
|
|
||||||
uint32_t chunkCount;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct HdfObjectPoolConfig {
|
|
||||||
char *buffer;
|
|
||||||
uint32_t bufferSize;
|
|
||||||
uint32_t numChunks;
|
|
||||||
const struct HdfObjectChunkConfig *chunks;
|
|
||||||
};
|
|
||||||
|
|
||||||
void *HdfObjectAllocAlloc(size_t size);
|
|
||||||
|
|
||||||
void HdfObjectAllocFree(void *object);
|
|
||||||
|
|
||||||
const struct HdfObjectPoolConfig *ObjectAllocGetConfig(void);
|
|
||||||
void HdfObjectAllocInit(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
#endif /* BLOCK_BUFFER_H */
|
|
||||||
|
|
||||||
@@ -1,189 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
|
||||||
*
|
|
||||||
* HDF is dual licensed: you can use it either under the terms of
|
|
||||||
* the GPL, or the BSD license, at your option.
|
|
||||||
* See the LICENSE file in the root of this repository for complete details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "hdf_object_alloc.h"
|
|
||||||
#include "hdf_slist.h"
|
|
||||||
#include "osal_mutex.h"
|
|
||||||
|
|
||||||
struct HdfChunkLink {
|
|
||||||
uint32_t buffSize;
|
|
||||||
uint8_t *buffer;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct HdfObjectNode {
|
|
||||||
struct HdfSListNode entry;
|
|
||||||
uint32_t chunkCount;
|
|
||||||
uint32_t freeCount;
|
|
||||||
uint32_t chunkSize;
|
|
||||||
struct HdfChunkLink **chunkStack;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct HdfObjectAlloc {
|
|
||||||
struct HdfSList nodes;
|
|
||||||
struct OsalMutex mutex;
|
|
||||||
bool isConstructed;
|
|
||||||
};
|
|
||||||
static const unsigned int ALIGN_MASK = 3;
|
|
||||||
#define ALIGN4(x) (uint32_t)(((uintptr_t)(x) + ALIGN_MASK) & (~ALIGN_MASK))
|
|
||||||
|
|
||||||
#define OBJECT_NODE_SIZE sizeof(struct ObjectNode)
|
|
||||||
#define OBJECT_CHUNK_COOKIE_SIZE (sizeof(struct ChunkLink) + sizeof(void *))
|
|
||||||
|
|
||||||
void HdfObjectAllocConstruct(struct HdfObjectAlloc *alloc)
|
|
||||||
{
|
|
||||||
HdfSListInit(&alloc->nodes);
|
|
||||||
OsalMutexInit(&alloc->mutex);
|
|
||||||
alloc->isConstructed = true;
|
|
||||||
}
|
|
||||||
struct HdfObjectAlloc *HdfObjectAllocGetInstance(void)
|
|
||||||
{
|
|
||||||
static struct HdfObjectAlloc instance = { 0 };
|
|
||||||
|
|
||||||
if (!instance.isConstructed) {
|
|
||||||
HdfObjectAllocConstruct(&instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
return &instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct HdfObjectNode *HdfObjectAllocFindSuitableChunk(
|
|
||||||
struct HdfObjectAlloc *alloc, size_t size)
|
|
||||||
{
|
|
||||||
struct HdfSListIterator it;
|
|
||||||
struct HdfObjectNode *bestFitNode = NULL;
|
|
||||||
struct HdfObjectNode *objectNode = NULL;
|
|
||||||
HdfSListIteratorInit(&it, &alloc->nodes);
|
|
||||||
|
|
||||||
while (HdfSListIteratorHasNext(&it)) {
|
|
||||||
objectNode = (struct HdfObjectNode *)HdfSListIteratorNext(&it);
|
|
||||||
if (size == objectNode->chunkSize) {
|
|
||||||
bestFitNode = objectNode;
|
|
||||||
break;
|
|
||||||
} else if (size < objectNode->chunkSize) {
|
|
||||||
bestFitNode = objectNode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return bestFitNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void HdfObjectAllocPushObjectNode(
|
|
||||||
struct HdfObjectAlloc *alloc, struct HdfObjectNode *node)
|
|
||||||
{
|
|
||||||
struct HdfSListIterator it;
|
|
||||||
struct HdfObjectNode *objectNode = NULL;
|
|
||||||
HdfSListIteratorInit(&it, &alloc->nodes);
|
|
||||||
|
|
||||||
while (HdfSListIteratorHasNext(&it)) {
|
|
||||||
objectNode = (struct HdfObjectNode *)HdfSListIteratorNext(&it);
|
|
||||||
if (node->chunkSize >= objectNode->chunkSize) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HdfSListIteratorInsert(&it, &node->entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void HdfObjectAllocPreloadChunk(
|
|
||||||
void *chunkBuf, uint32_t buffSize, uint32_t chunkSize)
|
|
||||||
{
|
|
||||||
struct HdfObjectAlloc *allocator = HdfObjectAllocGetInstance();
|
|
||||||
|
|
||||||
if (buffSize > OBJECT_NODE_SIZE) {
|
|
||||||
uint32_t idx;
|
|
||||||
struct ChunkLink *chunkLink;
|
|
||||||
struct ObjectNode *node;
|
|
||||||
uint32_t alignedSize = ALIGN4(chunkSize);
|
|
||||||
uint32_t alignedBufSize = ALIGN4(buffSize);
|
|
||||||
uint32_t blockSize = alignedSize + sizeof(struct ChunkLink);
|
|
||||||
uint8_t *alignedBuff = (uint8_t *)(uintptr_t)ALIGN4(chunkBuf);
|
|
||||||
node = (struct ObjectNode *)(alignedBuff + alignedBufSize - OBJECT_NODE_SIZE);
|
|
||||||
node->freeCount = 0;
|
|
||||||
node->chunkSize = alignedSize;
|
|
||||||
node->chunkCount = ((uint8_t *)node - alignedBuff) / (blockSize + sizeof(void *));
|
|
||||||
node->chunkStack = (struct ChunkLink **)(alignedBuff + node->chunkCount * blockSize);
|
|
||||||
|
|
||||||
for (idx = 0; idx < node->chunkCount; idx++) {
|
|
||||||
chunkLink = (struct ChunkLink *)&alignedBuff[idx * blockSize];
|
|
||||||
chunkLink->buffSize = node->chunkSize;
|
|
||||||
node->chunkStack[node->freeCount++] = chunkLink;
|
|
||||||
chunkLink->buffer = (uint8_t *)(chunkLink + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
HdfObjectAllocPushObjectNode(allocator, node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HdfObjectAllocLoadConfigs(const struct HdfObjectPoolConfig *configs)
|
|
||||||
{
|
|
||||||
uint32_t idx;
|
|
||||||
char *chunkBuffBegin = configs->buffer;
|
|
||||||
char *chunkBuffEnd = configs->buffer + configs->bufferSize;
|
|
||||||
|
|
||||||
for (idx = 0; (idx < configs->numChunks) && (chunkBuffBegin < chunkBuffEnd); idx++) {
|
|
||||||
const struct ObjectChunkConfig *chunkConfig = &configs->chunks[idx];
|
|
||||||
size_t chunkBufSize = OBJECT_NODE_SIZE + \
|
|
||||||
(OBJECT_CHUNK_COOKIE_SIZE + chunkConfig->chunkSize) * chunkConfig->chunkCount;
|
|
||||||
|
|
||||||
if (chunkBuffBegin + chunkBufSize <= chunkBuffEnd) {
|
|
||||||
HdfObjectAllocPreloadChunk(chunkBuffBegin, chunkBufSize, chunkConfig->chunkSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
chunkBuffBegin += chunkBufSize;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HdfObjectAllocInit(void)
|
|
||||||
{
|
|
||||||
const struct HdfObjectPoolConfig *config = HdfObjectAllocGetConfig();
|
|
||||||
|
|
||||||
if (config != NULL) {
|
|
||||||
HdfObjectAllocLoadConfigs(config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void *HdfObjectAllocAlloc(size_t size)
|
|
||||||
{
|
|
||||||
struct HdfChunkLink *chunkLink = NULL;
|
|
||||||
struct HdfObjectNode *objectNode = NULL;
|
|
||||||
struct HdfObjectAlloc *allocator = HdfObjectAllocGetInstance();
|
|
||||||
OsalMutexLock(&allocator->mutex);
|
|
||||||
objectNode = HdfObjectAllocFindSuitableChunk(allocator, size);
|
|
||||||
if ((objectNode != NULL) && (objectNode->freeCount == 0)) {
|
|
||||||
goto finished;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (objectNode->freeCount > objectNode->chunkCount) {
|
|
||||||
if (objectNode->freeCount > objectNode->chunkCount) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
chunkLink = (struct ChunkLink *)objectNode->chunkStack[--objectNode->freeCount];
|
|
||||||
finished:
|
|
||||||
OsalMutexUnlock(&allocator->mutex);
|
|
||||||
return chunkLink ? chunkLink->buffer : NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HdfObjectAllocFree(void *object)
|
|
||||||
{
|
|
||||||
struct HdfChunkLink *chunkLink = container_of(void, object, struct ChunkLink, buffer);
|
|
||||||
struct HdfObjectNode *objectNode = NULL;
|
|
||||||
struct HdfObjectAlloc *allocator = HdfObjectAllocGetInstance();
|
|
||||||
OsalMutexLock(&allocator->mutex);
|
|
||||||
objectNode = HdfObjectAllocFindSuitableChunk(allocator, chunkLink->buffSize);
|
|
||||||
if (objectNode != NULL) {
|
|
||||||
objectNode->chunkStack[objectNode->freeCount++] = chunkLink;
|
|
||||||
|
|
||||||
if (objectNode->freeCount > objectNode->chunkCount) {
|
|
||||||
HDF_LOGE("exception: count,free:%d,total %d", objectNode->freeCount, objectNode->chunkCount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
OsalMutexUnlock(&allocator->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user