#ifndefRTX_LIB_H_#defineRTX_LIB_H_#include<string.h>#include<stdint.h>#include"stm32h7xx.h"// Memory Pool Header structuretypedefstruct{uint32_t size;// Memory Pool sizeuint32_t used;// Used Memory}mem_head_t;// Memory Block Header structuretypedefstructmem_block_s{structmem_block_s*next;// Next Memory Block in listuint32_t info;// Block Info or max used Memory (in last block)}mem_block_t;// Memory Block Info: Length = <31:2>:'00', Type = <1:0>#defineMB_INFO_LEN_MASK0xFFFFFFFCU// Length mask#defineMB_INFO_TYPE_MASK0x00000003U// Type mask// Memory Head Pointer
__STATIC_INLINE mem_head_t*MemHeadPtr(void*mem){//lint -e{9079} -e{9087} "conversion from pointer to void to pointer to other type" [MISRA Note 6]return((mem_head_t*)mem);}// Memory Block Pointer
__STATIC_INLINE mem_block_t*MemBlockPtr(void*mem,uint32_t offset){uint32_t addr;mem_block_t*ptr;//lint --e{923} --e{9078} "cast between pointer and unsigned int" [MISRA Note 8]addr =(uint32_t)mem + offset;ptr =(mem_block_t*)addr;return ptr;}// ==== Library functions ====// Memory Heap Library functionsexternuint32_tosRtxMemoryInit(void*mem,uint32_t size);externvoid*osRtxMemoryAlloc(void*mem,uint32_t size,uint32_t type);externuint32_tosRtxMemoryFree(void*mem,void*block);#endif// RTX_LIB_H_
rtx_memory.c
#include"rtx_lib.h"// ==== Library functions ====/// Initialize Memory Pool with variable block size./// \param[in] mem pointer to memory pool./// \param[in] size size of a memory pool in bytes./// \return 1 - success, 0 - failure.
__WEAK uint32_tosRtxMemoryInit(void*mem,uint32_t size){mem_head_t*head;mem_block_t*ptr;// Check parameters//lint -e{923} "cast from pointer to unsigned int" [MISRA Note 7]if((mem ==NULL)||(((uint32_t)mem &7U)!=0U)||((size &7U)!=0U)||(size <(sizeof(mem_head_t)+(2U*sizeof(mem_block_t))))){//EvrRtxMemoryInit(mem, size, 0U);//lint -e{904} "Return statement before end of function" [MISRA Note 1]return0U;}// Initialize memory pool headerhead =MemHeadPtr(mem);head->size = size;head->used =sizeof(mem_head_t)+sizeof(mem_block_t);// Initialize first and last block headerptr =MemBlockPtr(mem,sizeof(mem_head_t));ptr->next =MemBlockPtr(mem, size -sizeof(mem_block_t));ptr->next->next =NULL;ptr->next->info =sizeof(mem_head_t)+sizeof(mem_block_t);ptr->info =0U;//EvrRtxMemoryInit(mem, size, 1U);return1U;}/// Allocate a memory block from a Memory Pool./// \param[in] mem pointer to memory pool./// \param[in] size size of a memory block in bytes./// \param[in] type memory block type: 0 - generic, 1 - control block/// \return allocated memory block or NULL in case of no memory is available.
__WEAK void*osRtxMemoryAlloc(void*mem,uint32_t size,uint32_t type){mem_block_t*ptr;mem_block_t*p,*p_new;uint32_t block_size;uint32_t hole_size;// Check parametersif((mem ==NULL)||(size ==0U)||((type &~MB_INFO_TYPE_MASK)!=0U)){//EvrRtxMemoryAlloc(mem, size, type, NULL);//lint -e{904} "Return statement before end of function" [MISRA Note 1]returnNULL;}// Add block header to sizeblock_size = size +sizeof(mem_block_t);// Make sure that block is 8-byte alignedblock_size =(block_size +7U)&~((uint32_t)7U);// Search for hole big enoughp =MemBlockPtr(mem,sizeof(mem_head_t));for(;;){//lint -e{923} -e{9078} "cast from pointer to unsigned int"hole_size =(uint32_t)p->next -(uint32_t)p;hole_size -= p->info & MB_INFO_LEN_MASK;if(hole_size >= block_size){// Hole foundbreak;}p = p->next;if(p->next ==NULL){// Failed (end of list)//EvrRtxMemoryAlloc(mem, size, type, NULL);//lint -e{904} "Return statement before end of function" [MISRA Note 1]returnNULL;}}// Update used memory(MemHeadPtr(mem))->used += block_size;// Update max used memoryp_new =MemBlockPtr(mem,(MemHeadPtr(mem))->size -sizeof(mem_block_t));if(p_new->info <(MemHeadPtr(mem))->used){p_new->info =(MemHeadPtr(mem))->used;}// Allocate blockif(p->info ==0U){// No block allocated, set info of first elementp->info = block_size | type;ptr =MemBlockPtr(p,sizeof(mem_block_t));}else{// Insert new element into the listp_new =MemBlockPtr(p, p->info & MB_INFO_LEN_MASK);p_new->next = p->next;p_new->info = block_size | type;p->next = p_new;ptr =MemBlockPtr(p_new,sizeof(mem_block_t));}//EvrRtxMemoryAlloc(mem, size, type, ptr);return ptr;}/// Return an allocated memory block back to a Memory Pool./// \param[in] mem pointer to memory pool./// \param[in] block memory block to be returned to the memory pool./// \return 1 - success, 0 - failure.
__WEAK uint32_tosRtxMemoryFree(void*mem,void*block){constmem_block_t*ptr;mem_block_t*p,*p_prev;// Check parametersif((mem ==NULL)||(block ==NULL)){//EvrRtxMemoryFree(mem, block, 0U);//lint -e{904} "Return statement before end of function" [MISRA Note 1]return0U;}// Memory block headerptr =MemBlockPtr(block,0U);ptr--;// Search for block headerp_prev =NULL;p =MemBlockPtr(mem,sizeof(mem_head_t));while(p != ptr){p_prev = p;p = p->next;if(p ==NULL){// Not found//EvrRtxMemoryFree(mem, block, 0U);//lint -e{904} "Return statement before end of function" [MISRA Note 1]return0U;}}// Update used memory(MemHeadPtr(mem))->used -= p->info & MB_INFO_LEN_MASK;// Free blockif(p_prev ==NULL){// Release first block, only set info to 0p->info =0U;}else{// Discard block from chained listp_prev->next = p->next;}//EvrRtxMemoryFree(mem, block, 1U);return1U;}
HashMap class Solution {public int[] twoSum(int[] nums, int target) {int a 0, b 0; // 返回两个索引HashMap<Integer, Integer> hm new HashMap<>(); // key是值,value是索引for (int i 0; i < nums.length; i) {if (!hm.containsKey(nums[…
P1596 [USACO10OCT] Lake Counting S - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) #include<bits/stdc.h>
using namespace std;
const int N110;
int m,n;
char g[N][N];
bool st[N][N]; //走/没走
int dx[] {-1,-1,-1,0,0,1,1,1}; //八联通
int dy[] {-1,0,1,1,-1,1…
docker:chown socket at step GROUP: No such process 原因:docker无法找到Group组信息,docker组有可能被误删除, 解决方式: groupadd docker
Docker是一种相对使用较简单的容器,我们可以通过以下几种方式获取信息&am…