diff options
| author | 2023-02-22 08:39:54 +0100 | |
|---|---|---|
| committer | 2023-02-22 08:39:54 +0100 | |
| commit | 2bfebba7be63518f337663ec9a81a4be0de835f7 (patch) | |
| tree | a637980ea3d963f75aa8decc48b34d732ccc64a1 | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | penes-snac2-2bfebba7be63518f337663ec9a81a4be0de835f7.tar.gz penes-snac2-2bfebba7be63518f337663ec9a81a4be0de835f7.tar.xz penes-snac2-2bfebba7be63518f337663ec9a81a4be0de835f7.zip | |
Don't wait for 3 seconds if there were some q_items processed.
| -rw-r--r-- | activitypub.c | 15 | ||||
| -rw-r--r-- | httpd.c | 35 | ||||
| -rw-r--r-- | snac.h | 4 |
3 files changed, 38 insertions, 16 deletions
diff --git a/activitypub.c b/activitypub.c index 1d191b8..c05c859 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -1160,9 +1160,10 @@ void process_user_queue_item(snac *snac, xs_dict *q_item) | |||
| 1160 | } | 1160 | } |
| 1161 | 1161 | ||
| 1162 | 1162 | ||
| 1163 | void process_user_queue(snac *snac) | 1163 | int process_user_queue(snac *snac) |
| 1164 | /* processes a user's queue */ | 1164 | /* processes a user's queue */ |
| 1165 | { | 1165 | { |
| 1166 | int cnt = 0; | ||
| 1166 | xs *list = user_queue(snac); | 1167 | xs *list = user_queue(snac); |
| 1167 | 1168 | ||
| 1168 | xs_list *p = list; | 1169 | xs_list *p = list; |
| @@ -1177,7 +1178,10 @@ void process_user_queue(snac *snac) | |||
| 1177 | } | 1178 | } |
| 1178 | 1179 | ||
| 1179 | process_user_queue_item(snac, q_item); | 1180 | process_user_queue_item(snac, q_item); |
| 1181 | cnt++; | ||
| 1180 | } | 1182 | } |
| 1183 | |||
| 1184 | return cnt; | ||
| 1181 | } | 1185 | } |
| 1182 | 1186 | ||
| 1183 | 1187 | ||
| @@ -1299,9 +1303,10 @@ void process_queue_item(xs_dict *q_item) | |||
| 1299 | } | 1303 | } |
| 1300 | 1304 | ||
| 1301 | 1305 | ||
| 1302 | void process_queue(void) | 1306 | int process_queue(void) |
| 1303 | /* processes the global queue */ | 1307 | /* processes the global queue */ |
| 1304 | { | 1308 | { |
| 1309 | int cnt = 0; | ||
| 1305 | xs *list = queue(); | 1310 | xs *list = queue(); |
| 1306 | 1311 | ||
| 1307 | xs_list *p = list; | 1312 | xs_list *p = list; |
| @@ -1310,9 +1315,13 @@ void process_queue(void) | |||
| 1310 | while (xs_list_iter(&p, &fn)) { | 1315 | while (xs_list_iter(&p, &fn)) { |
| 1311 | xs *q_item = dequeue(fn); | 1316 | xs *q_item = dequeue(fn); |
| 1312 | 1317 | ||
| 1313 | if (q_item != NULL) | 1318 | if (q_item != NULL) { |
| 1314 | job_post(q_item); | 1319 | job_post(q_item); |
| 1320 | cnt++; | ||
| 1321 | } | ||
| 1315 | } | 1322 | } |
| 1323 | |||
| 1324 | return cnt; | ||
| 1316 | } | 1325 | } |
| 1317 | 1326 | ||
| 1318 | 1327 | ||
| @@ -17,6 +17,10 @@ | |||
| 17 | 17 | ||
| 18 | #include <sys/resource.h> // for getrlimit() | 18 | #include <sys/resource.h> // for getrlimit() |
| 19 | 19 | ||
| 20 | #ifdef USE_POLL_FOR_SLEEP | ||
| 21 | #include <poll.h> | ||
| 22 | #endif | ||
| 23 | |||
| 20 | 24 | ||
| 21 | /* nodeinfo 2.0 template */ | 25 | /* nodeinfo 2.0 template */ |
| 22 | const char *nodeinfo_2_0_template = "" | 26 | const char *nodeinfo_2_0_template = "" |
| @@ -338,6 +342,7 @@ static void *job_thread(void *arg) | |||
| 338 | return NULL; | 342 | return NULL; |
| 339 | } | 343 | } |
| 340 | 344 | ||
| 345 | #include <poll.h> | ||
| 341 | 346 | ||
| 342 | static void *background_thread(void *arg) | 347 | static void *background_thread(void *arg) |
| 343 | /* background thread (queue management and other things) */ | 348 | /* background thread (queue management and other things) */ |
| @@ -351,6 +356,7 @@ static void *background_thread(void *arg) | |||
| 351 | 356 | ||
| 352 | while (srv_running) { | 357 | while (srv_running) { |
| 353 | time_t t; | 358 | time_t t; |
| 359 | int cnt = 0; | ||
| 354 | 360 | ||
| 355 | { | 361 | { |
| 356 | xs *list = user_list(); | 362 | xs *list = user_list(); |
| @@ -362,14 +368,14 @@ static void *background_thread(void *arg) | |||
| 362 | snac snac; | 368 | snac snac; |
| 363 | 369 | ||
| 364 | if (user_open(&snac, uid)) { | 370 | if (user_open(&snac, uid)) { |
| 365 | process_user_queue(&snac); | 371 | cnt += process_user_queue(&snac); |
| 366 | user_free(&snac); | 372 | user_free(&snac); |
| 367 | } | 373 | } |
| 368 | } | 374 | } |
| 369 | } | 375 | } |
| 370 | 376 | ||
| 371 | /* global queue */ | 377 | /* global queue */ |
| 372 | process_queue(); | 378 | cnt += process_queue(); |
| 373 | 379 | ||
| 374 | /* time to purge? */ | 380 | /* time to purge? */ |
| 375 | if ((t = time(NULL)) > purge_time) { | 381 | if ((t = time(NULL)) > purge_time) { |
| @@ -381,17 +387,24 @@ static void *background_thread(void *arg) | |||
| 381 | job_post(q_item); | 387 | job_post(q_item); |
| 382 | } | 388 | } |
| 383 | 389 | ||
| 384 | /* sleep 3 seconds */ | 390 | if (cnt == 0) { |
| 385 | pthread_mutex_t dummy_mutex = PTHREAD_MUTEX_INITIALIZER; | 391 | /* sleep 3 seconds */ |
| 386 | pthread_cond_t dummy_cond = PTHREAD_COND_INITIALIZER; | 392 | |
| 387 | struct timespec ts; | 393 | #ifdef USE_POLL_FOR_SLEEP |
| 394 | poll(NULL, 0, 3 * 1000); | ||
| 395 | #else | ||
| 396 | pthread_mutex_t dummy_mutex = PTHREAD_MUTEX_INITIALIZER; | ||
| 397 | pthread_cond_t dummy_cond = PTHREAD_COND_INITIALIZER; | ||
| 398 | struct timespec ts; | ||
| 388 | 399 | ||
| 389 | clock_gettime(CLOCK_REALTIME, &ts); | 400 | clock_gettime(CLOCK_REALTIME, &ts); |
| 390 | ts.tv_sec += 3; | 401 | ts.tv_sec += 3; |
| 391 | 402 | ||
| 392 | pthread_mutex_lock(&dummy_mutex); | 403 | pthread_mutex_lock(&dummy_mutex); |
| 393 | while (pthread_cond_timedwait(&dummy_cond, &dummy_mutex, &ts) == 0); | 404 | while (pthread_cond_timedwait(&dummy_cond, &dummy_mutex, &ts) == 0); |
| 394 | pthread_mutex_unlock(&dummy_mutex); | 405 | pthread_mutex_unlock(&dummy_mutex); |
| 406 | #endif | ||
| 407 | } | ||
| 395 | } | 408 | } |
| 396 | 409 | ||
| 397 | srv_log(xs_fmt("background thread stopped")); | 410 | srv_log(xs_fmt("background thread stopped")); |
| @@ -190,9 +190,9 @@ d_char *get_actor_inbox(snac *snac, char *actor); | |||
| 190 | int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout); | 190 | int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout); |
| 191 | int is_msg_public(snac *snac, char *msg); | 191 | int is_msg_public(snac *snac, char *msg); |
| 192 | 192 | ||
| 193 | void process_user_queue(snac *snac); | 193 | int process_user_queue(snac *snac); |
| 194 | void process_queue_item(xs_dict *q_item); | 194 | void process_queue_item(xs_dict *q_item); |
| 195 | void process_queue(void); | 195 | int process_queue(void); |
| 196 | 196 | ||
| 197 | int activitypub_get_handler(d_char *req, char *q_path, | 197 | int activitypub_get_handler(d_char *req, char *q_path, |
| 198 | char **body, int *b_size, char **ctype); | 198 | char **body, int *b_size, char **ctype); |