mirror of
https://github.com/zlgopen/awtk.git
synced 2025-05-08 19:44:45 +08:00
improve mutex
This commit is contained in:
parent
2456be86b6
commit
fcb5dd8f22
@ -174,7 +174,8 @@ ret_t canvas_set_clip_rect(canvas_t* c, const rect_t* r_in) {
|
||||
#ifdef WITH_NANOVG_GPU
|
||||
/* 在 opengl 的状态下让 vg 来处理裁剪区的大小直接交给 vg 来处理,去除 LCD 的大小限制的问题 */
|
||||
if (r) {
|
||||
rect_t clip_r = rect_init(tk_max(0, r->x), tk_max(0, r->y), tk_max(0, lcd_w), tk_max(0, lcd_h));
|
||||
rect_t clip_r =
|
||||
rect_init(tk_max(0, r->x), tk_max(0, r->y), tk_max(0, lcd_w), tk_max(0, lcd_h));
|
||||
lcd_set_clip_rect(c->lcd, &clip_r);
|
||||
} else {
|
||||
rect_t clip_r = rect_init(0, 0, lcd_w, lcd_h);
|
||||
|
@ -52,13 +52,22 @@ tk_mutex_t* tk_mutex_create() {
|
||||
ret_t tk_mutex_lock(tk_mutex_t* mutex) {
|
||||
return_value_if_fail(mutex != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return SDL_LockMutex(mutex->mutex) == 0 ? RET_OK : RET_FAIL;
|
||||
if (SDL_LockMutex(mutex->mutex) != 0) {
|
||||
log_debug("SDL_LockMutex fail\n");
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t tk_mutex_unlock(tk_mutex_t* mutex) {
|
||||
return_value_if_fail(mutex != NULL, RET_BAD_PARAMS);
|
||||
if (SDL_UnlockMutex(mutex->mutex) != 0) {
|
||||
log_debug("SDL_UnlockMutex fail\n");
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
return SDL_UnlockMutex(mutex->mutex) == 0 ? RET_OK : RET_FAIL;
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t tk_mutex_destroy(tk_mutex_t* mutex) {
|
||||
|
@ -3,23 +3,11 @@
|
||||
#include "tkc/thread.h"
|
||||
#include "tkc/platform.h"
|
||||
|
||||
static void* thread_entry(void* args) {
|
||||
tk_mutex_t* mutex = (tk_mutex_t*)args;
|
||||
|
||||
sleep_ms(100);
|
||||
tk_mutex_lock(mutex);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TEST(Mutex, basic) {
|
||||
tk_mutex_t* mutex = tk_mutex_create();
|
||||
tk_thread_t* thread = tk_thread_create(thread_entry, mutex);
|
||||
|
||||
tk_thread_start(thread);
|
||||
ASSERT_EQ(tk_mutex_lock(mutex), RET_OK);
|
||||
ASSERT_EQ(tk_mutex_unlock(mutex), RET_OK);
|
||||
tk_thread_join(thread);
|
||||
|
||||
tk_thread_destroy(thread);
|
||||
tk_mutex_destroy(mutex);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user