summaryrefslogtreecommitdiff
path: root/core/src/xmake/thread
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-10 06:35:04 +0800
committerGitHub <[email protected]>2025-11-10 06:35:04 +0800
commit2b01e46fcf619aaecb8435b0fac975e3aff0587f (patch)
tree8f005a8dfc3272e9f027560e5e1b5881a7a8bc70 /core/src/xmake/thread
parenta1b0ec856e2c22aac84022feb05b6687912e3d6e (diff)
parent2c387895657ae13cd717d7f42f5baed5eb028a8e (diff)
Merge pull request #7008 from xmake-io/format
format code
Diffstat (limited to 'core/src/xmake/thread')
-rw-r--r--core/src/xmake/thread/event_exit.c18
-rw-r--r--core/src/xmake/thread/event_incref.c12
-rw-r--r--core/src/xmake/thread/event_init.c25
-rw-r--r--core/src/xmake/thread/event_post.c12
-rw-r--r--core/src/xmake/thread/event_wait.c12
-rw-r--r--core/src/xmake/thread/mutex_exit.c18
-rw-r--r--core/src/xmake/thread/mutex_incref.c12
-rw-r--r--core/src/xmake/thread/mutex_init.c25
-rw-r--r--core/src/xmake/thread/mutex_lock.c12
-rw-r--r--core/src/xmake/thread/mutex_trylock.c12
-rw-r--r--core/src/xmake/thread/mutex_unlock.c12
-rw-r--r--core/src/xmake/thread/prefix.h131
-rw-r--r--core/src/xmake/thread/queue_clear.c12
-rw-r--r--core/src/xmake/thread/queue_exit.c18
-rw-r--r--core/src/xmake/thread/queue_incref.c12
-rw-r--r--core/src/xmake/thread/queue_init.c43
-rw-r--r--core/src/xmake/thread/queue_pop.c29
-rw-r--r--core/src/xmake/thread/queue_push.c51
-rw-r--r--core/src/xmake/thread/queue_size.c12
-rw-r--r--core/src/xmake/thread/semaphore_exit.c18
-rw-r--r--core/src/xmake/thread/semaphore_incref.c12
-rw-r--r--core/src/xmake/thread/semaphore_init.c25
-rw-r--r--core/src/xmake/thread/semaphore_post.c12
-rw-r--r--core/src/xmake/thread/semaphore_wait.c12
-rw-r--r--core/src/xmake/thread/sharedata_clear.c12
-rw-r--r--core/src/xmake/thread/sharedata_exit.c15
-rw-r--r--core/src/xmake/thread/sharedata_get.c29
-rw-r--r--core/src/xmake/thread/sharedata_incref.c12
-rw-r--r--core/src/xmake/thread/sharedata_init.c22
-rw-r--r--core/src/xmake/thread/sharedata_set.c54
-rw-r--r--core/src/xmake/thread/thread_exit.c20
-rw-r--r--core/src/xmake/thread/thread_init.c65
-rw-r--r--core/src/xmake/thread/thread_resume.c14
-rw-r--r--core/src/xmake/thread/thread_suspend.c14
-rw-r--r--core/src/xmake/thread/thread_wait.c14
35 files changed, 349 insertions, 479 deletions
diff --git a/core/src/xmake/thread/event_exit.c b/core/src/xmake/thread/event_exit.c
index 54e977068..a9b16db6c 100644
--- a/core/src/xmake/thread/event_exit.c
+++ b/core/src/xmake/thread/event_exit.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_event_exit.c
+ * @file event_exit.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_event"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_event"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,17 +33,14 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_event_exit(lua_State* lua)
-{
+tb_int_t xm_thread_event_exit(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_event_t* thread_event = xm_thread_event_get(lua, 1);
+ xm_thread_event_t *thread_event = xm_thread_event_get(lua, 1);
tb_assert_and_check_return_val(thread_event && thread_event->handle, 0);
- if (tb_atomic_fetch_and_sub(&thread_event->refn, 1) == 1)
- {
- if (thread_event->handle)
- {
+ if (tb_atomic_fetch_and_sub(&thread_event->refn, 1) == 1) {
+ if (thread_event->handle) {
tb_event_exit(thread_event->handle);
thread_event->handle = tb_null;
}
@@ -52,4 +49,3 @@ tb_int_t xm_thread_event_exit(lua_State* lua)
lua_pushboolean(lua, tb_true);
return 1;
}
-
diff --git a/core/src/xmake/thread/event_incref.c b/core/src/xmake/thread/event_incref.c
index ff8b658d9..9a2b6163a 100644
--- a/core/src/xmake/thread/event_incref.c
+++ b/core/src/xmake/thread/event_incref.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_event_incref.c
+ * @file event_incref.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_event"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_event"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,14 +33,12 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_event_incref(lua_State* lua)
-{
+tb_int_t xm_thread_event_incref(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_event_t* thread_event = xm_thread_event_get(lua, 1);
+ xm_thread_event_t *thread_event = xm_thread_event_get(lua, 1);
tb_assert_and_check_return_val(thread_event && thread_event->handle, 0);
lua_pushboolean(lua, tb_atomic_fetch_and_add(&thread_event->refn, 1) >= 1);
return 1;
}
-
diff --git a/core/src/xmake/thread/event_init.c b/core/src/xmake/thread/event_init.c
index 942537718..d661939b0 100644
--- a/core/src/xmake/thread/event_init.c
+++ b/core/src/xmake/thread/event_init.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_event"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_event"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,18 +33,16 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_event_init(lua_State* lua)
-{
+tb_int_t xm_thread_event_init(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- tb_bool_t ok = tb_false;
- xm_thread_event_t* thread_event = tb_null;
- do
- {
+ tb_bool_t ok = tb_false;
+ xm_thread_event_t *thread_event = tb_null;
+ do {
thread_event = tb_malloc0_type(xm_thread_event_t);
tb_assert_and_check_break(thread_event);
- thread_event->refn = 1;
+ thread_event->refn = 1;
thread_event->handle = tb_event_init();
tb_assert_and_check_break(thread_event->handle);
@@ -53,12 +51,9 @@ tb_int_t xm_thread_event_init(lua_State* lua)
} while (0);
- if (!ok)
- {
- if (thread_event)
- {
- if (thread_event->handle)
- {
+ if (!ok) {
+ if (thread_event) {
+ if (thread_event->handle) {
tb_event_exit(thread_event->handle);
thread_event->handle = tb_null;
}
diff --git a/core/src/xmake/thread/event_post.c b/core/src/xmake/thread/event_post.c
index 0b8e5dabd..fea3fdd82 100644
--- a/core/src/xmake/thread/event_post.c
+++ b/core/src/xmake/thread/event_post.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_event_lock.c
+ * @file event_post.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_event"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_event"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,14 +33,12 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_event_post(lua_State* lua)
-{
+tb_int_t xm_thread_event_post(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_event_t* thread_event = xm_thread_event_get(lua, 1);
+ xm_thread_event_t *thread_event = xm_thread_event_get(lua, 1);
tb_assert_and_check_return_val(thread_event && thread_event->handle, 0);
lua_pushboolean(lua, tb_event_post(thread_event->handle));
return 1;
}
-
diff --git a/core/src/xmake/thread/event_wait.c b/core/src/xmake/thread/event_wait.c
index d6d628311..ae4453d5e 100644
--- a/core/src/xmake/thread/event_wait.c
+++ b/core/src/xmake/thread/event_wait.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_event_wait.c
+ * @file event_wait.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_event"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_event"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,15 +33,13 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_event_wait(lua_State* lua)
-{
+tb_int_t xm_thread_event_wait(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_event_t* thread_event = xm_thread_event_get(lua, 1);
+ xm_thread_event_t *thread_event = xm_thread_event_get(lua, 1);
tb_assert_and_check_return_val(thread_event && thread_event->handle, 0);
tb_long_t timeout = (tb_long_t)luaL_checknumber(lua, 2);
lua_pushinteger(lua, tb_event_wait(thread_event->handle, timeout));
return 1;
}
-
diff --git a/core/src/xmake/thread/mutex_exit.c b/core/src/xmake/thread/mutex_exit.c
index 39d69ab8a..6d79e6197 100644
--- a/core/src/xmake/thread/mutex_exit.c
+++ b/core/src/xmake/thread/mutex_exit.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_mutex_exit.c
+ * @file mutex_exit.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_mutex"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_mutex"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,17 +33,14 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_mutex_exit(lua_State* lua)
-{
+tb_int_t xm_thread_mutex_exit(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_mutex_t* thread_mutex = xm_thread_mutex_get(lua, 1);
+ xm_thread_mutex_t *thread_mutex = xm_thread_mutex_get(lua, 1);
tb_assert_and_check_return_val(thread_mutex && thread_mutex->handle, 0);
- if (tb_atomic_fetch_and_sub(&thread_mutex->refn, 1) == 1)
- {
- if (thread_mutex->handle)
- {
+ if (tb_atomic_fetch_and_sub(&thread_mutex->refn, 1) == 1) {
+ if (thread_mutex->handle) {
tb_mutex_exit(thread_mutex->handle);
thread_mutex->handle = tb_null;
}
@@ -52,4 +49,3 @@ tb_int_t xm_thread_mutex_exit(lua_State* lua)
lua_pushboolean(lua, tb_true);
return 1;
}
-
diff --git a/core/src/xmake/thread/mutex_incref.c b/core/src/xmake/thread/mutex_incref.c
index 34a234757..d76f49daf 100644
--- a/core/src/xmake/thread/mutex_incref.c
+++ b/core/src/xmake/thread/mutex_incref.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_mutex_incref.c
+ * @file mutex_incref.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_mutex"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_mutex"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,14 +33,12 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_mutex_incref(lua_State* lua)
-{
+tb_int_t xm_thread_mutex_incref(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_mutex_t* thread_mutex = xm_thread_mutex_get(lua, 1);
+ xm_thread_mutex_t *thread_mutex = xm_thread_mutex_get(lua, 1);
tb_assert_and_check_return_val(thread_mutex && thread_mutex->handle, 0);
lua_pushboolean(lua, tb_atomic_fetch_and_add(&thread_mutex->refn, 1) >= 1);
return 1;
}
-
diff --git a/core/src/xmake/thread/mutex_init.c b/core/src/xmake/thread/mutex_init.c
index ff69e82ad..bca78a134 100644
--- a/core/src/xmake/thread/mutex_init.c
+++ b/core/src/xmake/thread/mutex_init.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_mutex"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_mutex"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,18 +33,16 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_mutex_init(lua_State* lua)
-{
+tb_int_t xm_thread_mutex_init(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- tb_bool_t ok = tb_false;
- xm_thread_mutex_t* thread_mutex = tb_null;
- do
- {
+ tb_bool_t ok = tb_false;
+ xm_thread_mutex_t *thread_mutex = tb_null;
+ do {
thread_mutex = tb_malloc0_type(xm_thread_mutex_t);
tb_assert_and_check_break(thread_mutex);
- thread_mutex->refn = 1;
+ thread_mutex->refn = 1;
thread_mutex->handle = tb_mutex_init();
tb_assert_and_check_break(thread_mutex->handle);
@@ -53,12 +51,9 @@ tb_int_t xm_thread_mutex_init(lua_State* lua)
} while (0);
- if (!ok)
- {
- if (thread_mutex)
- {
- if (thread_mutex->handle)
- {
+ if (!ok) {
+ if (thread_mutex) {
+ if (thread_mutex->handle) {
tb_mutex_exit(thread_mutex->handle);
thread_mutex->handle = tb_null;
}
diff --git a/core/src/xmake/thread/mutex_lock.c b/core/src/xmake/thread/mutex_lock.c
index 380301da1..711c3a07b 100644
--- a/core/src/xmake/thread/mutex_lock.c
+++ b/core/src/xmake/thread/mutex_lock.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_mutex_lock.c
+ * @file mutex_lock.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_mutex"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_mutex"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,14 +33,12 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_mutex_lock(lua_State* lua)
-{
+tb_int_t xm_thread_mutex_lock(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_mutex_t* thread_mutex = xm_thread_mutex_get(lua, 1);
+ xm_thread_mutex_t *thread_mutex = xm_thread_mutex_get(lua, 1);
tb_assert_and_check_return_val(thread_mutex && thread_mutex->handle, 0);
lua_pushboolean(lua, tb_mutex_enter(thread_mutex->handle));
return 1;
}
-
diff --git a/core/src/xmake/thread/mutex_trylock.c b/core/src/xmake/thread/mutex_trylock.c
index 7b83f3a90..7149a2b62 100644
--- a/core/src/xmake/thread/mutex_trylock.c
+++ b/core/src/xmake/thread/mutex_trylock.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_mutex_trylock.c
+ * @file mutex_trylock.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_mutex"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_mutex"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,14 +33,12 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_mutex_trylock(lua_State* lua)
-{
+tb_int_t xm_thread_mutex_trylock(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_mutex_t* thread_mutex = xm_thread_mutex_get(lua, 1);
+ xm_thread_mutex_t *thread_mutex = xm_thread_mutex_get(lua, 1);
tb_assert_and_check_return_val(thread_mutex && thread_mutex->handle, 0);
lua_pushboolean(lua, tb_mutex_enter_try(thread_mutex->handle));
return 1;
}
-
diff --git a/core/src/xmake/thread/mutex_unlock.c b/core/src/xmake/thread/mutex_unlock.c
index beb0c9e0a..a73d04dc1 100644
--- a/core/src/xmake/thread/mutex_unlock.c
+++ b/core/src/xmake/thread/mutex_unlock.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_mutex_unlock.c
+ * @file mutex_unlock.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_mutex"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_mutex"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,14 +33,12 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_mutex_unlock(lua_State* lua)
-{
+tb_int_t xm_thread_mutex_unlock(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_mutex_t* thread_mutex = xm_thread_mutex_get(lua, 1);
+ xm_thread_mutex_t *thread_mutex = xm_thread_mutex_get(lua, 1);
tb_assert_and_check_return_val(thread_mutex && thread_mutex->handle, 0);
lua_pushboolean(lua, tb_mutex_leave(thread_mutex->handle));
return 1;
}
-
diff --git a/core/src/xmake/thread/prefix.h b/core/src/xmake/thread/prefix.h
index 2b841e6a7..2ddd14adf 100644
--- a/core/src/xmake/thread/prefix.h
+++ b/core/src/xmake/thread/prefix.h
@@ -31,126 +31,117 @@
*/
// the thread type
-typedef struct __xm_thread_t
-{
+typedef struct __xm_thread_t {
tb_thread_ref_t handle;
tb_string_t callback;
tb_string_t callinfo;
-
-}xm_thread_t;
+} xm_thread_t;
// the thread value kind
-typedef enum __xm_thread_value_kind_e
-{
+typedef enum __xm_thread_value_kind_e {
XM_THREAD_VALUE_NIL = 0,
XM_THREAD_VALUE_BOOL = 1,
XM_THREAD_VALUE_INT = 2,
XM_THREAD_VALUE_NUM = 3,
XM_THREAD_VALUE_STR = 4
-
-}xm_thread_value_kind_e;
+} xm_thread_value_kind_e;
// the thread value type
-typedef struct __xm_thread_value_t
-{
- tb_uint32_t kind : 3;
- tb_uint32_t size : 29;
- union
- {
- tb_char_t* string;
+typedef struct __xm_thread_value_t {
+ tb_uint32_t kind : 3;
+ tb_uint32_t size : 29;
+ union {
+ tb_char_t *string;
tb_bool_t boolean;
lua_Integer integer;
lua_Number number;
} u;
-
-}xm_thread_value_t;
+} xm_thread_value_t;
// the thread event type
-typedef struct __xm_thread_event_t
-{
- tb_event_ref_t handle;
- tb_atomic_t refn;
-
-}xm_thread_event_t;
+typedef struct __xm_thread_event_t {
+ tb_event_ref_t handle;
+ tb_atomic_t refn;
+} xm_thread_event_t;
// the thread mutex type
-typedef struct __xm_thread_mutex_t
-{
- tb_mutex_ref_t handle;
- tb_atomic_t refn;
-
-}xm_thread_mutex_t;
+typedef struct __xm_thread_mutex_t {
+ tb_mutex_ref_t handle;
+ tb_atomic_t refn;
+} xm_thread_mutex_t;
// the thread semaphore type
-typedef struct __xm_thread_semaphore_t
-{
+typedef struct __xm_thread_semaphore_t {
tb_semaphore_ref_t handle;
tb_atomic_t refn;
-
-}xm_thread_semaphore_t;
+} xm_thread_semaphore_t;
// the thread queue type
-typedef struct __xm_thread_queue_t
-{
- tb_queue_ref_t handle;
- tb_atomic_t refn;
-
-}xm_thread_queue_t;
+typedef struct __xm_thread_queue_t {
+ tb_queue_ref_t handle;
+ tb_atomic_t refn;
+} xm_thread_queue_t;
// the thread sharedata type
-typedef struct __xm_thread_sharedata_t
-{
+typedef struct __xm_thread_sharedata_t {
xm_thread_value_t value;
tb_buffer_t buffer;
tb_atomic_t refn;
-
-}xm_thread_sharedata_t;
+} xm_thread_sharedata_t;
// get the thread event from arguments
-static __tb_inline__ xm_thread_event_t* xm_thread_event_get(lua_State* lua, tb_int_t index)
-{
- xm_thread_event_t* thread_event = tb_null;
- if (xm_lua_isinteger(lua, index)) thread_event = (xm_thread_event_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, index);
- else if (xm_lua_ispointer(lua, index)) thread_event = (xm_thread_event_t*)xm_lua_topointer(lua, index);
+static __tb_inline__ xm_thread_event_t *xm_thread_event_get(lua_State *lua, tb_int_t index) {
+ xm_thread_event_t *thread_event = tb_null;
+ if (xm_lua_isinteger(lua, index)) {
+ thread_event = (xm_thread_event_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, index);
+ } else if (xm_lua_ispointer(lua, index)) {
+ thread_event = (xm_thread_event_t *)xm_lua_topointer(lua, index);
+ }
return thread_event;
}
// get the thread mutex from arguments
-static __tb_inline__ xm_thread_mutex_t* xm_thread_mutex_get(lua_State* lua, tb_int_t index)
-{
- xm_thread_mutex_t* thread_mutex = tb_null;
- if (xm_lua_isinteger(lua, index)) thread_mutex = (xm_thread_mutex_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, index);
- else if (xm_lua_ispointer(lua, index)) thread_mutex = (xm_thread_mutex_t*)xm_lua_topointer(lua, index);
+static __tb_inline__ xm_thread_mutex_t *xm_thread_mutex_get(lua_State *lua, tb_int_t index) {
+ xm_thread_mutex_t *thread_mutex = tb_null;
+ if (xm_lua_isinteger(lua, index)) {
+ thread_mutex = (xm_thread_mutex_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, index);
+ } else if (xm_lua_ispointer(lua, index)) {
+ thread_mutex = (xm_thread_mutex_t *)xm_lua_topointer(lua, index);
+ }
return thread_mutex;
}
// get the thread semaphore from arguments
-static __tb_inline__ xm_thread_semaphore_t* xm_thread_semaphore_get(lua_State* lua, tb_int_t index)
-{
- xm_thread_semaphore_t* thread_semaphore = tb_null;
- if (xm_lua_isinteger(lua, index)) thread_semaphore = (xm_thread_semaphore_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, index);
- else if (xm_lua_ispointer(lua, index)) thread_semaphore = (xm_thread_semaphore_t*)xm_lua_topointer(lua, index);
+static __tb_inline__ xm_thread_semaphore_t *xm_thread_semaphore_get(lua_State *lua, tb_int_t index) {
+ xm_thread_semaphore_t *thread_semaphore = tb_null;
+ if (xm_lua_isinteger(lua, index)) {
+ thread_semaphore = (xm_thread_semaphore_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, index);
+ } else if (xm_lua_ispointer(lua, index)) {
+ thread_semaphore = (xm_thread_semaphore_t *)xm_lua_topointer(lua, index);
+ }
return thread_semaphore;
}
// get the thread queue from arguments
-static __tb_inline__ xm_thread_queue_t* xm_thread_queue_get(lua_State* lua, tb_int_t index)
-{
- xm_thread_queue_t* thread_queue = tb_null;
- if (xm_lua_isinteger(lua, index)) thread_queue = (xm_thread_queue_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, index);
- else if (xm_lua_ispointer(lua, index)) thread_queue = (xm_thread_queue_t*)xm_lua_topointer(lua, index);
+static __tb_inline__ xm_thread_queue_t *xm_thread_queue_get(lua_State *lua, tb_int_t index) {
+ xm_thread_queue_t *thread_queue = tb_null;
+ if (xm_lua_isinteger(lua, index)) {
+ thread_queue = (xm_thread_queue_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, index);
+ } else if (xm_lua_ispointer(lua, index)) {
+ thread_queue = (xm_thread_queue_t *)xm_lua_topointer(lua, index);
+ }
return thread_queue;
}
// get the thread sharedata from arguments
-static __tb_inline__ xm_thread_sharedata_t* xm_thread_sharedata_get(lua_State* lua, tb_int_t index)
-{
- xm_thread_sharedata_t* thread_sharedata = tb_null;
- if (xm_lua_isinteger(lua, index)) thread_sharedata = (xm_thread_sharedata_t*)(tb_size_t)(tb_long_t)lua_tointeger(lua, index);
- else if (xm_lua_ispointer(lua, index)) thread_sharedata = (xm_thread_sharedata_t*)xm_lua_topointer(lua, index);
+static __tb_inline__ xm_thread_sharedata_t *xm_thread_sharedata_get(lua_State *lua, tb_int_t index) {
+ xm_thread_sharedata_t *thread_sharedata = tb_null;
+ if (xm_lua_isinteger(lua, index)) {
+ thread_sharedata = (xm_thread_sharedata_t *)(tb_size_t)(tb_long_t)lua_tointeger(lua, index);
+ } else if (xm_lua_ispointer(lua, index)) {
+ thread_sharedata = (xm_thread_sharedata_t *)xm_lua_topointer(lua, index);
+ }
return thread_sharedata;
}
#endif
-
-
diff --git a/core/src/xmake/thread/queue_clear.c b/core/src/xmake/thread/queue_clear.c
index 4888babe2..533c035ed 100644
--- a/core/src/xmake/thread/queue_clear.c
+++ b/core/src/xmake/thread/queue_clear.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_queue_clear.c
+ * @file queue_clear.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_queue"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_queue"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,15 +33,13 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_queue_clear(lua_State* lua)
-{
+tb_int_t xm_thread_queue_clear(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_queue_t* thread_queue = xm_thread_queue_get(lua, 1);
+ xm_thread_queue_t *thread_queue = xm_thread_queue_get(lua, 1);
tb_assert_and_check_return_val(thread_queue && thread_queue->handle, 0);
tb_queue_clear(thread_queue->handle);
lua_pushboolean(lua, tb_true);
return 1;
}
-
diff --git a/core/src/xmake/thread/queue_exit.c b/core/src/xmake/thread/queue_exit.c
index 8178ea22f..de051250e 100644
--- a/core/src/xmake/thread/queue_exit.c
+++ b/core/src/xmake/thread/queue_exit.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_queue_exit.c
+ * @file queue_exit.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_queue"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_queue"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,17 +33,14 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_queue_exit(lua_State* lua)
-{
+tb_int_t xm_thread_queue_exit(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_queue_t* thread_queue = xm_thread_queue_get(lua, 1);
+ xm_thread_queue_t *thread_queue = xm_thread_queue_get(lua, 1);
tb_assert_and_check_return_val(thread_queue && thread_queue->handle, 0);
- if (tb_atomic_fetch_and_sub(&thread_queue->refn, 1) == 1)
- {
- if (thread_queue->handle)
- {
+ if (tb_atomic_fetch_and_sub(&thread_queue->refn, 1) == 1) {
+ if (thread_queue->handle) {
tb_queue_exit(thread_queue->handle);
thread_queue->handle = tb_null;
}
@@ -52,4 +49,3 @@ tb_int_t xm_thread_queue_exit(lua_State* lua)
lua_pushboolean(lua, tb_true);
return 1;
}
-
diff --git a/core/src/xmake/thread/queue_incref.c b/core/src/xmake/thread/queue_incref.c
index 4f06807c4..2322ce241 100644
--- a/core/src/xmake/thread/queue_incref.c
+++ b/core/src/xmake/thread/queue_incref.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_queue_incref.c
+ * @file queue_incref.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_queue"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_queue"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,14 +33,12 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_queue_incref(lua_State* lua)
-{
+tb_int_t xm_thread_queue_incref(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_queue_t* thread_queue = xm_thread_queue_get(lua, 1);
+ xm_thread_queue_t *thread_queue = xm_thread_queue_get(lua, 1);
tb_assert_and_check_return_val(thread_queue && thread_queue->handle, 0);
lua_pushboolean(lua, tb_atomic_fetch_and_add(&thread_queue->refn, 1) >= 1);
return 1;
}
-
diff --git a/core/src/xmake/thread/queue_init.c b/core/src/xmake/thread/queue_init.c
index 0c8af884d..a0d683dd3 100644
--- a/core/src/xmake/thread/queue_init.c
+++ b/core/src/xmake/thread/queue_init.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_queue"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_queue"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,14 +33,13 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* private implementation
*/
-static tb_void_t xm_thread_value_free(tb_element_ref_t element, tb_pointer_t buff)
-{
- xm_thread_value_t* item = (xm_thread_value_t*)buff;
- if (item)
- {
- if (item->kind == XM_THREAD_VALUE_STR)
- {
- if (item->u.string) tb_free((tb_pointer_t)item->u.string);
+static tb_void_t xm_thread_value_free(tb_element_ref_t element, tb_pointer_t buff) {
+ xm_thread_value_t *item = (xm_thread_value_t *)buff;
+ if (item) {
+ if (item->kind == XM_THREAD_VALUE_STR) {
+ if (item->u.string) {
+ tb_free((tb_pointer_t)item->u.string);
+ }
item->u.string = tb_null;
}
item->size = 0;
@@ -50,19 +49,18 @@ static tb_void_t xm_thread_value_free(tb_element_ref_t element, tb_pointer_t buf
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_queue_init(lua_State* lua)
-{
+tb_int_t xm_thread_queue_init(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- tb_bool_t ok = tb_false;
- xm_thread_queue_t* thread_queue = tb_null;
- do
- {
+ tb_bool_t ok = tb_false;
+ xm_thread_queue_t *thread_queue = tb_null;
+ do {
thread_queue = tb_malloc0_type(xm_thread_queue_t);
tb_assert_and_check_break(thread_queue);
- thread_queue->refn = 1;
- thread_queue->handle = tb_queue_init(0, tb_element_mem(sizeof(xm_thread_value_t), xm_thread_value_free, tb_null));
+ thread_queue->refn = 1;
+ thread_queue->handle = tb_queue_init(0,
+ tb_element_mem(sizeof(xm_thread_value_t), xm_thread_value_free, tb_null));
tb_assert_and_check_break(thread_queue->handle);
xm_lua_pushpointer(lua, (tb_pointer_t)thread_queue);
@@ -70,12 +68,9 @@ tb_int_t xm_thread_queue_init(lua_State* lua)
} while (0);
- if (!ok)
- {
- if (thread_queue)
- {
- if (thread_queue->handle)
- {
+ if (!ok) {
+ if (thread_queue) {
+ if (thread_queue->handle) {
tb_queue_exit(thread_queue->handle);
thread_queue->handle = tb_null;
}
diff --git a/core/src/xmake/thread/queue_pop.c b/core/src/xmake/thread/queue_pop.c
index c666a85dd..256cb151e 100644
--- a/core/src/xmake/thread/queue_pop.c
+++ b/core/src/xmake/thread/queue_pop.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_queue_pop.c
+ * @file queue_pop.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_queue"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_queue"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,30 +33,29 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_queue_pop(lua_State* lua)
-{
+tb_int_t xm_thread_queue_pop(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_queue_t* thread_queue = xm_thread_queue_get(lua, 1);
+ xm_thread_queue_t *thread_queue = xm_thread_queue_get(lua, 1);
tb_assert_and_check_return_val(thread_queue && thread_queue->handle, 0);
- if (tb_queue_null(thread_queue->handle))
- {
+ if (tb_queue_null(thread_queue->handle)) {
lua_pushnil(lua);
lua_pushliteral(lua, "the thread queue is empty");
return 2;
}
- xm_thread_value_t* item = (xm_thread_value_t*)tb_queue_get(thread_queue->handle);
+ xm_thread_value_t *item = (xm_thread_value_t *)tb_queue_get(thread_queue->handle);
tb_assert_and_check_return_val(item, 0);
tb_bool_t ok = tb_false;
- switch (item->kind)
- {
+ switch (item->kind) {
case XM_THREAD_VALUE_STR:
- if (item->size)
+ if (item->size) {
lua_pushlstring(lua, item->u.string, item->size);
- else lua_pushliteral(lua, "");
+ } else {
+ lua_pushliteral(lua, "");
+ }
ok = tb_true;
break;
case XM_THREAD_VALUE_INT:
@@ -79,8 +78,7 @@ tb_int_t xm_thread_queue_pop(lua_State* lua)
break;
}
- if (!ok)
- {
+ if (!ok) {
lua_pushnil(lua);
lua_pushliteral(lua, "invalid thread queue item");
return 2;
@@ -89,4 +87,3 @@ tb_int_t xm_thread_queue_pop(lua_State* lua)
tb_queue_pop(thread_queue->handle);
return 1;
}
-
diff --git a/core/src/xmake/thread/queue_push.c b/core/src/xmake/thread/queue_push.c
index 8125f2b9a..0a9ff63e1 100644
--- a/core/src/xmake/thread/queue_push.c
+++ b/core/src/xmake/thread/queue_push.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_queue_push.c
+ * @file queue_push.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_queue"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_queue"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,57 +33,43 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_queue_push(lua_State* lua)
-{
+tb_int_t xm_thread_queue_push(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_queue_t* thread_queue = xm_thread_queue_get(lua, 1);
+ xm_thread_queue_t *thread_queue = xm_thread_queue_get(lua, 1);
tb_assert_and_check_return_val(thread_queue && thread_queue->handle, 0);
- if (tb_queue_full(thread_queue->handle))
- {
+ if (tb_queue_full(thread_queue->handle)) {
lua_pushboolean(lua, tb_false);
lua_pushliteral(lua, "the thread queue is full");
return 2;
}
xm_thread_value_t item;
- if (lua_isstring(lua, 2))
- {
- size_t data_size = 0;
- tb_char_t const* data = luaL_checklstring(lua, 2, &data_size);
+ if (lua_isstring(lua, 2)) {
+ size_t data_size = 0;
+ tb_char_t const *data = luaL_checklstring(lua, 2, &data_size);
tb_assert_and_check_return_val(data, 0);
item.kind = (tb_uint32_t)XM_THREAD_VALUE_STR;
item.size = (tb_uint32_t)data_size;
- if (data_size)
- {
+ if (data_size) {
item.u.string = tb_malloc_cstr(data_size);
tb_assert_and_check_return_val(item.u.string, 0);
tb_memcpy(item.u.string, data, data_size);
}
- }
- else if (xm_lua_isinteger(lua, 2))
- {
- item.kind = (tb_uint32_t)XM_THREAD_VALUE_INT;
+ } else if (xm_lua_isinteger(lua, 2)) {
+ item.kind = (tb_uint32_t)XM_THREAD_VALUE_INT;
item.u.integer = lua_tointeger(lua, 2);
- }
- else if (lua_isnumber(lua, 2))
- {
- item.kind = (tb_uint32_t)XM_THREAD_VALUE_NUM;
+ } else if (lua_isnumber(lua, 2)) {
+ item.kind = (tb_uint32_t)XM_THREAD_VALUE_NUM;
item.u.number = lua_tonumber(lua, 2);
- }
- else if (lua_isboolean(lua, 2))
- {
- item.kind = (tb_uint32_t)XM_THREAD_VALUE_BOOL;
+ } else if (lua_isboolean(lua, 2)) {
+ item.kind = (tb_uint32_t)XM_THREAD_VALUE_BOOL;
item.u.boolean = lua_toboolean(lua, 2);
- }
- else if (lua_isnil(lua, 2))
- {
+ } else if (lua_isnil(lua, 2)) {
item.kind = (tb_uint32_t)XM_THREAD_VALUE_NIL;
- }
- else
- {
+ } else {
lua_pushboolean(lua, tb_false);
lua_pushliteral(lua, "unsupported thread queue item");
return 2;
@@ -93,4 +79,3 @@ tb_int_t xm_thread_queue_push(lua_State* lua)
lua_pushboolean(lua, tb_true);
return 1;
}
-
diff --git a/core/src/xmake/thread/queue_size.c b/core/src/xmake/thread/queue_size.c
index 559a1dceb..9adfbe028 100644
--- a/core/src/xmake/thread/queue_size.c
+++ b/core/src/xmake/thread/queue_size.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_queue_lock.c
+ * @file queue_size.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_queue"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_queue"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,14 +33,12 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_queue_size(lua_State* lua)
-{
+tb_int_t xm_thread_queue_size(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_queue_t* thread_queue = xm_thread_queue_get(lua, 1);
+ xm_thread_queue_t *thread_queue = xm_thread_queue_get(lua, 1);
tb_assert_and_check_return_val(thread_queue && thread_queue->handle, 0);
lua_pushinteger(lua, (tb_int_t)tb_queue_size(thread_queue->handle));
return 1;
}
-
diff --git a/core/src/xmake/thread/semaphore_exit.c b/core/src/xmake/thread/semaphore_exit.c
index cffffa249..ca6386757 100644
--- a/core/src/xmake/thread/semaphore_exit.c
+++ b/core/src/xmake/thread/semaphore_exit.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_semaphore_exit.c
+ * @file semaphore_exit.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_semaphore"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_semaphore"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,17 +33,14 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_semaphore_exit(lua_State* lua)
-{
+tb_int_t xm_thread_semaphore_exit(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_semaphore_t* thread_semaphore = xm_thread_semaphore_get(lua, 1);
+ xm_thread_semaphore_t *thread_semaphore = xm_thread_semaphore_get(lua, 1);
tb_assert_and_check_return_val(thread_semaphore && thread_semaphore->handle, 0);
- if (tb_atomic_fetch_and_sub(&thread_semaphore->refn, 1) == 1)
- {
- if (thread_semaphore->handle)
- {
+ if (tb_atomic_fetch_and_sub(&thread_semaphore->refn, 1) == 1) {
+ if (thread_semaphore->handle) {
tb_semaphore_exit(thread_semaphore->handle);
thread_semaphore->handle = tb_null;
}
@@ -52,4 +49,3 @@ tb_int_t xm_thread_semaphore_exit(lua_State* lua)
lua_pushboolean(lua, tb_true);
return 1;
}
-
diff --git a/core/src/xmake/thread/semaphore_incref.c b/core/src/xmake/thread/semaphore_incref.c
index 84c2118d3..315332981 100644
--- a/core/src/xmake/thread/semaphore_incref.c
+++ b/core/src/xmake/thread/semaphore_incref.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_semaphore_incref.c
+ * @file semaphore_incref.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_semaphore"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_semaphore"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,14 +33,12 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_semaphore_incref(lua_State* lua)
-{
+tb_int_t xm_thread_semaphore_incref(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_semaphore_t* thread_semaphore = xm_thread_semaphore_get(lua, 1);
+ xm_thread_semaphore_t *thread_semaphore = xm_thread_semaphore_get(lua, 1);
tb_assert_and_check_return_val(thread_semaphore && thread_semaphore->handle, 0);
lua_pushboolean(lua, tb_atomic_fetch_and_add(&thread_semaphore->refn, 1) >= 1);
return 1;
}
-
diff --git a/core/src/xmake/thread/semaphore_init.c b/core/src/xmake/thread/semaphore_init.c
index 976b48de9..a4c7a80fe 100644
--- a/core/src/xmake/thread/semaphore_init.c
+++ b/core/src/xmake/thread/semaphore_init.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_semaphore"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_semaphore"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,20 +33,18 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_semaphore_init(lua_State* lua)
-{
+tb_int_t xm_thread_semaphore_init(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- tb_bool_t ok = tb_false;
- xm_thread_semaphore_t* thread_semaphore = tb_null;
- do
- {
+ tb_bool_t ok = tb_false;
+ xm_thread_semaphore_t *thread_semaphore = tb_null;
+ do {
tb_long_t value = (tb_long_t)luaL_checknumber(lua, 1);
thread_semaphore = tb_malloc0_type(xm_thread_semaphore_t);
tb_assert_and_check_break(thread_semaphore);
- thread_semaphore->refn = 1;
+ thread_semaphore->refn = 1;
thread_semaphore->handle = tb_semaphore_init(value);
tb_assert_and_check_break(thread_semaphore->handle);
@@ -55,12 +53,9 @@ tb_int_t xm_thread_semaphore_init(lua_State* lua)
} while (0);
- if (!ok)
- {
- if (thread_semaphore)
- {
- if (thread_semaphore->handle)
- {
+ if (!ok) {
+ if (thread_semaphore) {
+ if (thread_semaphore->handle) {
tb_semaphore_exit(thread_semaphore->handle);
thread_semaphore->handle = tb_null;
}
diff --git a/core/src/xmake/thread/semaphore_post.c b/core/src/xmake/thread/semaphore_post.c
index 9ca94bda5..20aea4dc0 100644
--- a/core/src/xmake/thread/semaphore_post.c
+++ b/core/src/xmake/thread/semaphore_post.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_semaphore_lock.c
+ * @file semaphore_post.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_semaphore"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_semaphore"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,15 +33,13 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_semaphore_post(lua_State* lua)
-{
+tb_int_t xm_thread_semaphore_post(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_semaphore_t* thread_semaphore = xm_thread_semaphore_get(lua, 1);
+ xm_thread_semaphore_t *thread_semaphore = xm_thread_semaphore_get(lua, 1);
tb_assert_and_check_return_val(thread_semaphore && thread_semaphore->handle, 0);
tb_long_t value = (tb_long_t)luaL_checknumber(lua, 2);
lua_pushboolean(lua, tb_semaphore_post(thread_semaphore->handle, value));
return 1;
}
-
diff --git a/core/src/xmake/thread/semaphore_wait.c b/core/src/xmake/thread/semaphore_wait.c
index c8e4d1491..1c886d1bc 100644
--- a/core/src/xmake/thread/semaphore_wait.c
+++ b/core/src/xmake/thread/semaphore_wait.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_semaphore_unlock.c
+ * @file semaphore_wait.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_semaphore"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_semaphore"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,15 +33,13 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_semaphore_wait(lua_State* lua)
-{
+tb_int_t xm_thread_semaphore_wait(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_semaphore_t* thread_semaphore = xm_thread_semaphore_get(lua, 1);
+ xm_thread_semaphore_t *thread_semaphore = xm_thread_semaphore_get(lua, 1);
tb_assert_and_check_return_val(thread_semaphore && thread_semaphore->handle, 0);
tb_long_t timeout = (tb_long_t)luaL_checknumber(lua, 2);
lua_pushinteger(lua, tb_semaphore_wait(thread_semaphore->handle, timeout));
return 1;
}
-
diff --git a/core/src/xmake/thread/sharedata_clear.c b/core/src/xmake/thread/sharedata_clear.c
index 0c8b4afcf..e55d5b059 100644
--- a/core/src/xmake/thread/sharedata_clear.c
+++ b/core/src/xmake/thread/sharedata_clear.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_sharedata_clear.c
+ * @file sharedata_clear.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_sharedata"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_sharedata"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,11 +33,10 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_sharedata_clear(lua_State* lua)
-{
+tb_int_t xm_thread_sharedata_clear(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_sharedata_t* thread_sharedata = xm_thread_sharedata_get(lua, 1);
+ xm_thread_sharedata_t *thread_sharedata = xm_thread_sharedata_get(lua, 1);
tb_assert_and_check_return_val(thread_sharedata, 0);
thread_sharedata->value.kind = XM_THREAD_VALUE_NIL;
@@ -45,4 +44,3 @@ tb_int_t xm_thread_sharedata_clear(lua_State* lua)
lua_pushboolean(lua, tb_true);
return 1;
}
-
diff --git a/core/src/xmake/thread/sharedata_exit.c b/core/src/xmake/thread/sharedata_exit.c
index ad4a9f33f..419718f0f 100644
--- a/core/src/xmake/thread/sharedata_exit.c
+++ b/core/src/xmake/thread/sharedata_exit.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_sharedata_exit.c
+ * @file sharedata_exit.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_sharedata"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_sharedata"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,19 +33,16 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_sharedata_exit(lua_State* lua)
-{
+tb_int_t xm_thread_sharedata_exit(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_sharedata_t* thread_sharedata = xm_thread_sharedata_get(lua, 1);
+ xm_thread_sharedata_t *thread_sharedata = xm_thread_sharedata_get(lua, 1);
tb_assert_and_check_return_val(thread_sharedata, 0);
- if (tb_atomic_fetch_and_sub(&thread_sharedata->refn, 1) == 1)
- {
+ if (tb_atomic_fetch_and_sub(&thread_sharedata->refn, 1) == 1) {
tb_buffer_exit(&thread_sharedata->buffer);
tb_free(thread_sharedata);
}
lua_pushboolean(lua, tb_true);
return 1;
}
-
diff --git a/core/src/xmake/thread/sharedata_get.c b/core/src/xmake/thread/sharedata_get.c
index abd020d3b..6699a7500 100644
--- a/core/src/xmake/thread/sharedata_get.c
+++ b/core/src/xmake/thread/sharedata_get.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_sharedata_get.c
+ * @file sharedata_get.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_sharedata"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_sharedata"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,20 +33,22 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_sharedata_get_(lua_State* lua)
-{
+tb_int_t xm_thread_sharedata_get_(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_sharedata_t* thread_sharedata = xm_thread_sharedata_get(lua, 1);
+ xm_thread_sharedata_t *thread_sharedata = xm_thread_sharedata_get(lua, 1);
tb_assert_and_check_return_val(thread_sharedata, 0);
tb_bool_t ok = tb_false;
- switch (thread_sharedata->value.kind)
- {
+ switch (thread_sharedata->value.kind) {
case XM_THREAD_VALUE_STR:
- if (tb_buffer_size(&thread_sharedata->buffer) > 0)
- lua_pushlstring(lua, (tb_char_t*)tb_buffer_data(&thread_sharedata->buffer), tb_buffer_size(&thread_sharedata->buffer));
- else lua_pushliteral(lua, "");
+ if (tb_buffer_size(&thread_sharedata->buffer) > 0) {
+ lua_pushlstring(lua,
+ (tb_char_t *)tb_buffer_data(&thread_sharedata->buffer),
+ tb_buffer_size(&thread_sharedata->buffer));
+ } else {
+ lua_pushliteral(lua, "");
+ }
ok = tb_true;
break;
case XM_THREAD_VALUE_INT:
@@ -69,8 +71,7 @@ tb_int_t xm_thread_sharedata_get_(lua_State* lua)
break;
}
- if (!ok)
- {
+ if (!ok) {
lua_pushnil(lua);
lua_pushliteral(lua, "invalid thread sharedata thread_sharedata");
return 2;
@@ -78,5 +79,3 @@ tb_int_t xm_thread_sharedata_get_(lua_State* lua)
return 1;
}
-
-
diff --git a/core/src/xmake/thread/sharedata_incref.c b/core/src/xmake/thread/sharedata_incref.c
index e0d32c600..8706c00a3 100644
--- a/core/src/xmake/thread/sharedata_incref.c
+++ b/core/src/xmake/thread/sharedata_incref.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_sharedata_incref.c
+ * @file sharedata_incref.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_sharedata"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_sharedata"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,14 +33,12 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_sharedata_incref(lua_State* lua)
-{
+tb_int_t xm_thread_sharedata_incref(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_sharedata_t* thread_sharedata = xm_thread_sharedata_get(lua, 1);
+ xm_thread_sharedata_t *thread_sharedata = xm_thread_sharedata_get(lua, 1);
tb_assert_and_check_return_val(thread_sharedata, 0);
lua_pushboolean(lua, tb_atomic_fetch_and_add(&thread_sharedata->refn, 1) >= 1);
return 1;
}
-
diff --git a/core/src/xmake/thread/sharedata_init.c b/core/src/xmake/thread/sharedata_init.c
index b38fc217a..ac712e5f3 100644
--- a/core/src/xmake/thread/sharedata_init.c
+++ b/core/src/xmake/thread/sharedata_init.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_sharedata"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_sharedata"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,18 +33,16 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_sharedata_init(lua_State* lua)
-{
+tb_int_t xm_thread_sharedata_init(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- tb_bool_t ok = tb_false;
- xm_thread_sharedata_t* thread_sharedata = tb_null;
- do
- {
+ tb_bool_t ok = tb_false;
+ xm_thread_sharedata_t *thread_sharedata = tb_null;
+ do {
thread_sharedata = tb_malloc0_type(xm_thread_sharedata_t);
tb_assert_and_check_break(thread_sharedata);
- thread_sharedata->refn = 1;
+ thread_sharedata->refn = 1;
thread_sharedata->value.kind = XM_THREAD_VALUE_NIL;
tb_buffer_init(&thread_sharedata->buffer);
@@ -53,10 +51,8 @@ tb_int_t xm_thread_sharedata_init(lua_State* lua)
} while (0);
- if (!ok)
- {
- if (thread_sharedata)
- {
+ if (!ok) {
+ if (thread_sharedata) {
tb_buffer_exit(&thread_sharedata->buffer);
tb_free(thread_sharedata);
}
diff --git a/core/src/xmake/thread/sharedata_set.c b/core/src/xmake/thread/sharedata_set.c
index 08e661f20..2bd66d1f9 100644
--- a/core/src/xmake/thread/sharedata_set.c
+++ b/core/src/xmake/thread/sharedata_set.c
@@ -15,15 +15,15 @@
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
- * @file thread_sharedata_set.c
+ * @file sharedata_set.c
*
*/
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread_sharedata"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread_sharedata"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,45 +33,35 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_sharedata_set(lua_State* lua)
-{
+tb_int_t xm_thread_sharedata_set(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- xm_thread_sharedata_t* thread_sharedata = xm_thread_sharedata_get(lua, 1);
+ xm_thread_sharedata_t *thread_sharedata = xm_thread_sharedata_get(lua, 1);
tb_assert_and_check_return_val(thread_sharedata, 0);
- if (lua_isstring(lua, 2))
- {
- size_t data_size = 0;
- tb_char_t const* data = luaL_checklstring(lua, 2, &data_size);
+ if (lua_isstring(lua, 2)) {
+ size_t data_size = 0;
+ tb_char_t const *data = luaL_checklstring(lua, 2, &data_size);
tb_assert_and_check_return_val(data, 0);
thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_STR;
- if (data_size)
- tb_buffer_memncpy(&thread_sharedata->buffer, (tb_byte_t const*)data, data_size);
- else tb_buffer_clear(&thread_sharedata->buffer);
- }
- else if (xm_lua_isinteger(lua, 2))
- {
- thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_INT;
+ if (data_size) {
+ tb_buffer_memncpy(&thread_sharedata->buffer, (tb_byte_t const *)data, data_size);
+ } else {
+ tb_buffer_clear(&thread_sharedata->buffer);
+ }
+ } else if (xm_lua_isinteger(lua, 2)) {
+ thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_INT;
thread_sharedata->value.u.integer = lua_tointeger(lua, 2);
- }
- else if (lua_isnumber(lua, 2))
- {
- thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_NUM;
+ } else if (lua_isnumber(lua, 2)) {
+ thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_NUM;
thread_sharedata->value.u.number = lua_tonumber(lua, 2);
- }
- else if (lua_isboolean(lua, 2))
- {
- thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_BOOL;
+ } else if (lua_isboolean(lua, 2)) {
+ thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_BOOL;
thread_sharedata->value.u.boolean = lua_toboolean(lua, 2);
- }
- else if (lua_isnil(lua, 2))
- {
+ } else if (lua_isnil(lua, 2)) {
thread_sharedata->value.kind = (tb_uint32_t)XM_THREAD_VALUE_NIL;
- }
- else
- {
+ } else {
lua_pushboolean(lua, tb_false);
lua_pushliteral(lua, "unsupported thread sharedata item");
return 2;
@@ -80,5 +70,3 @@ tb_int_t xm_thread_sharedata_set(lua_State* lua)
lua_pushboolean(lua, tb_true);
return 1;
}
-
-
diff --git a/core/src/xmake/thread/thread_exit.c b/core/src/xmake/thread/thread_exit.c
index 9d2c8e908..ca495d4a5 100644
--- a/core/src/xmake/thread/thread_exit.c
+++ b/core/src/xmake/thread/thread_exit.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,26 +33,23 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_exit(lua_State* lua)
-{
- // check
+tb_int_t xm_thread_exit(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
// is pointer?
- if (!xm_lua_ispointer(lua, 1))
+ if (!xm_lua_ispointer(lua, 1)) {
return 0;
+ }
// get thread
- xm_thread_t* thread = (xm_thread_t*)xm_lua_topointer(lua, 1);
+ xm_thread_t *thread = (xm_thread_t *)xm_lua_topointer(lua, 1);
tb_check_return_val(thread, 0);
// exit thread
- if (thread)
- {
+ if (thread) {
tb_string_exit(&thread->callback);
tb_string_exit(&thread->callinfo);
- if (thread->handle)
- {
+ if (thread->handle) {
tb_thread_exit(thread->handle);
thread->handle = tb_null;
}
@@ -61,4 +58,3 @@ tb_int_t xm_thread_exit(lua_State* lua)
lua_pushboolean(lua, tb_true);
return 1;
}
-
diff --git a/core/src/xmake/thread/thread_init.c b/core/src/xmake/thread/thread_init.c
index 6fc44267a..2d3e067f7 100644
--- a/core/src/xmake/thread/thread_init.c
+++ b/core/src/xmake/thread/thread_init.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -35,47 +35,46 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* macros
*/
-#define XM_THREAD_ENGINE_NAME "xmake"
+#define XM_THREAD_ENGINE_NAME "xmake"
/* //////////////////////////////////////////////////////////////////////////////////////
* private implementation
*/
-static tb_int_t xm_thread_func(tb_cpointer_t priv)
-{
- xm_thread_t* thread = (xm_thread_t*)priv;
+static tb_int_t xm_thread_func(tb_cpointer_t priv) {
+ xm_thread_t *thread = (xm_thread_t *)priv;
tb_assert_and_check_return_val(thread, 0);
xm_engine_ref_t engine = xm_engine_pool_alloc(xm_engine_pool());
- if (!engine) engine = xm_engine_init(XM_THREAD_ENGINE_NAME, tb_null);
- if (engine)
- {
- lua_State* lua = xm_engine_lua(engine);
+ if (!engine) {
+ engine = xm_engine_init(XM_THREAD_ENGINE_NAME, tb_null);
+ }
+ if (engine) {
+ lua_State *lua = xm_engine_lua(engine);
tb_assert(lua);
// pass callback
- tb_char_t const* callback_data = tb_string_cstr(&thread->callback);
+ tb_char_t const *callback_data = tb_string_cstr(&thread->callback);
tb_size_t callback_size = tb_string_size(&thread->callback);
- if (callback_data && callback_size)
- {
+ if (callback_data && callback_size) {
lua_pushlstring(lua, callback_data, callback_size);
lua_setglobal(lua, "_THREAD_CALLBACK");
}
// pass callinfo
- tb_char_t const* callinfo_data = tb_string_cstr(&thread->callinfo);
+ tb_char_t const *callinfo_data = tb_string_cstr(&thread->callinfo);
tb_size_t callinfo_size = tb_string_size(&thread->callinfo);
- if (callinfo_data && callinfo_size)
- {
+ if (callinfo_data && callinfo_size) {
lua_pushlstring(lua, callinfo_data, callinfo_size);
lua_setglobal(lua, "_THREAD_CALLINFO");
}
// start engine
- tb_char_t* argv[] = {XM_THREAD_ENGINE_NAME, tb_null};
+ tb_char_t *argv[] = { XM_THREAD_ENGINE_NAME, tb_null };
xm_engine_main(engine, 1, argv, tb_null);
- if (!xm_engine_pool_free(xm_engine_pool(), engine))
+ if (!xm_engine_pool_free(xm_engine_pool(), engine)) {
xm_engine_exit(engine);
+ }
}
return 0;
}
@@ -83,26 +82,23 @@ static tb_int_t xm_thread_func(tb_cpointer_t priv)
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_init(lua_State* lua)
-{
- // check
+tb_int_t xm_thread_init(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
- tb_bool_t ok = tb_false;
- xm_thread_t* thread = tb_null;
- do
- {
+ tb_bool_t ok = tb_false;
+ xm_thread_t *thread = tb_null;
+ do {
// get thread name
- tb_char_t const* name = luaL_checkstring(lua, 1);
+ tb_char_t const *name = luaL_checkstring(lua, 1);
// get callback
- size_t callback_size = 0;
- tb_char_t const* callback_data = luaL_checklstring(lua, 2, &callback_size);
+ size_t callback_size = 0;
+ tb_char_t const *callback_data = luaL_checklstring(lua, 2, &callback_size);
tb_assert_and_check_break(callback_data && callback_size);
// get callinfo
- size_t callinfo_size = 0;
- tb_char_t const* callinfo_data = luaL_checklstring(lua, 3, &callinfo_size);
+ size_t callinfo_size = 0;
+ tb_char_t const *callinfo_data = luaL_checklstring(lua, 3, &callinfo_size);
tb_assert_and_check_break(callinfo_data && callinfo_size);
// get stack size
@@ -127,14 +123,11 @@ tb_int_t xm_thread_init(lua_State* lua)
} while (0);
- if (!ok)
- {
- if (thread)
- {
+ if (!ok) {
+ if (thread) {
tb_string_exit(&thread->callback);
tb_string_exit(&thread->callinfo);
- if (thread->handle)
- {
+ if (thread->handle) {
tb_thread_exit(thread->handle);
thread->handle = tb_null;
}
diff --git a/core/src/xmake/thread/thread_resume.c b/core/src/xmake/thread/thread_resume.c
index 9843ac2d7..d9ab421cf 100644
--- a/core/src/xmake/thread/thread_resume.c
+++ b/core/src/xmake/thread/thread_resume.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,21 +33,19 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_resume(lua_State* lua)
-{
- // check
+tb_int_t xm_thread_resume(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
// is pointer?
- if (!xm_lua_ispointer(lua, 1))
+ if (!xm_lua_ispointer(lua, 1)) {
return 0;
+ }
// get thread
- xm_thread_t* thread = (xm_thread_t*)xm_lua_topointer(lua, 1);
+ xm_thread_t *thread = (xm_thread_t *)xm_lua_topointer(lua, 1);
tb_check_return_val(thread && thread->handle, 0);
// resume thread
lua_pushboolean(lua, tb_thread_resume(thread->handle));
return 1;
}
-
diff --git a/core/src/xmake/thread/thread_suspend.c b/core/src/xmake/thread/thread_suspend.c
index e21509413..7eb6a6a36 100644
--- a/core/src/xmake/thread/thread_suspend.c
+++ b/core/src/xmake/thread/thread_suspend.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,21 +33,19 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_suspend(lua_State* lua)
-{
- // check
+tb_int_t xm_thread_suspend(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
// is pointer?
- if (!xm_lua_ispointer(lua, 1))
+ if (!xm_lua_ispointer(lua, 1)) {
return 0;
+ }
// get thread
- xm_thread_t* thread = (xm_thread_t*)xm_lua_topointer(lua, 1);
+ xm_thread_t *thread = (xm_thread_t *)xm_lua_topointer(lua, 1);
tb_check_return_val(thread && thread->handle, 0);
// suspend thread
lua_pushboolean(lua, tb_thread_suspend(thread->handle));
return 1;
}
-
diff --git a/core/src/xmake/thread/thread_wait.c b/core/src/xmake/thread/thread_wait.c
index f2d7199ec..8c9ffab18 100644
--- a/core/src/xmake/thread/thread_wait.c
+++ b/core/src/xmake/thread/thread_wait.c
@@ -22,8 +22,8 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
-#define TB_TRACE_MODULE_NAME "thread"
-#define TB_TRACE_MODULE_DEBUG (0)
+#define TB_TRACE_MODULE_NAME "thread"
+#define TB_TRACE_MODULE_DEBUG (0)
/* //////////////////////////////////////////////////////////////////////////////////////
* includes
@@ -33,17 +33,16 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/
-tb_int_t xm_thread_wait(lua_State* lua)
-{
- // check
+tb_int_t xm_thread_wait(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);
// is pointer?
- if (!xm_lua_ispointer(lua, 1))
+ if (!xm_lua_ispointer(lua, 1)) {
return 0;
+ }
// get thread
- xm_thread_t* thread = (xm_thread_t*)xm_lua_topointer(lua, 1);
+ xm_thread_t *thread = (xm_thread_t *)xm_lua_topointer(lua, 1);
tb_check_return_val(thread->handle, 0);
// get timeout
@@ -54,4 +53,3 @@ tb_int_t xm_thread_wait(lua_State* lua)
lua_pushinteger(lua, (tb_int_t)tb_thread_wait(thread->handle, timeout, &retval));
return 1;
}
-