|
24 | 24 | #include "butil/macros.h" // BAIDU_CASSERT |
25 | 25 | #include "butil/logging.h" |
26 | 26 | #include "butil/thread_local.h" |
| 27 | +#include "butil/reloadable_flags.h" |
27 | 28 | #include "bthread/task_group.h" // TaskGroup |
28 | 29 | #include "bthread/task_control.h" // TaskControl |
29 | 30 | #include "bthread/timer_thread.h" |
|
32 | 33 |
|
33 | 34 | namespace bthread { |
34 | 35 |
|
| 36 | +static bool validate_bthread_concurrency(const char*, int32_t val) { |
| 37 | + // bthread_setconcurrency sets the flag on success path which should |
| 38 | + // not be strictly in a validator. But it's OK for a int flag. |
| 39 | + return bthread_setconcurrency(val) == 0; |
| 40 | +} |
| 41 | +static bool validate_bthread_min_concurrency(const char*, int32_t val); |
| 42 | +static bool validate_bthread_current_tag(const char*, int32_t val); |
| 43 | +static bool validate_bthread_concurrency_by_tag(const char*, int32_t val); |
| 44 | + |
35 | 45 | DEFINE_int32(bthread_concurrency, 8 + BTHREAD_EPOLL_THREAD_NUM, |
36 | 46 | "Number of pthread workers"); |
| 47 | +BUTIL_VALIDATE_GFLAG(bthread_concurrency, validate_bthread_concurrency); |
37 | 48 |
|
38 | 49 | DEFINE_int32(bthread_min_concurrency, 0, |
39 | 50 | "Initial number of pthread workers which will be added on-demand." |
40 | 51 | " The laziness is disabled when this value is non-positive," |
41 | 52 | " and workers will be created eagerly according to -bthread_concurrency and bthread_setconcurrency(). "); |
| 53 | +BUTIL_VALIDATE_GFLAG(bthread_min_concurrency, validate_bthread_min_concurrency); |
42 | 54 |
|
43 | 55 | DEFINE_int32(bthread_current_tag, BTHREAD_TAG_INVALID, "Set bthread concurrency for this tag"); |
| 56 | +BUTIL_VALIDATE_GFLAG(bthread_current_tag, validate_bthread_current_tag); |
44 | 57 |
|
45 | 58 | DEFINE_int32(bthread_concurrency_by_tag, 8 + BTHREAD_EPOLL_THREAD_NUM, |
46 | 59 | "Number of pthread workers of FLAGS_bthread_current_tag"); |
| 60 | +BUTIL_VALIDATE_GFLAG(bthread_concurrency_by_tag, validate_bthread_concurrency_by_tag); |
47 | 61 |
|
48 | 62 | static bool never_set_bthread_concurrency = true; |
49 | 63 |
|
50 | | -static bool validate_bthread_concurrency(const char*, int32_t val) { |
51 | | - // bthread_setconcurrency sets the flag on success path which should |
52 | | - // not be strictly in a validator. But it's OK for a int flag. |
53 | | - return bthread_setconcurrency(val) == 0; |
54 | | -} |
55 | | -const int ALLOW_UNUSED register_FLAGS_bthread_concurrency = |
56 | | - ::GFLAGS_NS::RegisterFlagValidator(&FLAGS_bthread_concurrency, |
57 | | - validate_bthread_concurrency); |
58 | | - |
59 | | -static bool validate_bthread_min_concurrency(const char*, int32_t val); |
60 | | - |
61 | | -const int ALLOW_UNUSED register_FLAGS_bthread_min_concurrency = |
62 | | - ::GFLAGS_NS::RegisterFlagValidator(&FLAGS_bthread_min_concurrency, |
63 | | - validate_bthread_min_concurrency); |
64 | | - |
65 | | -static bool validate_bthread_current_tag(const char*, int32_t val); |
66 | | - |
67 | | -const int ALLOW_UNUSED register_FLAGS_bthread_current_tag = |
68 | | - ::GFLAGS_NS::RegisterFlagValidator(&FLAGS_bthread_current_tag, validate_bthread_current_tag); |
69 | | - |
70 | | -static bool validate_bthread_concurrency_by_tag(const char*, int32_t val); |
71 | | - |
72 | | -const int ALLOW_UNUSED register_FLAGS_bthread_concurrency_by_tag = |
73 | | - ::GFLAGS_NS::RegisterFlagValidator(&FLAGS_bthread_concurrency_by_tag, |
74 | | - validate_bthread_concurrency_by_tag); |
75 | | - |
76 | 64 | BAIDU_CASSERT(sizeof(TaskControl*) == sizeof(butil::atomic<TaskControl*>), atomic_size_match); |
77 | 65 |
|
78 | 66 | pthread_mutex_t g_task_control_mutex = PTHREAD_MUTEX_INITIALIZER; |
|
0 commit comments