Skip to content

Commit

Permalink
Merge pull request #15 from plos-clan/new-mtask
Browse files Browse the repository at this point in the history
New mtask
  • Loading branch information
min0911Y authored Dec 18, 2024
2 parents f1af2f2 + 603f434 commit 3c039d1
Show file tree
Hide file tree
Showing 100 changed files with 1,336 additions and 1,394 deletions.
2 changes: 2 additions & 0 deletions apps/pf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_binary(pf)
target_link_libraries(pf misc)
9 changes: 9 additions & 0 deletions apps/pf/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This code is released under the MIT License

#include <libc-base.h>
#include <sys.h>

int main(int argc, char **argv) {
mem_set(0x114514, 1);
return 0;
}
2 changes: 2 additions & 0 deletions cmake/disable-warning
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_flag("-Wno-compound-token-split-by-macro")
add_compile_flag("-Wno-pointer-integer-compare")
add_compile_flag("-Wno-pointer-bool-conversion")
add_compile_flag("-Wno-nan-infinity-disabled")
endif()
add_compile_flag("-Wno-address-of-packed-member")
add_compile_flag("-Wno-attributes")
4 changes: 2 additions & 2 deletions cmake/use-ubscan
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
implicit-integer-sign-change #
integer-divide-by-zero #
nonnull-attribute #
# null #
null #
nullability #
# pointer-overflow #
pointer-overflow #
return #
returns-nonnull-attribute #
shift #
Expand Down
33 changes: 17 additions & 16 deletions include/data-structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@
#ifdef __cplusplus
extern "C" {
#endif
#include "data-structure/array-list.h"
#include "data-structure/avltree.h"
#include "data-structure/atomic/event.h"
#include "data-structure/atomic/queue-mt.h"
#include "data-structure/base.h"
#include "data-structure/bitmap.h"
#include "data-structure/circular-buffer.h"
#include "data-structure/circular-queue.h"
#include "data-structure/event.h"
#include "data-structure/list.h"
#include "data-structure/mbitstream.h"
#include "data-structure/mstream.h"
#include "data-structure/queue-mt.h"
#include "data-structure/queue.h"
#include "data-structure/rbtree-strptr.h"
#include "data-structure/rbtree.h"
#include "data-structure/slist-strptr.h"
#include "data-structure/slist.h"
#include "data-structure/trie.h"
#include "data-structure/kernel/kqueue.h"
#include "data-structure/ordered-map/slist-strptr.h"
#include "data-structure/ordered-set/array-list.h"
#include "data-structure/ordered-set/bitmap.h"
#include "data-structure/ordered-set/circular-buffer.h"
#include "data-structure/ordered-set/circular-queue.h"
#include "data-structure/ordered-set/list.h"
#include "data-structure/ordered-set/mbitstream.h"
#include "data-structure/ordered-set/mstream.h"
#include "data-structure/ordered-set/queue.h"
#include "data-structure/ordered-set/slist.h"
#include "data-structure/sorted-map/avltree.h"
#include "data-structure/sorted-map/rbtree-strptr.h"
#include "data-structure/sorted-map/rbtree.h"
#include "data-structure/sorted-map/trie.h"
#ifdef __cplusplus
}
#endif
6 changes: 3 additions & 3 deletions include/data-structure.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Generated by macro 'mkheader'.
// This file is automatically generated, please do not modify it.
#pragma once
#include "data-structure/list.hpp"
#include "data-structure/queue.hpp"
#include "data-structure/rbtree.hpp"
#include "data-structure/ordered-set/list.hpp"
#include "data-structure/ordered-set/queue.hpp"
#include "data-structure/sorted-map/rbtree.hpp"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand Down
50 changes: 50 additions & 0 deletions include/data-structure/kernel/kqueue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once
#include <define.h>

#ifdef __cplusplus
# error "内核不允许使用 C++"
#endif

// 未完成

typedef struct kqueue {
void **buffer;
size_t head;
size_t tail;
size_t capacity;
size_t size;
} *kqueue_t;

finline void kqueue_init(kqueue_t queue, void **buffer, size_t capacity) {
queue->buffer = buffer;
queue->head = 0;
queue->tail = 0;
queue->capacity = capacity;
atom_store(&queue->size, 0);
}

finline bool kqueue_enqueue(kqueue_t queue, void *item) {
size_t size = atom_load(&queue->size);
if (size == queue->capacity) {
return false; // Queue is full
}
queue->buffer[queue->tail] = item;
queue->tail = (queue->tail + 1) % queue->capacity;
atom_add(&queue->size, 1);
return true;
}

finline bool kqueue_dequeue(kqueue_t queue, void **item) {
size_t size = atomic_load(&queue->size);
if (size == 0) {
return false; // Queue is empty
}
*item = queue->buffer[queue->head];
queue->head = (queue->head + 1) % queue->capacity;
atom_sub(&queue->size, 1);
return true;
}

finline size_t kqueue_size(kqueue_t queue) {
return atom_load(&queue->size);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#ifdef ALL_IMPLEMENTATION
# define SIZED_EVENT_IMPLEMENTATION
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand Down Expand Up @@ -34,6 +34,13 @@ extern avltree_t avltree_alloc(int32_t key, void *value) __THROW __attr_malloc;
*/
extern void avltree_free(avltree_t root) __THROW;

/**
*\brief 释放AVL树,并调用回调函数处理节点值
*\param[in] root 树的根节点
*\param[in] callback 回调函数指针,用于处理节点值
*/
extern void avltree_free_with(avltree_t root, void (*callback)(void *)) __THROW;

/**
*\brief 获取AVL树中指定键值的节点值指针
*\param[in] root 树的根节点
Expand Down Expand Up @@ -216,6 +223,14 @@ static void avltree_free(avltree_t root) noexcept {
free(root);
}

static void avltree_free_with(avltree_t root, void (*callback)(void *)) noexcept {
if (root == null) return;
avltree_free_with(root->left, callback);
avltree_free_with(root->right, callback);
if (callback) callback(root->value);
free(root);
}

static void *avltree_get(avltree_t root, int32_t key) noexcept {
while (root != null && root->key != key) {
if (key < root->key)
Expand Down Expand Up @@ -320,9 +335,9 @@ static avltree_t avltree_delete_with(avltree_t root, int32_t key,
if (root == null) { return null; }

if (key < root->key) {
root->left = avltree_delete(root->left, key);
root->left = avltree_delete_with(root->left, key, callback);
} else if (key > root->key) {
root->right = avltree_delete(root->right, key);
root->right = avltree_delete_with(root->right, key, callback);
} else {
if (root->left == null) {
if (callback) callback(root->value);
Expand All @@ -335,6 +350,7 @@ static avltree_t avltree_delete_with(avltree_t root, int32_t key,
free(root);
return temp;
} else {
if (callback) callback(root->value);
avltree_t temp = avltree_min(root->right);
root->key = temp->key;
root->value = temp->value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand All @@ -10,7 +10,7 @@
#ifdef RBTREE_SP_IMPLEMENTATION
# define SLIST_SP_IMPLEMENTATION
#endif
#include "slist-strptr.h"
#include "../ordered-map/slist-strptr.h"

#ifndef _RBTREE_ENUM_
# define _RBTREE_ENUM_
Expand Down Expand Up @@ -135,8 +135,8 @@ static rbtree_sp_t rbtree_sp_right_rotate(rbtree_sp_t root, rbtree_sp_t y) __THR
*\param[in] v 替换后的子树根节点
*\return 替换后的树的根节点
*/
static rbtree_sp_t rbtree_sp_transplant(rbtree_sp_t root, rbtree_sp_t u, rbtree_sp_t v)
__THROW __wur;
static rbtree_sp_t rbtree_sp_transplant(rbtree_sp_t root, rbtree_sp_t u, rbtree_sp_t v) __THROW
__wur;

/**
*\brief 执行插入操作后修复红黑树性质
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "base.h"
#include "../base.h"

#pragma GCC system_header

Expand Down
3 changes: 3 additions & 0 deletions include/define/define/assert.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// This code is released under the MIT License

#pragma once

#pragma GCC system_header

#include "00-include.h"

#ifndef __cplusplus
Expand Down
3 changes: 3 additions & 0 deletions include/define/define/assert.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// This code is released under the MIT License

#pragma once

#pragma GCC system_header

#include "00-include.hpp"

#define assert_type_is_int(T) static_assert(std::is_integral_v<T>, "类型 " #T " 必须是整数")
Expand Down
3 changes: 3 additions & 0 deletions include/define/define/attribute.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// This code is released under the MIT License

#pragma once

#pragma GCC system_header

#include "00-include.h"

// 部分数据结构不应该有 padding
Expand Down
5 changes: 5 additions & 0 deletions include/define/define/base.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// This code is released under the MIT License

#pragma once

#pragma GCC system_header

#include "00-include.h"

// 获取数组的长度
Expand All @@ -11,6 +14,8 @@
// 获取表达式的类型,类似于 auto
#define typeof(arg) __typeof__((void)0, arg)

#define offsetof(t, d) __builtin_offsetof(t, d)

#define alloca(size) __builtin_alloca(size)

#if NO_BUILTIN
Expand Down
Loading

0 comments on commit 3c039d1

Please sign in to comment.