Skip to content

Commit 05cb76b

Browse files
committed
[xos]reorder thread, semaphore, spinlock and mutex sections in xos environ and inline wrappers
1 parent e1464af commit 05cb76b

6 files changed

Lines changed: 204 additions & 204 deletions

File tree

‎documents/docs/guide/architecture-design.md‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,22 @@ struct xos_environ_t {
162162
struct co_transfer_t (*jump)(void * fctx, void * priv);
163163
} coroutine;
164164

165+
/* 线程 */
166+
struct {
167+
struct thread_t * (*create)(const char * name, void (*func)(void *), void * data, int stksz);
168+
void (*destroy)(struct thread_t * thread);
169+
void (*wait)(struct thread_t * thread);
170+
void (*sleep)(uint64_t ns);
171+
} thread;
172+
173+
/* 信号量 */
174+
struct {
175+
void (*init)(struct semaphore_t * sem, unsigned int count);
176+
void (*exit)(struct semaphore_t * sem);
177+
int (*wait)(struct semaphore_t * sem, int timeout);
178+
int (*post)(struct semaphore_t * sem);
179+
} semaphore;
180+
165181
/* 自旋锁 */
166182
struct {
167183
void (*init)(struct spinlock_t * lock);
@@ -171,14 +187,6 @@ struct xos_environ_t {
171187
int (*unlock)(struct spinlock_t * lock);
172188
} spinlock;
173189

174-
/* 线程 */
175-
struct {
176-
struct thread_t * (*create)(const char * name, void (*func)(void *), void * data, int stksz);
177-
void (*destroy)(struct thread_t * thread);
178-
void (*wait)(struct thread_t * thread);
179-
void (*sleep)(uint64_t ns);
180-
} thread;
181-
182190
/* 互斥锁 */
183191
struct {
184192
void (*init)(struct mutex_t * lock);
@@ -188,14 +196,6 @@ struct xos_environ_t {
188196
int (*unlock)(struct mutex_t * lock);
189197
} mutex;
190198

191-
/* 信号量 */
192-
struct {
193-
void (*init)(struct semaphore_t * sem, unsigned int count);
194-
void (*exit)(struct semaphore_t * sem);
195-
int (*wait)(struct semaphore_t * sem, int timeout);
196-
int (*post)(struct semaphore_t * sem);
197-
} semaphore;
198-
199199
/* 字符串与内存操作 */
200200
struct {
201201
char * (*strcpy)(char * dest, const char * src);
@@ -218,7 +218,7 @@ struct xos_environ_t {
218218
};
219219
```
220220

221-
各分组按 `mem` → `dma` → `io` → `stdio` → `pm` → `file` → `coroutine` → `spinlock` → `thread` → `mutex` → `semaphore` → `other` 的顺序声明,平台实现建议使用指定初始化器并按此顺序书写,便于与 `xstar/xos/xos.h` 对照。
221+
各分组按 `mem` → `dma` → `io` → `stdio` → `pm` → `file` → `coroutine` → `thread` → `semaphore` → `spinlock` → `mutex` → `other` 的顺序声明,平台实现建议使用指定初始化器并按此顺序书写,便于与 `xstar/xos/xos.h` 对照。
222222

223223
### API 分类
224224

@@ -233,10 +233,10 @@ XOS 通过 `xos_environ_t` 提供平台相关的操作,同时还直接提供
233233
| **电源管理** (`pm`) | `xos_pm_shutdown/reboot/standby` |
234234
| **文件系统** (`file`) | `xos_file_cwd/open/close/read/write/seek/tell/length/sync`, `xos_file_mkdir/remove/access/walk`, `xos_file_isdir/isfile/mode` |
235235
| **协程** (`coroutine`) | `xos_coroutine_make`, `xos_coroutine_jump` |
236-
| **自旋锁** (`spinlock`) | `xos_spinlock_init/exit/lock/trylock/unlock` |
237236
| **线程** (`thread`) | `xos_thread_create/destroy/wait/sleep` |
238-
| **互斥锁** (`mutex`) | `xos_mutex_init/exit/lock/trylock/unlock` |
239237
| **信号量** (`semaphore`) | `xos_semaphore_init/exit/wait/post` |
238+
| **自旋锁** (`spinlock`) | `xos_spinlock_init/exit/lock/trylock/unlock` |
239+
| **互斥锁** (`mutex`) | `xos_mutex_init/exit/lock/trylock/unlock` |
240240
| **字符串与内存操作** (`other`) | `xos_strcpy/strncpy/strcat/strncat/strlen/strnlen/strcmp/strncmp/strcasecmp/strncasecmp`, `xos_memset/memcpy/memmove/memchr/memcmp` |
241241
| **格式化** | `xos_sprintf/snprintf/printf/sscanf` 等 |
242242
| **数值转换** | `xos_strtol/strtoll/strtod/atoi/atol` 等 |

‎documents/docs/guide/development-guide.md‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ obj-$(CONFIG_WBOXTEST_MYGROUP) += xxx.o
593593

594594
### xos_environ_t 接口
595595

596-
分组按 `mem` → `dma` → `io` → `stdio` → `pm` → `file` → `coroutine` → `spinlock` → `thread` → `mutex` → `semaphore` → `other` 的顺序声明(详见 `xstar/xos/xos.h`),初始化时建议保持相同顺序:
596+
分组按 `mem` → `dma` → `io` → `stdio` → `pm` → `file` → `coroutine` → `thread` → `semaphore` → `spinlock` → `mutex` → `other` 的顺序声明(详见 `xstar/xos/xos.h`),初始化时建议保持相同顺序:
597597

598598
```c
599599
static struct xos_environ_t env = {
@@ -660,6 +660,20 @@ static struct xos_environ_t env = {
660660
.jump = my_coroutine_jump,
661661
},
662662

663+
.thread = {
664+
.create = my_thread_create,
665+
.destroy = my_thread_destroy,
666+
.wait = my_thread_wait,
667+
.sleep = my_thread_sleep,
668+
},
669+
670+
.semaphore = {
671+
.init = my_semaphore_init,
672+
.exit = my_semaphore_exit,
673+
.wait = my_semaphore_wait,
674+
.post = my_semaphore_post,
675+
},
676+
663677
.spinlock = {
664678
.init = my_spinlock_init,
665679
.exit = my_spinlock_exit,
@@ -668,13 +682,6 @@ static struct xos_environ_t env = {
668682
.unlock = my_spinlock_unlock,
669683
},
670684

671-
.thread = {
672-
.create = my_thread_create,
673-
.destroy = my_thread_destroy,
674-
.wait = my_thread_wait,
675-
.sleep = my_thread_sleep,
676-
},
677-
678685
.mutex = {
679686
.init = my_mutex_init,
680687
.exit = my_mutex_exit,
@@ -683,13 +690,6 @@ static struct xos_environ_t env = {
683690
.unlock = my_mutex_unlock,
684691
},
685692

686-
.semaphore = {
687-
.init = my_semaphore_init,
688-
.exit = my_semaphore_exit,
689-
.wait = my_semaphore_wait,
690-
.post = my_semaphore_post,
691-
},
692-
693693
.other = {
694694
.strcpy = my_strcpy,
695695
.strncpy = my_strncpy,

‎documents/i18n/en/docusaurus-plugin-content-docs/current/guide/architecture-design.md‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,22 @@ struct xos_environ_t {
162162
struct co_transfer_t (*jump)(void * fctx, void * priv);
163163
} coroutine;
164164

165+
/* Thread */
166+
struct {
167+
struct thread_t * (*create)(const char * name, void (*func)(void *), void * data, int stksz);
168+
void (*destroy)(struct thread_t * thread);
169+
void (*wait)(struct thread_t * thread);
170+
void (*sleep)(uint64_t ns);
171+
} thread;
172+
173+
/* Semaphore */
174+
struct {
175+
void (*init)(struct semaphore_t * sem, unsigned int count);
176+
void (*exit)(struct semaphore_t * sem);
177+
int (*wait)(struct semaphore_t * sem, int timeout);
178+
int (*post)(struct semaphore_t * sem);
179+
} semaphore;
180+
165181
/* Spinlock */
166182
struct {
167183
void (*init)(struct spinlock_t * lock);
@@ -171,14 +187,6 @@ struct xos_environ_t {
171187
int (*unlock)(struct spinlock_t * lock);
172188
} spinlock;
173189

174-
/* Thread */
175-
struct {
176-
struct thread_t * (*create)(const char * name, void (*func)(void *), void * data, int stksz);
177-
void (*destroy)(struct thread_t * thread);
178-
void (*wait)(struct thread_t * thread);
179-
void (*sleep)(uint64_t ns);
180-
} thread;
181-
182190
/* Mutex */
183191
struct {
184192
void (*init)(struct mutex_t * lock);
@@ -188,14 +196,6 @@ struct xos_environ_t {
188196
int (*unlock)(struct mutex_t * lock);
189197
} mutex;
190198

191-
/* Semaphore */
192-
struct {
193-
void (*init)(struct semaphore_t * sem, unsigned int count);
194-
void (*exit)(struct semaphore_t * sem);
195-
int (*wait)(struct semaphore_t * sem, int timeout);
196-
int (*post)(struct semaphore_t * sem);
197-
} semaphore;
198-
199199
/* String and memory operations */
200200
struct {
201201
char * (*strcpy)(char * dest, const char * src);
@@ -218,7 +218,7 @@ struct xos_environ_t {
218218
};
219219
```
220220

221-
The groups are declared in the order `mem` → `dma` → `io` → `stdio` → `pm` → `file` → `coroutine` → `spinlock` → `thread` → `mutex` → `semaphore` → `other`. Platform implementations should use designated initializers written in this order so they can be compared directly against `xstar/xos/xos.h`.
221+
The groups are declared in the order `mem` → `dma` → `io` → `stdio` → `pm` → `file` → `coroutine` → `thread` → `semaphore` → `spinlock` → `mutex` → `other`. Platform implementations should use designated initializers written in this order so they can be compared directly against `xstar/xos/xos.h`.
222222

223223
### API Categories
224224

@@ -233,10 +233,10 @@ XOS provides platform-related operations via `xos_environ_t`, and also directly
233233
| **Power Management** (`pm`) | `xos_pm_shutdown/reboot/standby` |
234234
| **File System** (`file`) | `xos_file_cwd/open/close/read/write/seek/tell/length/sync`, `xos_file_mkdir/remove/access/walk`, `xos_file_isdir/isfile/mode` |
235235
| **Coroutine** (`coroutine`) | `xos_coroutine_make`, `xos_coroutine_jump` |
236-
| **Spinlock** (`spinlock`) | `xos_spinlock_init/exit/lock/trylock/unlock` |
237236
| **Thread** (`thread`) | `xos_thread_create/destroy/wait/sleep` |
238-
| **Mutex** (`mutex`) | `xos_mutex_init/exit/lock/trylock/unlock` |
239237
| **Semaphore** (`semaphore`) | `xos_semaphore_init/exit/wait/post` |
238+
| **Spinlock** (`spinlock`) | `xos_spinlock_init/exit/lock/trylock/unlock` |
239+
| **Mutex** (`mutex`) | `xos_mutex_init/exit/lock/trylock/unlock` |
240240
| **String & Memory Operations** (`other`) | `xos_strcpy/strncpy/strcat/strncat/strlen/strnlen/strcmp/strncmp/strcasecmp/strncasecmp`, `xos_memset/memcpy/memmove/memchr/memcmp` |
241241
| **Formatting** | `xos_sprintf/snprintf/printf/sscanf`, etc. |
242242
| **Numeric Conversion** | `xos_strtol/strtoll/strtod/atoi/atol`, etc. |

‎documents/i18n/en/docusaurus-plugin-content-docs/current/guide/development-guide.md‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ Porting XOS to a new platform requires implementing the `xos_environ_t` function
588588

589589
### xos_environ_t Interface
590590

591-
The groups are declared in the order `mem` → `dma` → `io` → `stdio` → `pm` → `file` → `coroutine` → `spinlock` → `thread` → `mutex` → `semaphore` → `other` (see `xstar/xos/xos.h`); keep the same order when initializing:
591+
The groups are declared in the order `mem` → `dma` → `io` → `stdio` → `pm` → `file` → `coroutine` → `thread` → `semaphore` → `spinlock` → `mutex` → `other` (see `xstar/xos/xos.h`); keep the same order when initializing:
592592

593593
```c
594594
static struct xos_environ_t env = {
@@ -655,6 +655,20 @@ static struct xos_environ_t env = {
655655
.jump = my_coroutine_jump,
656656
},
657657

658+
.thread = {
659+
.create = my_thread_create,
660+
.destroy = my_thread_destroy,
661+
.wait = my_thread_wait,
662+
.sleep = my_thread_sleep,
663+
},
664+
665+
.semaphore = {
666+
.init = my_semaphore_init,
667+
.exit = my_semaphore_exit,
668+
.wait = my_semaphore_wait,
669+
.post = my_semaphore_post,
670+
},
671+
658672
.spinlock = {
659673
.init = my_spinlock_init,
660674
.exit = my_spinlock_exit,
@@ -663,13 +677,6 @@ static struct xos_environ_t env = {
663677
.unlock = my_spinlock_unlock,
664678
},
665679

666-
.thread = {
667-
.create = my_thread_create,
668-
.destroy = my_thread_destroy,
669-
.wait = my_thread_wait,
670-
.sleep = my_thread_sleep,
671-
},
672-
673680
.mutex = {
674681
.init = my_mutex_init,
675682
.exit = my_mutex_exit,
@@ -678,13 +685,6 @@ static struct xos_environ_t env = {
678685
.unlock = my_mutex_unlock,
679686
},
680687

681-
.semaphore = {
682-
.init = my_semaphore_init,
683-
.exit = my_semaphore_exit,
684-
.wait = my_semaphore_wait,
685-
.post = my_semaphore_post,
686-
},
687-
688688
.other = {
689689
.strcpy = my_strcpy,
690690
.strncpy = my_strncpy,

0 commit comments

Comments
 (0)