Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iwyu #2073

Merged
merged 5 commits into from
Jan 5, 2025
Merged

Iwyu #2073

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/core/dialer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
// Copyright 2018 Devolutions <[email protected]>
//
Expand All @@ -12,6 +12,9 @@
#ifndef CORE_DIALER_H
#define CORE_DIALER_H

#include "defs.h"
#include "stats.h"

extern int nni_dialer_find(nni_dialer **, uint32_t);
extern int nni_dialer_hold(nni_dialer *);
extern void nni_dialer_rele(nni_dialer *);
Expand Down
4 changes: 3 additions & 1 deletion src/core/file.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2018 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
Expand All @@ -11,6 +11,8 @@
#ifndef CORE_FILE_H
#define CORE_FILE_H

#include "defs.h"

// File/Store Support
//
// Some transports require a persistent storage for things like configs,
Expand Down
5 changes: 4 additions & 1 deletion src/core/listener.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
// Copyright 2018 Devolutions <[email protected]>
//
Expand All @@ -12,6 +12,9 @@
#ifndef CORE_LISTENER_H
#define CORE_LISTENER_H

#include "core/defs.h"
#include "core/stats.h"

extern int nni_listener_find(nni_listener **, uint32_t);
extern int nni_listener_hold(nni_listener *);
extern void nni_listener_rele(nni_listener *);
Expand Down
4 changes: 2 additions & 2 deletions src/core/lmq.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2021 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
Expand All @@ -10,7 +10,7 @@
#ifndef CORE_LMQ_H
#define CORE_LMQ_H

#include "nng_impl.h"
#include "core/defs.h"

// nni_lmq is a very lightweight message queue. Defining it this way allows
// us to share some common code. Locking must be supplied by the caller.
Expand Down
4 changes: 3 additions & 1 deletion src/core/message.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2021 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2017 Capitar IT Group BV <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
Expand All @@ -11,6 +11,8 @@
#ifndef CORE_MESSAGE_H
#define CORE_MESSAGE_H

#include "core/defs.h"

// Internally used message API. Again, this is not part of our public API.
// "trim" operations work from the front, and "chop" work from the end.

Expand Down
3 changes: 1 addition & 2 deletions src/core/msgqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#ifndef CORE_MSGQUEUE_H
#define CORE_MSGQUEUE_H

#include "nng_impl.h"
#include "defs.h"
#include "pollable.h"

// Message queues. Message queues work in some ways like Go channels;
Expand All @@ -33,7 +33,6 @@ extern int nni_msgq_init(nni_msgq **, unsigned);
// messages that may be in the queue.
extern void nni_msgq_fini(nni_msgq *);


extern void nni_msgq_aio_put(nni_msgq *, nni_aio *);
extern void nni_msgq_aio_get(nni_msgq *, nni_aio *);

Expand Down
2 changes: 2 additions & 0 deletions src/core/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#ifndef CORE_OPTIONS_H
#define CORE_OPTIONS_H

#include "defs.h"

// Integer limits.
#define NNI_MAXINT (2147483647)
// the -1 trick works around a compiler warning on some compilers (MSVC)
Expand Down
9 changes: 5 additions & 4 deletions src/core/pipe.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
Expand All @@ -15,9 +15,10 @@
// OUTSIDE of the core is STRICTLY VERBOTEN. NO DIRECT ACCESS BY PROTOCOLS OR
// TRANSPORTS.

#include "core/defs.h"
#include "core/thread.h"
#include "nng/nng.h"
#include "defs.h"
#include "stats.h"
#include "thread.h"

#include "sp/transport.h"

// AIO
Expand Down
21 changes: 6 additions & 15 deletions src/core/platform.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
// Copyright 2018 Devolutions <[email protected]>
//
Expand All @@ -21,6 +21,8 @@
#include <stddef.h>
#include <stdint.h>

#include "defs.h"

// These are the APIs that a platform must implement to support nng.

// A word about fork-safety: This library is *NOT* fork safe, in that
Expand Down Expand Up @@ -83,11 +85,9 @@ extern void *nni_zalloc(size_t);
// Most implementations can just call free() here.
extern void nni_free(void *, size_t);

typedef struct nni_plat_mtx nni_plat_mtx;
typedef struct nni_plat_rwlock nni_plat_rwlock;
typedef struct nni_plat_cv nni_plat_cv;
typedef struct nni_plat_thr nni_plat_thr;
typedef struct nni_rwlock nni_rwlock;
typedef struct nni_plat_mtx nni_plat_mtx;
typedef struct nni_plat_cv nni_plat_cv;
typedef struct nni_plat_thr nni_plat_thr;

//
// Threading & Synchronization Support
Expand All @@ -109,15 +109,6 @@ extern void nni_plat_mtx_lock(nni_plat_mtx *);
// thread that owned the mutex.
extern void nni_plat_mtx_unlock(nni_plat_mtx *);

// read/write locks - these work like mutexes except that multiple readers
// can acquire the lock. These are not safe for recursive use, and it is
// unspecified whether any measures are provided to prevent starvation.
extern void nni_rwlock_init(nni_rwlock *);
extern void nni_rwlock_fini(nni_rwlock *);
extern void nni_rwlock_rdlock(nni_rwlock *);
extern void nni_rwlock_wrlock(nni_rwlock *);
extern void nni_rwlock_unlock(nni_rwlock *);

// nni_plat_cv_init initializes a condition variable. We require a mutex be
// supplied with it, and that mutex must always be held when performing any
// operations on the condition variable (other than fini.) As with mutexes, an
Expand Down
7 changes: 4 additions & 3 deletions src/core/pollable.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2021 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
Expand All @@ -10,8 +10,9 @@
#ifndef CORE_POLLABLE_H
#define CORE_POLLABLE_H

#include "core/defs.h"
#include "core/list.h"
#include "defs.h"
#include "list.h"
#include "platform.h"

typedef struct nni_pollable nni_pollable;

Expand Down
16 changes: 11 additions & 5 deletions src/core/reap.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2021 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2017 Capitar IT Group BV <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
Expand All @@ -14,14 +14,13 @@

#include <stdbool.h>

// New stuff.
static nni_reap_list *reap_list = NULL;
static nni_thr reap_thr;
static bool reap_exit = false;
static nni_mtx reap_mtx = NNI_MTX_INITIALIZER;
static bool reap_empty;
static nni_cv reap_work_cv = NNI_CV_INITIALIZER(&reap_mtx);
static nni_cv reap_empty_cv = NNI_CV_INITIALIZER(&reap_mtx);
static nni_mtx reap_mtx;
static nni_cv reap_work_cv;
static nni_cv reap_empty_cv;

static void
reap_worker(void *unused)
Expand Down Expand Up @@ -109,6 +108,9 @@ nni_reap_sys_init(void)
int rv;

reap_exit = false;
nni_mtx_init(&reap_mtx);
nni_cv_init(&reap_work_cv, &reap_mtx);
nni_cv_init(&reap_empty_cv, &reap_mtx);
// If this fails, we don't fail init, instead we will try to
// start up at reap time.
if ((rv = nni_thr_init(&reap_thr, reap_worker, NULL)) != 0) {
Expand All @@ -127,6 +129,10 @@ nni_reap_sys_fini(void)
nni_mtx_unlock(&reap_mtx);
nni_thr_fini(&reap_thr);

nni_cv_fini(&reap_work_cv);
nni_cv_fini(&reap_empty_cv);
nni_mtx_fini(&reap_mtx);

// NB: The subsystem linkages remain in place. We don't need
// to reinitialize them across future initializations.
}
8 changes: 3 additions & 5 deletions src/core/refcnt.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
Expand All @@ -9,10 +9,8 @@
#ifndef CORE_REFCNT_H
#define CORE_REFCNT_H

#include <nng/nng.h>

#include <core/nng_impl.h>
#include <core/platform.h>
#include "defs.h"
#include "platform.h"

typedef struct {
nni_atomic_int rc_cnt;
Expand Down
6 changes: 5 additions & 1 deletion src/core/socket.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
Expand All @@ -11,6 +11,10 @@
#ifndef CORE_SOCKET_H
#define CORE_SOCKET_H

#include "defs.h"
#include "msgqueue.h"
#include "stats.h"

extern int nni_sock_find(nni_sock **, uint32_t);
extern void nni_sock_hold(nni_sock *);
extern void nni_sock_rele(nni_sock *);
Expand Down
16 changes: 15 additions & 1 deletion src/core/sockimpl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
Expand All @@ -11,6 +11,20 @@
#ifndef CORE_SOCKIMPL_H
#define CORE_SOCKIMPL_H

#include "defs.h"

#include "aio.h"
#include "dialer.h"
#include "list.h"
#include "listener.h"
#include "protocol.h"
#include "reap.h"
#include "refcnt.h"
#include "stats.h"
#include "url.h"

#include "sp/transport.h"

// This file contains stuff shared within the core between sockets, endpoints,
// and pipes. This must not be exposed to other subsystems -- these internals
// are subject to change at any time.
Expand Down
4 changes: 2 additions & 2 deletions src/core/stream.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2024 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
Expand All @@ -13,7 +13,7 @@
// This provides an abstraction for byte streams, allowing polymorphic
// use of them in rather flexible contexts.

#include "core/nng_impl.h"
#include "defs.h"

// Private property operations (these include the types.)
extern int nni_stream_get(
Expand Down
8 changes: 5 additions & 3 deletions src/core/strs.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2020 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2017 Capitar IT Group BV <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
Expand All @@ -13,11 +13,13 @@

// Safe string functions, in case the platform misses these.

extern char * nni_strdup(const char *);
#include "defs.h"

extern char *nni_strdup(const char *);
extern void nni_strfree(char *);
extern size_t nni_strlcpy(char *, const char *, size_t);
extern size_t nni_strnlen(const char *, size_t);
extern char * nni_strcasestr(const char *, const char *);
extern char *nni_strcasestr(const char *, const char *);
extern int nni_strncasecmp(const char *, const char *, size_t);
extern int nni_strcasecmp(const char *, const char *);
extern int nni_asprintf(char **, const char *, ...);
Expand Down
27 changes: 6 additions & 21 deletions src/platform/posix/posix_impl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2021 Staysail Systems, Inc. <[email protected]>
// Copyright 2025 Staysail Systems, Inc. <[email protected]>
// Copyright 2018 Capitar IT Group BV <[email protected]>
//
// This software is supplied under the terms of the MIT License, a
Expand Down Expand Up @@ -32,7 +32,9 @@
#define NNG_PLATFORM_POSIX_SOCKADDR
#define NNG_PLATFORM_POSIX_UDP

#include "platform/posix/posix_config.h"
#include "core/defs.h"

#include "posix_config.h"
#endif

#ifdef NNG_PLATFORM_POSIX_SOCKADDR
Expand Down Expand Up @@ -63,30 +65,13 @@ struct nni_plat_mtx {
PTHREAD_MUTEX_INITIALIZER \
}

struct nni_rwlock {
pthread_rwlock_t rwl;
};

#define NNI_RWLOCK_INITIALIZER \
{ \
PTHREAD_RWLOCK_INITIALIZER \
}

// No static form of CV initialization because of the need to use
// attributes to set the clock type.
struct nni_plat_cv {
pthread_cond_t cv;
nni_plat_mtx *mtx;
pthread_cond_t cv;
pthread_mutex_t *mtx;
};

// NOTE: condition variables initialized with this should *NOT*
// be used with nni_cv_until -- the clock attributes are not passed
// and the wake-up times will not be correct.
#define NNI_CV_INITIALIZER(mxp) \
{ \
.mtx = mxp, .cv = PTHREAD_COND_INITIALIZER \
}

struct nni_plat_thr {
pthread_t tid;
void (*func)(void *);
Expand Down
Loading
Loading