Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ctime] fixup of data racing #8187

Merged
merged 5 commits into from
Oct 26, 2023
Merged

Conversation

polarvid
Copy link
Contributor

@polarvid polarvid commented Oct 25, 2023

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

Fixup of data racing in shared timer id list of ctime.c

你的解决方案是什么 (what is your solution)

在什么测试环境下测试通过 (what is the test environment)

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification

components/libc/compilers/common/ctime.c Outdated Show resolved Hide resolved
components/libc/compilers/common/ctime.c Outdated Show resolved Hide resolved
include/rthw.h Outdated Show resolved Hide resolved
include/rtthread.h Outdated Show resolved Hide resolved
@polarvid polarvid force-pushed the shell/fix-ctime branch 2 times, most recently from 39a94d0 to 0178e2a Compare October 25, 2023 12:32
@polarvid
Copy link
Contributor Author

polarvid commented Oct 25, 2023

现在定义更乱了……

rt-thread/include/rtdef.h

Lines 495 to 514 in 3283f54

struct rt_spinlock
{
rt_hw_spinlock_t lock;
#if defined(RT_DEBUGING_SPINLOCK)
void *owner;
void *pc;
#endif /* RT_DEBUGING_SPINLOCK */
};
typedef struct rt_spinlock rt_spinlock_t;
#ifndef RT_SPINLOCK_INIT
#define RT_SPINLOCK_INIT {{0}} // default
#endif /* RT_SPINLOCK_INIT */
#else
typedef rt_ubase_t rt_spinlock_t;
struct rt_spinlock
{
rt_spinlock_t lock;
};

一下是

typedef struct rt_spinlock rt_spinlock_t;
 struct rt_spinlock 
 { 
     rt_hw_spinlock_t lock;
 }; 

非 SMP 又是

 typedef rt_ubase_t rt_spinlock_t;
 struct rt_spinlock 
 { 
     rt_spinlock_t lock; 
 };

让人摸不着头脑

@xqyjlj
Copy link
Contributor

xqyjlj commented Oct 26, 2023

非smp时, rt_spinlock_t 的值就会通过宏传到rt_hw_interrupt_enable(level)里面去,所以非smp的rt_spinlock_t 就得是个常量

@xqyjlj
Copy link
Contributor

xqyjlj commented Oct 26, 2023

很久以前就是这种用法了,我尝试改过,结果非smp上面根本行不通

image

@polarvid
Copy link
Contributor Author

非smp时, rt_spinlock_t 的值就会通过宏传到rt_hw_interrupt_enable(level)里面去,所以非smp的rt_spinlock_t 就得是个常量

先不讨论具体怎么改。从原则来说,如果改 rt_spinlock_t 为结构体在非 SMP 遇到使用的问题,也得是纠正错误的用法呀。非 SMP 的时候当作整型来用,这种设计不是很合理。这样搞下去,代码会越来越乱,到处是莫名其妙的兼容逻辑。

@Guozhanxin Guozhanxin merged commit eafb04e into RT-Thread:master Oct 26, 2023
35 checks passed
@polarvid polarvid deleted the shell/fix-ctime branch October 26, 2023 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants