]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Convert the isc/tid.h to use own signed integer isc_tid_t type
authorOndřej Surý <ondrej@isc.org>
Wed, 4 Jun 2025 15:54:20 +0000 (17:54 +0200)
committerOndřej Surý <ondrej@isc.org>
Sat, 28 Jun 2025 11:32:12 +0000 (13:32 +0200)
Change the internal type used for isc_tid unit to isc_tid_t to hide the
specific integer type being used for the 'tid'.  Internally, the signed
integer type is being used.  This allows us to have negatively indexed
arrays that works both for threads with assigned tid and the threads
with unassigned tid.  This should be used only in specific situations.

34 files changed:
lib/dns/badcache.c
lib/dns/dispatch.c
lib/dns/include/dns/qp.h
lib/dns/include/dns/validator.h
lib/dns/include/dns/zone.h
lib/dns/qp.c
lib/dns/request.c
lib/dns/resolver.c
lib/dns/unreachcache.c
lib/dns/zone.c
lib/isc/include/isc/loop.h
lib/isc/include/isc/netmgr.h
lib/isc/include/isc/refcount.h
lib/isc/include/isc/tid.h
lib/isc/include/isc/uv.h
lib/isc/loop.c
lib/isc/loop_p.h
lib/isc/netmgr/http.c
lib/isc/netmgr/netmgr-int.h
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/proxyudp.c
lib/isc/netmgr/streamdns.c
lib/isc/netmgr/tcp.c
lib/isc/netmgr/tlsstream.c
lib/isc/netmgr/udp.c
lib/isc/tid.c
lib/ns/client.c
lib/ns/include/ns/client.h
lib/ns/interfacemgr.c
tests/bench/qpmulti.c
tests/dns/dispatch_test.c
tests/isc/async_test.c
tests/isc/netmgr_common.h
tests/isc/work_test.c

index 47d3b8123638cc834a82e25e874ca2b78d6e9993..a474d182e61bae5faf6b48d3045424ed3ce62e5f 100644 (file)
@@ -254,7 +254,7 @@ dns_badcache_add(dns_badcache_t *bc, const dns_name_t *name,
        REQUIRE(name != NULL);
 
        isc_loop_t *loop = isc_loop();
-       uint32_t tid = isc_tid();
+       isc_tid_t tid = isc_tid();
        struct cds_list_head *lru = &bc->lru[tid];
 
        isc_stdtime_t now = isc_stdtime_now();
@@ -320,7 +320,7 @@ dns_badcache_find(dns_badcache_t *bc, const dns_name_t *name,
                }
        }
 
-       uint32_t tid = isc_tid();
+       isc_tid_t tid = isc_tid();
        struct cds_list_head *lru = &bc->lru[tid];
        bcentry_purge(ht, lru, now);
 
index c7e99bfb561565ecaaeda84e8eab9dea291eeef5..9f5f8a8eedab00be9c6b8fa8c2dfe2266b447015 100644 (file)
@@ -110,7 +110,7 @@ struct dns_dispentry {
 struct dns_dispatch {
        /* Unlocked. */
        unsigned int magic; /*%< magic */
-       uint32_t tid;
+       isc_tid_t tid;
        isc_socktype_t socktype;
        isc_refcount_t references;
        isc_mem_t *mctx;
@@ -186,7 +186,7 @@ static void
 dispentry_cancel(dns_dispentry_t *resp, isc_result_t result);
 static isc_result_t
 dispatch_createudp(dns_dispatchmgr_t *mgr, const isc_sockaddr_t *localaddr,
-                  uint32_t tid, dns_dispatch_t **dispp);
+                  isc_tid_t tid, dns_dispatch_t **dispp);
 static void
 udp_startrecv(isc_nmhandle_t *handle, dns_dispentry_t *resp);
 static void
@@ -1102,7 +1102,7 @@ dns_dispatchmgr_getnetmgr(dns_dispatchmgr_t *mgr) {
  * Allocate and set important limits.
  */
 static void
-dispatch_allocate(dns_dispatchmgr_t *mgr, isc_socktype_t type, uint32_t tid,
+dispatch_allocate(dns_dispatchmgr_t *mgr, isc_socktype_t type, isc_tid_t tid,
                  dns_dispatch_t **dispp) {
        dns_dispatch_t *disp = NULL;
 
@@ -1168,7 +1168,7 @@ dns_dispatch_createtcp(dns_dispatchmgr_t *mgr, const isc_sockaddr_t *localaddr,
                       dns_transport_t *transport, dns_dispatchopt_t options,
                       dns_dispatch_t **dispp) {
        dns_dispatch_t *disp = NULL;
-       uint32_t tid = isc_tid();
+       isc_tid_t tid = isc_tid();
 
        REQUIRE(VALID_DISPATCHMGR(mgr));
        REQUIRE(destaddr != NULL);
@@ -1229,7 +1229,7 @@ dns_dispatch_gettcp(dns_dispatchmgr_t *mgr, const isc_sockaddr_t *destaddr,
        dns_dispatch_t *disp_connected = NULL;
        dns_dispatch_t *disp_fallback = NULL;
        isc_result_t result = ISC_R_NOTFOUND;
-       uint32_t tid = isc_tid();
+       isc_tid_t tid = isc_tid();
 
        REQUIRE(VALID_DISPATCHMGR(mgr));
        REQUIRE(destaddr != NULL);
@@ -1326,7 +1326,7 @@ dns_dispatch_createudp(dns_dispatchmgr_t *mgr, const isc_sockaddr_t *localaddr,
 
 static isc_result_t
 dispatch_createudp(dns_dispatchmgr_t *mgr, const isc_sockaddr_t *localaddr,
-                  uint32_t tid, dns_dispatch_t **dispp) {
+                  isc_tid_t tid, dns_dispatch_t **dispp) {
        isc_result_t result = ISC_R_SUCCESS;
        dns_dispatch_t *disp = NULL;
        isc_sockaddr_t sa_any;
@@ -1379,7 +1379,7 @@ dispatch_destroy_rcu(struct rcu_head *rcu_head) {
 static void
 dispatch_destroy(dns_dispatch_t *disp) {
        dns_dispatchmgr_t *mgr = disp->mgr;
-       uint32_t tid = isc_tid();
+       isc_tid_t tid = isc_tid();
 
        disp->magic = 0;
 
@@ -2237,14 +2237,14 @@ dns_dispentry_getlocaladdress(dns_dispentry_t *resp, isc_sockaddr_t *addrp) {
 
 dns_dispatch_t *
 dns_dispatchset_get(dns_dispatchset_t *dset) {
-       uint32_t tid = isc_tid();
+       isc_tid_t tid = isc_tid();
 
        /* check that dispatch set is configured */
        if (dset == NULL || dset->ndisp == 0) {
                return NULL;
        }
 
-       INSIST(tid < dset->ndisp);
+       INSIST((uint32_t)tid < dset->ndisp);
 
        return dset->dispatches[tid];
 }
index d72730c80acb94ea7adcfcee2a846f3b8dcf5906..bbac5ca6fbaf729ee076e27078a7beeb4ddc0645 100644 (file)
@@ -150,7 +150,7 @@ typedef struct dns_qpreader {
  */
 typedef struct dns_qpread {
        DNS_QPREADER_FIELDS;
-       uint32_t tid;
+       isc_tid_t tid;
 } dns_qpread_t;
 
 /*%
index 6132ad88ec15fa5ec9dc7a46c43cdf3c6d2038fe..ba50a827f2483abd793c9519b1245c0ea1305721 100644 (file)
@@ -76,7 +76,7 @@ struct dns_validator {
        unsigned int   magic;
        dns_view_t    *view;
        isc_loop_t    *loop;
-       uint32_t       tid;
+       isc_tid_t      tid;
        isc_refcount_t references;
 
        /* Name and type of the response to be validated. */
index 20b5f885b18ef9e43581ceae21b1aee35c5e47bc..50f65c192132638203cafd91039a74e131aa0d78 100644 (file)
@@ -145,7 +145,7 @@ typedef enum {
  ***/
 
 void
-dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx, unsigned int tid);
+dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx, isc_tid_t tid);
 /*%<
  *     Creates a new empty zone and attach '*zonep' to it.
  *
index d2a8963162e2fb71ad7f82b62315876603e711ac..e0b709338bb4c614982453df965d61f7776af0d5 100644 (file)
@@ -86,7 +86,8 @@ static atomic_uint_fast64_t rollback_time;
                if (isc_log_wouldlog(ISC_LOG_DEBUG(7))) {                      \
                        isc_log_write(DNS_LOGCATEGORY_DATABASE,                \
                                      DNS_LOGMODULE_QP, ISC_LOG_DEBUG(7),      \
-                                     "%s:%d:%s(qp %p uctx \"%s\"):t%u: " fmt, \
+                                     "%s:%d:%s(qp %p uctx \"%s\"):t%" PRItid  \
+                                     ": " fmt,                                \
                                      __FILE__, __LINE__, __func__, qp,        \
                                      qp ? TRIENAME(qp) : "(null)", isc_tid(), \
                                      ##__VA_ARGS__);                          \
index 3d8da41d085b1bd86ae0f2e9da8ce57dd37232fa..b6913a901a2b1d98af01ebfc9a4ecd0f26ef5ec6 100644 (file)
@@ -67,7 +67,7 @@ struct dns_request {
        int32_t flags;
 
        isc_loop_t *loop;
-       unsigned int tid;
+       isc_tid_t tid;
 
        isc_result_t result;
        isc_job_cb cb;
@@ -172,10 +172,10 @@ dns_requestmgr_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr,
 static void
 requests_cancel(void *arg) {
        dns_requestmgr_t *requestmgr = arg;
-       uint32_t tid = isc_tid();
+       isc_tid_t tid = isc_tid();
 
        ISC_LIST_FOREACH (requestmgr->requests[tid], request, link) {
-               req_log(ISC_LOG_DEBUG(3), "%s(%" PRIu32 ": request %p",
+               req_log(ISC_LOG_DEBUG(3), "%s(%" PRItid ": request %p",
                        __func__, tid, request);
                if (DNS_REQUEST_COMPLETE(request)) {
                        /* The callback has been already scheduled */
@@ -210,12 +210,12 @@ dns_requestmgr_shutdown(dns_requestmgr_t *requestmgr) {
         */
        synchronize_rcu();
 
-       uint32_t tid = isc_tid();
+       isc_tid_t tid = isc_tid();
        uint32_t nloops = isc_loopmgr_nloops(requestmgr->loopmgr);
        for (size_t i = 0; i < nloops; i++) {
                dns_requestmgr_ref(requestmgr);
 
-               if (i == tid) {
+               if (i == (uint32_t)tid) {
                        /* Run the current loop synchronously */
                        requests_cancel(requestmgr);
                        continue;
index af4be39a4b1299176e2422826f06cfaf1d650491..749754a2743e7e010e23c912881e3cdf139432d4 100644 (file)
@@ -342,7 +342,7 @@ struct fetchctx {
        isc_stdtime_t now;
 
        isc_loop_t *loop;
-       unsigned int tid;
+       isc_tid_t tid;
 
        dns_edectx_t edectx;
 
index efbfd8605346f143f6fdc88ed5b3af59b3722f02..a0e852ccca587eee51e1a7a67c10037288c32be8 100644 (file)
@@ -291,7 +291,7 @@ dns_unreachcache_add(dns_unreachcache_t *uc, const isc_sockaddr_t *remote,
        REQUIRE(local != NULL);
 
        isc_loop_t *loop = isc_loop();
-       uint32_t tid = isc_tid();
+       isc_tid_t tid = isc_tid();
        struct cds_list_head *lru = &uc->lru[tid];
        isc_stdtime_t now = isc_stdtime_now();
        isc_stdtime_t expire = now + uc->expire_min_s;
@@ -377,7 +377,7 @@ dns_unreachcache_find(dns_unreachcache_t *uc, const isc_sockaddr_t *remote,
                result = ISC_R_SUCCESS;
        }
 
-       uint32_t tid = isc_tid();
+       isc_tid_t tid = isc_tid();
        struct cds_list_head *lru = &uc->lru[tid];
        ucentry_purge(ht, lru, now);
 
@@ -410,7 +410,7 @@ dns_unreachcache_remove(dns_unreachcache_t *uc, const isc_sockaddr_t *remote,
                ucentry_evict(ht, found);
        }
 
-       uint32_t tid = isc_tid();
+       isc_tid_t tid = isc_tid();
        struct cds_list_head *lru = &uc->lru[tid];
        ucentry_purge(ht, lru, now);
 
index 86eda3409f9554cd04c34c2d2a39e4bc8ef054d8..52c897c2a7bbd35b46e7a909fc2b377eaec34a71 100644 (file)
@@ -288,7 +288,7 @@ struct dns_zone {
        isc_rwlock_t dblock;
        dns_db_t *db; /* Locked by dblock */
 
-       unsigned int tid;
+       isc_tid_t tid;
 
        /* Locked */
        dns_zonemgr_t *zmgr;
@@ -1124,7 +1124,7 @@ inc_stats(dns_zone_t *zone, isc_statscounter_t counter) {
  ***/
 
 void
-dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx, unsigned int tid) {
+dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx, isc_tid_t tid) {
        isc_time_t now;
        dns_zone_t *zone = NULL;
 
@@ -19239,7 +19239,7 @@ isc_result_t
 dns_zonemgr_createzone(dns_zonemgr_t *zmgr, dns_zone_t **zonep) {
        isc_mem_t *mctx = NULL;
        dns_zone_t *zone = NULL;
-       unsigned int tid;
+       isc_tid_t tid;
 
        REQUIRE(DNS_ZONEMGR_VALID(zmgr));
        REQUIRE(zonep != NULL && *zonep == NULL);
index ae263d4e83c050f1e751191bf8366b20d31b93ff..2552548c3636db27170a11cf9e97d96150ec3a1e 100644 (file)
@@ -155,7 +155,7 @@ isc_loop_main(isc_loopmgr_t *loopmgr);
  */
 
 isc_loop_t *
-isc_loop_get(isc_loopmgr_t *loopmgr, uint32_t tid);
+isc_loop_get(isc_loopmgr_t *loopmgr, isc_tid_t tid);
 /*%<
  * Return the loop object associated with the 'tid' threadid
  *
index 8825c8c77d6b01adf2a360cab725ceb808beb8f0..14987514eaab0ce1e2cfd96547bea1cb4a3e7021 100644 (file)
@@ -917,7 +917,7 @@ isc_nm_verify_tls_peer_result_string(const isc_nmhandle_t *handle);
  */
 
 void
-isc__nm_force_tid(int tid);
+isc__nm_force_tid(isc_tid_t tid);
 /*%<
  * Force the thread ID to 'tid'. This is STRICTLY for use in unit
  * tests and should not be used in any production code.
index eb4efed40198a5b29238d28f270ae59ab1f79a6a..77763ff5056f0e2a38eda40b4909e184bf26f58e 100644 (file)
@@ -133,57 +133,61 @@ typedef atomic_uint_fast32_t isc_refcount_t;
 #define ISC_REFCOUNT_STATIC_TRACE_DECL(name) \
        ISC__REFCOUNT_TRACE_DECL(name, static inline)
 
-#define ISC__REFCOUNT_TRACE_IMPL(name, destroy, stat)                         \
-       stat name##_t *name##__ref(name##_t *ptr, const char *func,           \
-                                  const char *file, unsigned int line) {     \
-               REQUIRE(ptr != NULL);                                         \
-               uint_fast32_t refs =                                          \
-                       isc_refcount_increment(&ptr->references) + 1;         \
-               fprintf(stderr,                                               \
-                       "%s:%s:%s:%u:t%u:%p->references = %" PRIuFAST32 "\n", \
-                       __func__, func, file, line, isc_tid(), ptr, refs);    \
-               return (ptr);                                                 \
-       }                                                                     \
-                                                                              \
-       stat void name##__unref(name##_t *ptr, const char *func,              \
-                               const char *file, unsigned int line) {        \
-               REQUIRE(ptr != NULL);                                         \
-               uint_fast32_t refs =                                          \
-                       isc_refcount_decrement(&ptr->references) - 1;         \
-               if (refs == 0) {                                              \
-                       isc_refcount_destroy(&ptr->references);               \
-                       destroy(ptr);                                         \
-               }                                                             \
-               fprintf(stderr,                                               \
-                       "%s:%s:%s:%u:t%u:%p->references = %" PRIuFAST32 "\n", \
-                       __func__, func, file, line, isc_tid(), ptr, refs);    \
-       }                                                                     \
-       stat void name##__attach(name##_t *ptr, name##_t **ptrp,              \
-                                const char *func, const char *file,          \
-                                unsigned int line) {                         \
-               REQUIRE(ptrp != NULL && *ptrp == NULL);                       \
-               uint_fast32_t refs =                                          \
-                       isc_refcount_increment(&ptr->references) + 1;         \
-               fprintf(stderr,                                               \
-                       "%s:%s:%s:%u:t%u:%p->references = %" PRIuFAST32 "\n", \
-                       __func__, func, file, line, isc_tid(), ptr, refs);    \
-               *ptrp = ptr;                                                  \
-       }                                                                     \
-                                                                              \
-       stat void name##__detach(name##_t **ptrp, const char *func,           \
-                                const char *file, unsigned int line) {       \
-               REQUIRE(ptrp != NULL && *ptrp != NULL);                       \
-               name##_t *ptr = *ptrp;                                        \
-               *ptrp = NULL;                                                 \
-               uint_fast32_t refs =                                          \
-                       isc_refcount_decrement(&ptr->references) - 1;         \
-               if (refs == 0) {                                              \
-                       isc_refcount_destroy(&ptr->references);               \
-                       destroy(ptr);                                         \
-               }                                                             \
-               fprintf(stderr,                                               \
-                       "%s:%s:%s:%u:t%u:%p->references = %" PRIuFAST32 "\n", \
-                       __func__, func, file, line, isc_tid(), ptr, refs);    \
+#define ISC__REFCOUNT_TRACE_IMPL(name, destroy, stat)                      \
+       stat name##_t *name##__ref(name##_t *ptr, const char *func,        \
+                                  const char *file, unsigned int line) {  \
+               REQUIRE(ptr != NULL);                                      \
+               uint_fast32_t refs =                                       \
+                       isc_refcount_increment(&ptr->references) + 1;      \
+               fprintf(stderr,                                            \
+                       "%s:%s:%s:%u:t%" PRItid                            \
+                       ":%p->references = %" PRIuFAST32 "\n",             \
+                       __func__, func, file, line, isc_tid(), ptr, refs); \
+               return (ptr);                                              \
+       }                                                                  \
+                                                                           \
+       stat void name##__unref(name##_t *ptr, const char *func,           \
+                               const char *file, unsigned int line) {     \
+               REQUIRE(ptr != NULL);                                      \
+               uint_fast32_t refs =                                       \
+                       isc_refcount_decrement(&ptr->references) - 1;      \
+               if (refs == 0) {                                           \
+                       isc_refcount_destroy(&ptr->references);            \
+                       destroy(ptr);                                      \
+               }                                                          \
+               fprintf(stderr,                                            \
+                       "%s:%s:%s:%u:t%" PRItid                            \
+                       ":%p->references = %" PRIuFAST32 "\n",             \
+                       __func__, func, file, line, isc_tid(), ptr, refs); \
+       }                                                                  \
+       stat void name##__attach(name##_t *ptr, name##_t **ptrp,           \
+                                const char *func, const char *file,       \
+                                unsigned int line) {                      \
+               REQUIRE(ptrp != NULL && *ptrp == NULL);                    \
+               uint_fast32_t refs =                                       \
+                       isc_refcount_increment(&ptr->references) + 1;      \
+               fprintf(stderr,                                            \
+                       "%s:%s:%s:%u:t%" PRItid                            \
+                       ":%p->references = %" PRIuFAST32 "\n",             \
+                       __func__, func, file, line, isc_tid(), ptr, refs); \
+               *ptrp = ptr;                                               \
+       }                                                                  \
+                                                                           \
+       stat void name##__detach(name##_t **ptrp, const char *func,        \
+                                const char *file, unsigned int line) {    \
+               REQUIRE(ptrp != NULL && *ptrp != NULL);                    \
+               name##_t *ptr = *ptrp;                                     \
+               *ptrp = NULL;                                              \
+               uint_fast32_t refs =                                       \
+                       isc_refcount_decrement(&ptr->references) - 1;      \
+               if (refs == 0) {                                           \
+                       isc_refcount_destroy(&ptr->references);            \
+                       destroy(ptr);                                      \
+               }                                                          \
+               fprintf(stderr,                                            \
+                       "%s:%s:%s:%u:t%" PRItid                            \
+                       ":%p->references = %" PRIuFAST32 "\n",             \
+                       __func__, func, file, line, isc_tid(), ptr, refs); \
        }
 
 #define ISC_REFCOUNT_TRACE_IMPL(name, destroy) \
index 318d09a6fd0117329cd6621c6e550de3d013c305..b506205979f35605b37f4f112cb73b07229c4262 100644 (file)
 
 #include <isc/thread.h>
 
-#define ISC_TID_UNKNOWN UINT32_MAX
+typedef int32_t isc_tid_t;
 
-uint32_t
+#define PRItid PRId32
+
+#define ISC_TID_UNKNOWN (isc_tid_t) - 1
+
+isc_tid_t
 isc_tid_count(void);
 /*%<
  * Returns the number of threads.
  */
 
-extern thread_local uint32_t isc__tid_local;
+extern thread_local isc_tid_t isc__tid_local;
 
-static inline uint32_t
+static inline isc_tid_t
 isc_tid(void) {
        return isc__tid_local;
 }
@@ -38,7 +42,7 @@ isc_tid(void) {
 /* Private */
 
 void
-isc__tid_init(uint32_t tid);
+isc__tid_init(isc_tid_t tid);
 
 void
-isc__tid_initcount(uint32_t count);
+isc__tid_initcount(isc_tid_t count);
index 541f697b1b3b9f0ae62a1d4c4333117f97ea1651..7acbc8b693fa3cafc34adbf3e0e9bedea7036cfa 100644 (file)
@@ -77,7 +77,7 @@ isc__uverr2result(int uverr, bool dolog, const char *file, unsigned int line,
 #define uv_idle_init(loop, idle)                                          \
        ({                                                                \
                int __r = uv_idle_init(loop, idle);                       \
-               fprintf(stderr, "%" PRIu32 ":%s_:uv_idle_init(%p, %p)\n", \
+               fprintf(stderr, "%" PRItid ":%s_:uv_idle_init(%p, %p)\n", \
                        isc_tid(), __func__, loop, idle);                 \
                __r;                                                      \
        })
@@ -85,7 +85,7 @@ isc__uverr2result(int uverr, bool dolog, const char *file, unsigned int line,
 #define uv_timer_init(loop, timer)                                         \
        ({                                                                 \
                int __r = uv_timer_init(loop, timer);                      \
-               fprintf(stderr, "%" PRIu32 ":%s_:uv_timer_init(%p, %p)\n", \
+               fprintf(stderr, "%" PRItid ":%s_:uv_timer_init(%p, %p)\n", \
                        isc_tid(), __func__, loop, timer);                 \
                __r;                                                       \
        })
@@ -93,7 +93,7 @@ isc__uverr2result(int uverr, bool dolog, const char *file, unsigned int line,
 #define uv_async_init(loop, async, async_cb)                                   \
        ({                                                                     \
                int __r = uv_async_init(loop, async, async_cb);                \
-               fprintf(stderr, "%" PRIu32 ":%s_:uv_timer_init(%p, %p, %p)\n", \
+               fprintf(stderr, "%" PRItid ":%s_:uv_timer_init(%p, %p, %p)\n", \
                        isc_tid(), __func__, loop, async, async_cb);           \
                __r;                                                           \
        })
@@ -101,7 +101,7 @@ isc__uverr2result(int uverr, bool dolog, const char *file, unsigned int line,
 #define uv_close(handle, close_cb)                                    \
        ({                                                            \
                uv_close(handle, close_cb);                           \
-               fprintf(stderr, "%" PRIu32 ":%s_:uv_close(%p, %p)\n", \
+               fprintf(stderr, "%" PRItid ":%s_:uv_close(%p, %p)\n", \
                        isc_tid(), __func__, handle, close_cb);       \
        })
 
index 8f5da3c8599b524215b3803a0ed38069434b6221..1afbb2ef5651b2c0fd3431554a28b8d5b9a0c82f 100644 (file)
@@ -187,7 +187,7 @@ shutdown_cb(uv_async_t *handle) {
 }
 
 static void
-loop_init(isc_loop_t *loop, isc_loopmgr_t *loopmgr, uint32_t tid,
+loop_init(isc_loop_t *loop, isc_loopmgr_t *loopmgr, isc_tid_t tid,
          const char *kind) {
        *loop = (isc_loop_t){
                .tid = tid,
@@ -306,7 +306,7 @@ loop_thread(void *arg) {
 
        /* Start the helper thread */
        isc_thread_create(helper_thread, helper, &helper->thread);
-       snprintf(name, sizeof(name), "isc-helper-%04" PRIu32, loop->tid);
+       snprintf(name, sizeof(name), "isc-helper-%04" PRItid, loop->tid);
        isc_thread_setname(helper->thread, name);
 
        int r = uv_prepare_start(&loop->quiescent, quiescent_cb);
@@ -535,7 +535,7 @@ isc_loopmgr_pause(isc_loopmgr_t *loopmgr) {
                isc_loop_t *loop = &loopmgr->loops[i];
 
                /* Skip current loop */
-               if (i == isc_tid()) {
+               if (i == (size_t)isc_tid()) {
                        continue;
                }
 
@@ -645,9 +645,9 @@ isc_loop_main(isc_loopmgr_t *loopmgr) {
 }
 
 isc_loop_t *
-isc_loop_get(isc_loopmgr_t *loopmgr, uint32_t tid) {
+isc_loop_get(isc_loopmgr_t *loopmgr, isc_tid_t tid) {
        REQUIRE(VALID_LOOPMGR(loopmgr));
-       REQUIRE(tid < loopmgr->nloops);
+       REQUIRE((uint32_t)tid < loopmgr->nloops);
 
        return LOOP(loopmgr, tid);
 }
index 6bfdcdf1879d952cb89ab7f10f3d933505e27a49..f1f201ee354b8a61fd41293c1e4da906e196129a 100644 (file)
@@ -46,7 +46,7 @@ struct isc_loop {
        isc_loopmgr_t *loopmgr;
 
        uv_loop_t loop;
-       uint32_t tid;
+       isc_tid_t tid;
 
        isc_mem_t *mctx;
 
index 3a6ba669212897476f00ee836a6b3b655889ddde..6d06cb4fe33f4cb06c7ad2f7dbdb3ef1188585f4 100644 (file)
@@ -304,7 +304,7 @@ static void
 http_cleanup_listener_endpoints(isc_nmsocket_t *listener);
 
 static isc_nm_http_endpoints_t *
-http_get_listener_endpoints(isc_nmsocket_t *listener, const int tid);
+http_get_listener_endpoints(isc_nmsocket_t *listener, const isc_tid_t tid);
 
 static void
 http_initsocket(isc_nmsocket_t *sock);
@@ -3385,7 +3385,7 @@ typedef struct http_endpoints_data {
 static void
 http_set_endpoints_cb(void *arg) {
        http_endpoints_data_t *data = arg;
-       const int tid = isc_tid();
+       const isc_tid_t tid = isc_tid();
        isc_nmsocket_t *listener = data->listener;
        isc_nm_http_endpoints_t *endpoints = data->endpoints;
        isc__networker_t *worker = &listener->worker->netmgr->workers[tid];
@@ -3470,7 +3470,7 @@ http_cleanup_listener_endpoints(isc_nmsocket_t *listener) {
 }
 
 static isc_nm_http_endpoints_t *
-http_get_listener_endpoints(isc_nmsocket_t *listener, const int tid) {
+http_get_listener_endpoints(isc_nmsocket_t *listener, const isc_tid_t tid) {
        isc_nm_http_endpoints_t *eps;
        REQUIRE(VALID_NMSOCK(listener));
        REQUIRE(tid >= 0);
index 5534e7bdb4d48990b1ec43c17e22ca945ba77a39..79c60fdd60d1c3a3ec0b0c1ed0b5040d9c88b7f9 100644 (file)
@@ -151,8 +151,8 @@ STATIC_ASSERT(ISC_NETMGR_TCP_RECVBUF_SIZE <= ISC_NETMGR_RECVBUF_SIZE,
 #define gettid() (uint64_t)(pthread_self())
 #endif
 
-#define NETMGR_TRACE_LOG(format, ...)                                \
-       fprintf(stderr, "%" PRIu64 ":%d:%s:%u:%s:" format, gettid(), \
+#define NETMGR_TRACE_LOG(format, ...)                                         \
+       fprintf(stderr, "%" PRIu64 ":%" PRItid ":%s:%u:%s:" format, gettid(), \
                isc_tid(), file, line, func, __VA_ARGS__)
 
 #define FLARG                                                                 \
@@ -496,7 +496,7 @@ typedef void (*isc_nm_closehandlecb_t)(void *arg);
 struct isc_nmsocket {
        /*% Unlocked, RO */
        int magic;
-       uint32_t tid;
+       isc_tid_t tid;
        isc_refcount_t references;
        isc_nmsocket_type type;
        isc__networker_t *worker;
@@ -1008,7 +1008,7 @@ isc__nmhandle_tls_keepalive(isc_nmhandle_t *handle, bool value);
 
 void
 isc__nm_async_tls_set_tlsctx(isc_nmsocket_t *listener, isc_tlsctx_t *tlsctx,
-                            const int tid);
+                            const isc_tid_t tid);
 
 void
 isc__nmhandle_tls_setwritetimeout(isc_nmhandle_t *handle,
index a1ec3ab4e0fb273d8a41349b873f0ba6892b2f8e..4603f3c8eb18f6270683380893575eafa2230253 100644 (file)
@@ -118,9 +118,10 @@ networker_teardown(void *arg) {
 
        worker->shuttingdown = true;
 
-       isc__netmgr_log(worker->netmgr, ISC_LOG_DEBUG(1),
-                       "Shutting down network manager worker on loop %p(%d)",
-                       loop, isc_tid());
+       isc__netmgr_log(
+               worker->netmgr, ISC_LOG_DEBUG(1),
+               "Shutting down network manager worker on loop %p(%" PRItid ")",
+               loop, isc_tid());
 
        uv_walk(&loop->loop, shutdown_walk_cb, NULL);
 
@@ -2558,7 +2559,7 @@ typedef struct settlsctx_data {
 static void
 settlsctx_cb(void *arg) {
        settlsctx_data_t *data = arg;
-       const uint32_t tid = isc_tid();
+       const isc_tid_t tid = isc_tid();
        isc_nmsocket_t *listener = data->listener;
        isc_tlsctx_t *tlsctx = data->tlsctx;
        isc__networker_t *worker = &listener->worker->netmgr->workers[tid];
@@ -2666,7 +2667,8 @@ isc__networker_destroy(isc__networker_t *worker) {
        worker->netmgr = NULL;
 
        isc__netmgr_log(netmgr, ISC_LOG_DEBUG(1),
-                       "Destroying network manager worker on loop %p(%d)",
+                       "Destroying network manager worker on loop %p(%" PRItid
+                       ")",
                        worker->loop, isc_tid());
 
        isc_loop_detach(&worker->loop);
index a4d038c6414a3dd27cba021fd8f534aba1f120b5..27f40fea9ea0731f6befe7f2b40bbdc9938fb1f8 100644 (file)
@@ -491,7 +491,7 @@ static void
 stop_proxyudp_child_job(void *arg) {
        isc_nmsocket_t *listener = NULL;
        isc_nmsocket_t *sock = arg;
-       uint32_t tid = 0;
+       isc_tid_t tid = 0;
 
        if (sock == NULL) {
                return;
index a0bc22ed53200b13dcf35ff6255b9a208b0731b7..82b6beb9a856e58ff79b57a9f0ae80445d5001d9 100644 (file)
@@ -700,7 +700,7 @@ streamdns_accept_cb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) {
        isc_nmsocket_t *listensock = (isc_nmsocket_t *)cbarg;
        isc_nmsocket_t *nsock;
        isc_sockaddr_t iface;
-       int tid = isc_tid();
+       isc_tid_t tid = isc_tid();
 
        REQUIRE(VALID_NMHANDLE(handle));
        REQUIRE(VALID_NMSOCK(handle->sock));
index 76dd0c8a7887e3b0d0ddfd6665203d259f5f6018..327b345ec3238f8d32e2f7ae2b1ccbae7ed9e1d4 100644 (file)
@@ -442,7 +442,7 @@ done_result:
 
 static void
 start_tcp_child(isc_nm_t *mgr, isc_sockaddr_t *iface, isc_nmsocket_t *sock,
-               uv_os_sock_t fd, int tid) {
+               uv_os_sock_t fd, isc_tid_t tid) {
        isc_nmsocket_t *csock = &sock->children[tid];
        isc__networker_t *worker = &mgr->workers[tid];
 
index b928842e298494445c27b2e42837be3d5ed1eef3..df94724431388a8e4d0fbe6159809c0b48292fae 100644 (file)
@@ -126,7 +126,7 @@ static void
 tls_cleanup_listener_tlsctx(isc_nmsocket_t *listener);
 
 static isc_tlsctx_t *
-tls_get_listener_tlsctx(isc_nmsocket_t *listener, const int tid);
+tls_get_listener_tlsctx(isc_nmsocket_t *listener, const isc_tid_t tid);
 
 static void
 tls_keep_client_tls_session(isc_nmsocket_t *sock);
@@ -1548,7 +1548,7 @@ tls_cleanup_listener_tlsctx(isc_nmsocket_t *listener) {
 }
 
 static isc_tlsctx_t *
-tls_get_listener_tlsctx(isc_nmsocket_t *listener, const int tid) {
+tls_get_listener_tlsctx(isc_nmsocket_t *listener, const isc_tid_t tid) {
        REQUIRE(VALID_NMSOCK(listener));
        REQUIRE(tid >= 0);
 
@@ -1561,7 +1561,7 @@ tls_get_listener_tlsctx(isc_nmsocket_t *listener, const int tid) {
 
 void
 isc__nm_async_tls_set_tlsctx(isc_nmsocket_t *listener, isc_tlsctx_t *tlsctx,
-                            const int tid) {
+                            const isc_tid_t tid) {
        REQUIRE(tid >= 0);
 
        isc_tlsctx_free(&listener->tlsstream.listener_tls_ctx[tid]);
index e8106c1b13ab04f604509077b978d2909dfbc3ad..9ea9af595865f4fe3985bc31772942222fe1a4c1 100644 (file)
@@ -180,7 +180,7 @@ done:
 
 static void
 start_udp_child(isc_nm_t *mgr, isc_sockaddr_t *iface, isc_nmsocket_t *sock,
-               uv_os_sock_t fd, int tid) {
+               uv_os_sock_t fd, isc_tid_t tid) {
        isc__networker_t *worker = &mgr->workers[tid];
        isc_nmsocket_t *csock = &sock->children[tid];
 
index 2f4788189e7082a113ff64302cbca78ff4967ae6..e8416a733c5fe48c574a804da64719302713f67b 100644 (file)
 /**
  * Private
  */
-thread_local uint32_t isc__tid_local = ISC_TID_UNKNOWN;
+thread_local isc_tid_t isc__tid_local = ISC_TID_UNKNOWN;
 
 /*
  * Zero is a better nonsense value in this case than ISC_TID_UNKNOWN;
  * avoids things like trying to allocate 32GB of per-thread counters.
  */
-static uint32_t tid_count = 0;
+static isc_tid_t tid_count = 0;
 
 /**
  * Protected
  */
 
 void
-isc__tid_init(uint32_t tid) {
+isc__tid_init(isc_tid_t tid) {
        REQUIRE(isc__tid_local == ISC_TID_UNKNOWN || isc__tid_local == tid);
        isc__tid_local = tid;
 }
 
 void
-isc__tid_initcount(uint32_t count) {
+isc__tid_initcount(isc_tid_t count) {
        REQUIRE(tid_count == 0 || tid_count == count);
        tid_count = count;
 }
@@ -50,7 +50,7 @@ isc__tid_initcount(uint32_t count) {
  * Public
  */
 
-uint32_t
+isc_tid_t
 isc_tid_count(void) {
        return tid_count;
 }
index 6696bd15f232eb344d6d10fd55e5fe8b83e208b1..bafd51f306b37b26af8a7bb88312781d9ba4ce30 100644 (file)
@@ -2644,7 +2644,8 @@ ISC_REFCOUNT_IMPL(ns_clientmgr, clientmgr_destroy);
 
 isc_result_t
 ns_clientmgr_create(ns_server_t *sctx, isc_loopmgr_t *loopmgr,
-                   dns_aclenv_t *aclenv, int tid, ns_clientmgr_t **managerp) {
+                   dns_aclenv_t *aclenv, isc_tid_t tid,
+                   ns_clientmgr_t **managerp) {
        ns_clientmgr_t *manager = NULL;
        isc_mem_t *mctx = NULL;
 
index 773647a2eab6f457d62abf97279499af7c5e6b3b..8d17118c4d8ffd801cd9e3bf3070615a4ba38fce 100644 (file)
@@ -149,7 +149,7 @@ struct ns_clientmgr {
 
        ns_server_t   *sctx;
        isc_refcount_t references;
-       uint32_t       tid;
+       isc_tid_t      tid;
        isc_loop_t    *loop;
 
        dns_aclenv_t *aclenv;
@@ -331,7 +331,8 @@ ns_client_settimeout(ns_client_t *client, unsigned int seconds);
 
 isc_result_t
 ns_clientmgr_create(ns_server_t *sctx, isc_loopmgr_t *loopmgr,
-                   dns_aclenv_t *aclenv, int tid, ns_clientmgr_t **managerp);
+                   dns_aclenv_t *aclenv, isc_tid_t tid,
+                   ns_clientmgr_t **managerp);
 /*%<
  * Create a client manager.
  */
index 118f3113e4d952498d179882e54bc89bf0747d81..03a42c0c0dabd787bf2a1518e835e2ed4efdc88c 100644 (file)
@@ -1358,11 +1358,10 @@ ns_interfacemgr_getserver(ns_interfacemgr_t *mgr) {
 
 ns_clientmgr_t *
 ns_interfacemgr_getclientmgr(ns_interfacemgr_t *mgr) {
-       int tid = isc_tid();
+       isc_tid_t tid = isc_tid();
 
        REQUIRE(NS_INTERFACEMGR_VALID(mgr));
-       REQUIRE(tid >= 0);
-       REQUIRE((uint32_t)tid < mgr->ncpus);
+       REQUIRE(tid >= 0 && (uint32_t)tid < mgr->ncpus);
 
        return mgr->clientmgrs[tid];
 }
index ac1c10b3d684880df90601a08c106a469d02c033..783bf37f5150586b6506d1c7974838ce10c9a3e5 100644 (file)
 #define ZIPF   0
 
 #if VERBOSE
-#define TRACE(fmt, ...)                                                   \
-       isc_log_write(DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_QP,         \
-                     ISC_LOG_DEBUG(7), "%s:%d:%s():t%d: " fmt, __FILE__, \
-                     __LINE__, __func__, isc_tid(), ##__VA_ARGS__)
+#define TRACE(fmt, ...)                                                  \
+       isc_log_write(DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_QP,        \
+                     ISC_LOG_DEBUG(7), "%s:%d:%s():t%" PRItid ": " fmt, \
+                     __FILE__, __LINE__, __func__, isc_tid(), ##__VA_ARGS__)
 #else
 #define TRACE(...)
 #endif
index 685d6a11c900331be15e5e1699983d4dc403c9e2..343f4416bc4c38190e7d22726c052c8ff7b16bcf 100644 (file)
@@ -303,7 +303,7 @@ ISC_LOOP_TEST_IMPL(dispatchset_get) {
        dns_dispatchmgr_t *dispatchmgr = NULL;
        dns_dispatchset_t *dset = NULL;
        dns_dispatch_t *d1, *d2, *d3, *d4, *d5;
-       uint32_t tid_saved;
+       isc_tid_t tid_saved;
 
        UNUSED(arg);
 
index ea8d543919418df79a35b9b692279d1a5d6fdd02..f9b32f438763ea553db35089377455354d2ef6ba 100644 (file)
@@ -41,7 +41,7 @@ static atomic_uint scheduled = 0;
 
 static void
 async_cb(void *arg) {
-       uint32_t tid = isc_tid();
+       isc_tid_t tid = isc_tid();
 
        UNUSED(arg);
 
@@ -57,7 +57,7 @@ async_cb(void *arg) {
 
 static void
 async_setup_cb(void *arg) {
-       uint32_t tid = isc_loopmgr_nloops(loopmgr) - 1;
+       isc_tid_t tid = isc_loopmgr_nloops(loopmgr) - 1;
        isc_loop_t *loop = isc_loop_get(loopmgr, tid);
 
        UNUSED(arg);
index d5cf4b34c9afd523d07a4bc9eb487da7b21d56bd..b1c784adf956a6baeb683b0bc6c7a85606285515 100644 (file)
@@ -211,13 +211,14 @@ extern isc_nm_recv_cb_t connect_readcb;
        fprintf(stderr, "%s:%s:%d:%s = %" PRId64 "\n", __func__, __FILE__, \
                __LINE__, #v, atomic_load(&v))
 #define P(v) fprintf(stderr, #v " = %" PRId64 "\n", v)
-#define F()                                                                 \
-       fprintf(stderr, "%u:%s(%p, %s, %p)\n", isc_tid(), __func__, handle, \
-               isc_result_totext(eresult), cbarg)
+#define F()                                                                  \
+       fprintf(stderr, "%" PRItid ":%s(%p, %s, %p)\n", isc_tid(), __func__, \
+               handle, isc_result_totext(eresult), cbarg)
 
 #define isc_loopmgr_shutdown(loopmgr)                                      \
        {                                                                  \
-               fprintf(stderr, "%u:%s:%s:%d:isc_loopmgr_shutdown(%p)\n",  \
+               fprintf(stderr,                                            \
+                       "%" PRItid ":%s:%s:%d:isc_loopmgr_shutdown(%p)\n", \
                        isc_tid(), __func__, __FILE__, __LINE__, loopmgr); \
                isc_loopmgr_shutdown(loopmgr);                             \
        }
index 046cccb1b9050468d44aace374f92c23992f52b7..39f3ba1d176b43978e274a24e11cefd01b780500 100644 (file)
@@ -45,7 +45,7 @@ work_cb(void *arg) {
 
        atomic_fetch_add(&scheduled, 1);
 
-       assert_int_equal(isc_tid(), UINT32_MAX);
+       assert_int_equal(isc_tid(), ISC_TID_UNKNOWN);
 }
 
 static void
@@ -59,7 +59,7 @@ after_work_cb(void *arg) {
 static void
 work_enqueue_cb(void *arg) {
        UNUSED(arg);
-       uint32_t tid = isc_loopmgr_nloops(loopmgr) - 1;
+       isc_tid_t tid = isc_loopmgr_nloops(loopmgr) - 1;
 
        isc_loop_t *loop = isc_loop_get(loopmgr, tid);