]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/messaging: s/getpid/tevent_cached_getpid
authorStefan Metzmacher <metze@samba.org>
Mon, 25 Jul 2022 12:29:35 +0000 (14:29 +0200)
committerJeremy Allison <jra@samba.org>
Mon, 25 Jul 2022 17:34:33 +0000 (17:34 +0000)
Our messaging code is very performance critical and
we should note waste time in getpid() syscalls...

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/messaging/messages_dgm.c
lib/messaging/messages_dgm_ref.c

index ef065def4d9d90c660f863a80b26493cde81550a..f71b49cc01fd3718d98e5ba513f5b384b37f1175 100644 (file)
@@ -283,7 +283,7 @@ static int messaging_dgm_out_destructor(struct messaging_dgm_out *out)
        DLIST_REMOVE(out->ctx->outsocks, out);
 
        if ((tevent_queue_length(out->queue) != 0) &&
-           (getpid() == out->ctx->pid)) {
+           (tevent_cached_getpid() == out->ctx->pid)) {
                /*
                 * We have pending jobs. We can't close the socket,
                 * this has been handed over to messaging_dgm_out_queue_state.
@@ -784,7 +784,7 @@ static int messaging_dgm_out_send_fragmented(struct tevent_context *ev,
 
        hdr = (struct messaging_dgm_fragment_hdr) {
                .msglen = msglen,
-               .pid = getpid(),
+               .pid = tevent_cached_getpid(),
                .sock = out->sock
        };
 
@@ -1011,7 +1011,7 @@ int messaging_dgm_init(struct tevent_context *ev,
                goto fail_nomem;
        }
        ctx->ev = ev;
-       ctx->pid = getpid();
+       ctx->pid = tevent_cached_getpid();
        ctx->recv_cb = recv_cb;
        ctx->recv_cb_private_data = recv_cb_private_data;
 
@@ -1116,7 +1116,7 @@ static int messaging_dgm_context_destructor(struct messaging_dgm_context *c)
 
        close(c->sock);
 
-       if (getpid() == c->pid) {
+       if (tevent_cached_getpid() == c->pid) {
                struct sun_path_buf name;
                int ret;
 
@@ -1154,7 +1154,7 @@ static int messaging_dgm_context_destructor(struct messaging_dgm_context *c)
 static void messaging_dgm_validate(struct messaging_dgm_context *ctx)
 {
 #ifdef DEVELOPER
-       pid_t pid = getpid();
+       pid_t pid = tevent_cached_getpid();
        struct sockaddr_storage addr;
        socklen_t addrlen = sizeof(addr);
        struct sockaddr_un *un_addr;
@@ -1519,7 +1519,7 @@ int messaging_dgm_get_unique(pid_t pid, uint64_t *unique)
 
        messaging_dgm_validate(ctx);
 
-       if (pid == getpid()) {
+       if (pid == tevent_cached_getpid()) {
                /*
                 * Protect against losing our own lock
                 */
@@ -1632,7 +1632,7 @@ static int messaging_dgm_wipe_fn(pid_t pid, void *private_data)
 
 int messaging_dgm_wipe(void)
 {
-       pid_t pid = getpid();
+       pid_t pid = tevent_cached_getpid();
        messaging_dgm_forall(messaging_dgm_wipe_fn, &pid);
        return 0;
 }
index 470dfbeabc74f8650b4eb38b89835aad58216da5..4e38c2dea243ae5040203150844567c6ad917fd2 100644 (file)
@@ -64,7 +64,7 @@ void *messaging_dgm_ref(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
 
        tmp_refs = refs;
 
-       if ((refs != NULL) && (dgm_pid != getpid())) {
+       if ((refs != NULL) && (dgm_pid != tevent_cached_getpid())) {
                /*
                 * Have to reinit after fork
                 */
@@ -85,10 +85,10 @@ void *messaging_dgm_ref(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
                        *err = ret;
                        return NULL;
                }
-               dgm_pid = getpid();
+               dgm_pid = tevent_cached_getpid();
        } else {
                int ret;
-               ret = messaging_dgm_get_unique(getpid(), unique);
+               ret = messaging_dgm_get_unique(tevent_cached_getpid(), unique);
                DBG_DEBUG("messaging_dgm_get_unique returned %s\n",
                          strerror(ret));
                if (ret != 0) {