Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib/intern/BLI_timer.c')
-rw-r--r--source/blender/blenlib/intern/BLI_timer.c200
1 files changed, 101 insertions, 99 deletions
diff --git a/source/blender/blenlib/intern/BLI_timer.c b/source/blender/blenlib/intern/BLI_timer.c
index 77409015aa6..bf9fd1b57f8 100644
--- a/source/blender/blenlib/intern/BLI_timer.c
+++ b/source/blender/blenlib/intern/BLI_timer.c
@@ -31,154 +31,156 @@
#define GET_TIME() PIL_check_seconds_timer()
typedef struct TimedFunction {
- struct TimedFunction *next, *prev;
- BLI_timer_func func;
- BLI_timer_data_free user_data_free;
- void *user_data;
- double next_time;
- uintptr_t uuid;
- bool tag_removal;
- bool persistent;
+ struct TimedFunction *next, *prev;
+ BLI_timer_func func;
+ BLI_timer_data_free user_data_free;
+ void *user_data;
+ double next_time;
+ uintptr_t uuid;
+ bool tag_removal;
+ bool persistent;
} TimedFunction;
typedef struct TimerContainer {
- ListBase funcs;
- bool file_load_cb_registered;
+ ListBase funcs;
+ bool file_load_cb_registered;
} TimerContainer;
static TimerContainer GlobalTimer = {{0}};
static void ensure_callback_is_registered(void);
-void BLI_timer_register(
- uintptr_t uuid,
- BLI_timer_func func,
- void *user_data,
- BLI_timer_data_free user_data_free,
- double first_interval,
- bool persistent)
+void BLI_timer_register(uintptr_t uuid,
+ BLI_timer_func func,
+ void *user_data,
+ BLI_timer_data_free user_data_free,
+ double first_interval,
+ bool persistent)
{
- ensure_callback_is_registered();
-
- TimedFunction *timed_func = MEM_callocN(sizeof(TimedFunction), __func__);
- timed_func->func = func;
- timed_func->user_data_free = user_data_free;
- timed_func->user_data = user_data;
- timed_func->next_time = GET_TIME() + first_interval;
- timed_func->tag_removal = false;
- timed_func->persistent = persistent;
- timed_func->uuid = uuid;
-
- BLI_addtail(&GlobalTimer.funcs, timed_func);
+ ensure_callback_is_registered();
+
+ TimedFunction *timed_func = MEM_callocN(sizeof(TimedFunction), __func__);
+ timed_func->func = func;
+ timed_func->user_data_free = user_data_free;
+ timed_func->user_data = user_data;
+ timed_func->next_time = GET_TIME() + first_interval;
+ timed_func->tag_removal = false;
+ timed_func->persistent = persistent;
+ timed_func->uuid = uuid;
+
+ BLI_addtail(&GlobalTimer.funcs, timed_func);
}
static void clear_user_data(TimedFunction *timed_func)
{
- if (timed_func->user_data_free) {
- timed_func->user_data_free(timed_func->uuid, timed_func->user_data);
- timed_func->user_data_free = NULL;
- }
+ if (timed_func->user_data_free) {
+ timed_func->user_data_free(timed_func->uuid, timed_func->user_data);
+ timed_func->user_data_free = NULL;
+ }
}
bool BLI_timer_unregister(uintptr_t uuid)
{
- LISTBASE_FOREACH(TimedFunction *, timed_func, &GlobalTimer.funcs) {
- if (timed_func->uuid == uuid) {
- if (timed_func->tag_removal) {
- return false;
- }
- else {
- timed_func->tag_removal = true;
- clear_user_data(timed_func);
- return true;
- }
- }
- }
- return false;
+ LISTBASE_FOREACH (TimedFunction *, timed_func, &GlobalTimer.funcs) {
+ if (timed_func->uuid == uuid) {
+ if (timed_func->tag_removal) {
+ return false;
+ }
+ else {
+ timed_func->tag_removal = true;
+ clear_user_data(timed_func);
+ return true;
+ }
+ }
+ }
+ return false;
}
bool BLI_timer_is_registered(uintptr_t uuid)
{
- LISTBASE_FOREACH(TimedFunction *, timed_func, &GlobalTimer.funcs) {
- if (timed_func->uuid == uuid && !timed_func->tag_removal) {
- return true;
- }
- }
- return false;
+ LISTBASE_FOREACH (TimedFunction *, timed_func, &GlobalTimer.funcs) {
+ if (timed_func->uuid == uuid && !timed_func->tag_removal) {
+ return true;
+ }
+ }
+ return false;
}
static void execute_functions_if_necessary(void)
{
- double current_time = GET_TIME();
-
- LISTBASE_FOREACH(TimedFunction *, timed_func, &GlobalTimer.funcs) {
- if (timed_func->tag_removal) {
- continue;
- }
- if (timed_func->next_time > current_time) {
- continue;
- }
-
- double ret = timed_func->func(timed_func->uuid, timed_func->user_data);
-
- if (ret < 0) {
- timed_func->tag_removal = true;
- }
- else {
- timed_func->next_time = current_time + ret;
- }
- }
+ double current_time = GET_TIME();
+
+ LISTBASE_FOREACH (TimedFunction *, timed_func, &GlobalTimer.funcs) {
+ if (timed_func->tag_removal) {
+ continue;
+ }
+ if (timed_func->next_time > current_time) {
+ continue;
+ }
+
+ double ret = timed_func->func(timed_func->uuid, timed_func->user_data);
+
+ if (ret < 0) {
+ timed_func->tag_removal = true;
+ }
+ else {
+ timed_func->next_time = current_time + ret;
+ }
+ }
}
static void remove_tagged_functions(void)
{
- for (TimedFunction *timed_func = GlobalTimer.funcs.first; timed_func; ) {
- TimedFunction *next = timed_func->next;
- if (timed_func->tag_removal) {
- clear_user_data(timed_func);
- BLI_freelinkN(&GlobalTimer.funcs, timed_func);
- }
- timed_func = next;
- }
+ for (TimedFunction *timed_func = GlobalTimer.funcs.first; timed_func;) {
+ TimedFunction *next = timed_func->next;
+ if (timed_func->tag_removal) {
+ clear_user_data(timed_func);
+ BLI_freelinkN(&GlobalTimer.funcs, timed_func);
+ }
+ timed_func = next;
+ }
}
void BLI_timer_execute()
{
- execute_functions_if_necessary();
- remove_tagged_functions();
+ execute_functions_if_necessary();
+ remove_tagged_functions();
}
void BLI_timer_free()
{
- LISTBASE_FOREACH(TimedFunction *, timed_func, &GlobalTimer.funcs) {
- timed_func->tag_removal = true;
- }
+ LISTBASE_FOREACH (TimedFunction *, timed_func, &GlobalTimer.funcs) {
+ timed_func->tag_removal = true;
+ }
- remove_tagged_functions();
+ remove_tagged_functions();
}
struct ID;
struct Main;
-static void remove_non_persistent_functions(struct Main *UNUSED(_1), struct ID *UNUSED(_2), void *UNUSED(_3))
+static void remove_non_persistent_functions(struct Main *UNUSED(_1),
+ struct ID *UNUSED(_2),
+ void *UNUSED(_3))
{
- LISTBASE_FOREACH(TimedFunction *, timed_func, &GlobalTimer.funcs) {
- if (!timed_func->persistent) {
- timed_func->tag_removal = true;
- }
- }
+ LISTBASE_FOREACH (TimedFunction *, timed_func, &GlobalTimer.funcs) {
+ if (!timed_func->persistent) {
+ timed_func->tag_removal = true;
+ }
+ }
}
static bCallbackFuncStore load_pre_callback = {
- NULL, NULL, /* next, prev */
- remove_non_persistent_functions, /* func */
- NULL, /* arg */
- 0, /* alloc */
+ NULL,
+ NULL, /* next, prev */
+ remove_non_persistent_functions, /* func */
+ NULL, /* arg */
+ 0, /* alloc */
};
static void ensure_callback_is_registered()
{
- if (!GlobalTimer.file_load_cb_registered) {
- BLI_callback_add(&load_pre_callback, BLI_CB_EVT_LOAD_PRE);
- GlobalTimer.file_load_cb_registered = true;
- }
+ if (!GlobalTimer.file_load_cb_registered) {
+ BLI_callback_add(&load_pre_callback, BLI_CB_EVT_LOAD_PRE);
+ GlobalTimer.file_load_cb_registered = true;
+ }
}