Skip to content

Commit f80f4db

Browse files
Add function to expose parallel worker threads (#352)
* Add function to expose parallel worker threads
1 parent 3955f21 commit f80f4db

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

php_parallel.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,12 @@ extern zend_module_entry parallel_module_entry;
3030
ZEND_TSRMLS_CACHE_EXTERN()
3131
# endif
3232

33-
#endif /* PHP_PARALLEL_H */
33+
#if _WIN32
34+
# define PARALLEL_API __declspec(dllexport)
35+
#else
36+
# define PARALLEL_API __attribute__ ((visibility("default")))
37+
#endif
38+
39+
PARALLEL_API bool php_parallel_is_parallel_worker_thread(void);
3440

41+
#endif /* PHP_PARALLEL_H */

src/scheduler.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define HAVE_PARALLEL_SCHEDULER
2020

2121
#include "parallel.h"
22+
#include "../php_parallel.h"
2223
#include "zend_types.h"
2324

2425
TSRM_TLS php_parallel_runtime_t* php_parallel_scheduler_context = NULL;
@@ -179,7 +180,7 @@ static zend_always_inline void php_parallel_scheduler_add(
179180
}
180181
}
181182

182-
static zend_always_inline zend_bool php_parallel_scheduler_empty(php_parallel_runtime_t *runtime) {
183+
static zend_always_inline bool php_parallel_scheduler_empty(php_parallel_runtime_t *runtime) {
183184
return !zend_llist_count(&runtime->schedule);
184185
}
185186

@@ -683,6 +684,10 @@ zend_bool php_parallel_scheduler_cancel(php_parallel_future_t *future) {
683684
}
684685
}
685686

687+
PARALLEL_API bool php_parallel_is_parallel_worker_thread(void) {
688+
return php_parallel_scheduler_context != NULL;
689+
}
690+
686691
static void php_parallel_scheduler_interrupt(zend_execute_data *execute_data) {
687692
if (php_parallel_scheduler_context) {
688693
php_parallel_monitor_lock(php_parallel_scheduler_context->monitor);

0 commit comments

Comments
 (0)