... | ... |
@@ -39,6 +39,7 @@ typedef struct bg_t { |
39 | 39 |
int sizebgload; |
40 | 40 |
bgload_t *bgload; |
41 | 41 |
pthread_t thread; |
42 |
+ char pinnedpath[1024]; |
|
42 | 43 |
pthread_attr_t tattr; |
43 | 44 |
int flag_threadstarted; |
44 | 45 |
int do_exit; |
... | ... |
@@ -52,7 +53,7 @@ bg_t *bg_init(int sizebgload); |
52 | 53 |
void bg_free(bg_t *bg); |
53 | 54 |
int bg_resetmarks(bg_t *bg); |
54 | 55 |
bgload_t *bg_get(bg_t *bg, char *path); |
55 |
-int bg_add(bg_t *bg, char *path); |
|
56 |
+int bg_add(bg_t *bg, char *path, int flag_pinned); /* only one image is pinned (excluded from unload) */ |
|
56 | 57 |
int bg_freeunmarked(bg_t *bg); |
57 | 58 |
|
58 | 59 |
void *bg_thread(void *); |
... | ... |
@@ -16,7 +16,6 @@ |
16 | 16 |
#ifndef BG_H |
17 | 17 |
#define BG_H |
18 | 18 |
|
19 |
-#include <pthread.h> |
|
20 | 19 |
#include <time.h> |
21 | 20 |
#include <sys/time.h> |
22 | 21 |
#include "raylib.h" |
... | ... |
@@ -39,10 +38,10 @@ typedef struct bgload_t { |
39 | 38 |
typedef struct bg_t { |
40 | 39 |
int sizebgload; |
41 | 40 |
bgload_t *bgload; |
42 |
- int pipe[2]; |
|
43 | 41 |
pthread_t thread; |
44 | 42 |
pthread_attr_t tattr; |
45 | 43 |
int flag_threadstarted; |
44 |
+ int do_exit; |
|
46 | 45 |
} bg_t; |
47 | 46 |
|
48 | 47 |
|
... | ... |
@@ -17,6 +17,8 @@ |
17 | 17 |
#define BG_H |
18 | 18 |
|
19 | 19 |
#include <pthread.h> |
20 |
+#include <time.h> |
|
21 |
+#include <sys/time.h> |
|
20 | 22 |
#include "raylib.h" |
21 | 23 |
|
22 | 24 |
typedef struct bgload_t { |
... | ... |
@@ -30,6 +32,8 @@ typedef struct bgload_t { |
30 | 32 |
Image image; // to use only from owner |
31 | 33 |
int has_data; // to use only from owner |
32 | 34 |
int has_failedload; // to use only from owner |
35 |
+ time_t lastused; // to don't purge until some time has passed after load |
|
36 |
+ struct timeval tv_lastadded; // to be able to load the "most recently added bgload" first |
|
33 | 37 |
} bgload_t; |
34 | 38 |
|
35 | 39 |
typedef struct bg_t { |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,60 @@ |
1 |
+/* |
|
2 |
+ * bg.c |
|
3 |
+ * |
|
4 |
+ * Wrapper over pthread with the addition of some interthread comms. |
|
5 |
+ * |
|
6 |
+ * HEADER FILE |
|
7 |
+ * |
|
8 |
+ * History: |
|
9 |
+ * 20250904 Creation from imgmover prototype. |
|
10 |
+ * |
|
11 |
+ * Author: Dario Rodriguez dario@darionomono.com |
|
12 |
+ * (c) Dario Rodriguez 2025 |
|
13 |
+ * This program is licensed under the terms of GNU GPL v2.1+ |
|
14 |
+ */ |
|
15 |
+ |
|
16 |
+#ifndef BG_H |
|
17 |
+#define BG_H |
|
18 |
+ |
|
19 |
+#include <pthread.h> |
|
20 |
+#include "raylib.h" |
|
21 |
+ |
|
22 |
+typedef struct bgload_t { |
|
23 |
+ /* main/thread ownership management */ |
|
24 |
+ int lended_to_thread; // written from main, read from thread |
|
25 |
+ int thread_finished; // written from thread, read from main |
|
26 |
+ int is_todo; // written from main, read from thread |
|
27 |
+ int has_mark; // written/read from main |
|
28 |
+ /* data only accessed from owner */ |
|
29 |
+ char path[1024]; // to use only from owner |
|
30 |
+ Image image; // to use only from owner |
|
31 |
+ int has_data; // to use only from owner |
|
32 |
+ int has_failedload; // to use only from owner |
|
33 |
+} bgload_t; |
|
34 |
+ |
|
35 |
+typedef struct bg_t { |
|
36 |
+ int sizebgload; |
|
37 |
+ bgload_t *bgload; |
|
38 |
+ int pipe[2]; |
|
39 |
+ pthread_t thread; |
|
40 |
+ pthread_attr_t tattr; |
|
41 |
+ int flag_threadstarted; |
|
42 |
+} bg_t; |
|
43 |
+ |
|
44 |
+ |
|
45 |
+void bg_staticinit(void); |
|
46 |
+void bg_staticfini(void); |
|
47 |
+ |
|
48 |
+bg_t *bg_init(int sizebgload); |
|
49 |
+void bg_free(bg_t *bg); |
|
50 |
+int bg_resetmarks(bg_t *bg); |
|
51 |
+bgload_t *bg_get(bg_t *bg, char *path); |
|
52 |
+int bg_add(bg_t *bg, char *path); |
|
53 |
+int bg_freeunmarked(bg_t *bg); |
|
54 |
+ |
|
55 |
+void *bg_thread(void *); |
|
56 |
+ |
|
57 |
+ |
|
58 |
+#endif |
|
59 |
+ |
|
60 |
+ |