diff options
| author | Garrett D'Amore <garrett@damore.org> | 2016-12-22 01:57:10 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2016-12-22 01:57:10 -0800 |
| commit | 101c1b6a946d9f2f48c6dd89940ae669141e0511 (patch) | |
| tree | 4da688859d87526d03d724ab1a729c6846650eae /src/platform | |
| parent | b92672e20420683e73bfc017956ac6ef2b6b793b (diff) | |
| download | nng-101c1b6a946d9f2f48c6dd89940ae669141e0511.tar.gz nng-101c1b6a946d9f2f48c6dd89940ae669141e0511.tar.bz2 nng-101c1b6a946d9f2f48c6dd89940ae669141e0511.zip | |
Use C99 structure initializers FTW. Various other changes.
Diffstat (limited to 'src/platform')
| -rw-r--r-- | src/platform/posix/posix_alloc.c | 7 | ||||
| -rw-r--r-- | src/platform/posix/posix_clock.c | 7 | ||||
| -rw-r--r-- | src/platform/posix/posix_config.h | 2 | ||||
| -rw-r--r-- | src/platform/posix/posix_debug.c | 18 | ||||
| -rw-r--r-- | src/platform/posix/posix_impl.h | 42 | ||||
| -rw-r--r-- | src/platform/posix/posix_synch.c | 31 | ||||
| -rw-r--r-- | src/platform/posix/posix_thread.c | 35 |
7 files changed, 69 insertions, 73 deletions
diff --git a/src/platform/posix/posix_alloc.c b/src/platform/posix/posix_alloc.c index 16b2dce3..eb5c889e 100644 --- a/src/platform/posix/posix_alloc.c +++ b/src/platform/posix/posix_alloc.c @@ -7,13 +7,6 @@ * found online at https://opensource.org/licenses/MIT. */ -/* - * This is more of a direct #include of a .c rather than .h file. - * But having it be a .h makes compiler rules work out properly. Do - * not include this more than once into your program, or you will - * get multiple symbols defined. - */ - #include "core/nng_impl.h" #ifdef PLATFORM_POSIX_ALLOC diff --git a/src/platform/posix/posix_clock.c b/src/platform/posix/posix_clock.c index 5c29d5ff..83f0b151 100644 --- a/src/platform/posix/posix_clock.c +++ b/src/platform/posix/posix_clock.c @@ -8,13 +8,6 @@ */ /* - * This is more of a direct #include of a .c rather than .h file. - * But having it be a .h makes compiler rules work out properly. Do - * not include this more than once into your program, or you will - * get multiple symbols defined. - */ - -/* * POSIX clock stuff. */ #include "core/nng_impl.h" diff --git a/src/platform/posix/posix_config.h b/src/platform/posix/posix_config.h index a8da8ccd..dd2167ab 100644 --- a/src/platform/posix/posix_config.h +++ b/src/platform/posix/posix_config.h @@ -44,4 +44,4 @@ #else #define NNG_USE_CLOCKID CLOCK_REALTIME #endif -#endif /* CLOCK_REALTIME */ +#endif // CLOCK_REALTIME diff --git a/src/platform/posix/posix_debug.c b/src/platform/posix/posix_debug.c index 37c0af66..56b443e9 100644 --- a/src/platform/posix/posix_debug.c +++ b/src/platform/posix/posix_debug.c @@ -1,11 +1,11 @@ -/* - * Copyright 2016 Garrett D'Amore <garrett@damore.org> - * - * This software is supplied under the terms of the MIT License, a - * copy of which should be located in the distribution where this - * file was obtained (LICENSE.txt). A copy of the license may also be - * found online at https://opensource.org/licenses/MIT. - */ +// +// Copyright 2016 Garrett D'Amore <garrett@damore.org> +// +// This software is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// #include "core/nng_impl.h" @@ -28,4 +28,4 @@ nni_plat_println(const char *message) } -#endif /* PLATFORM_POSIX_DEBUG */ +#endif // PLATFORM_POSIX_DEBUG diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h index c18af983..0a3151f3 100644 --- a/src/platform/posix/posix_impl.h +++ b/src/platform/posix/posix_impl.h @@ -1,21 +1,14 @@ -/* - * Copyright 2016 Garrett D'Amore <garrett@damore.org> - * - * This software is supplied under the terms of the MIT License, a - * copy of which should be located in the distribution where this - * file was obtained (LICENSE.txt). A copy of the license may also be - * found online at https://opensource.org/licenses/MIT. - */ +// +// Copyright 2016 Garrett D'Amore <garrett@damore.org> +// +// This software is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// -/* - * This is more of a direct #include of a .c rather than .h file. - * But having it be a .h makes compiler rules work out properly. Do - * not include this more than once into your program, or you will - * get multiple symbols defined. - * - * The file itself pulls in POSIX implementations for platform specific - * functionality. - */ +#ifndef PLATFORM_POSIX_IMPL_H +#define PLATFORM_POSIX_IMPL_H #ifdef PLATFORM_POSIX #define PLATFORM_POSIX_ALLOC @@ -23,7 +16,20 @@ #define PLATFORM_POSIX_CLOCK #define PLATFORM_POSIX_SYNCH #define PLATFORM_POSIX_THREAD -#define PLATFORM_POSIX_VSNPRINTF #include "platform/posix/posix_config.h" #endif + +// Define types that this platform uses. +#ifdef PLATFORM_POSIX_SYNCH +struct nni_mutex { + pthread_mutex_t mx; +} + +struct nni_condvar { + pthread_cond_t cv; + pthread_mutex_t * mx; +} +#endif + +#endif // PLATFORM_POSIX_IMPL_H
\ No newline at end of file diff --git a/src/platform/posix/posix_synch.c b/src/platform/posix/posix_synch.c index 555da36b..13147573 100644 --- a/src/platform/posix/posix_synch.c +++ b/src/platform/posix/posix_synch.c @@ -26,14 +26,27 @@ #include <pthread.h> #include <time.h> -struct nni_mutex { - pthread_mutex_t mx; -}; +int +nni_mutex_init(nni_mutex *mp) +{ + // pthrad_mutex_attr_t attr; + if (pthread_mutex_init(&mp->mx, NULL) != NULL) { + return (NNG_ENOMEM); + } + return (0); +} + + +void +nni_mutex_fini(nni_mutex *mp) +{ + int rv; + + if ((rv = pthread_mutex_destroy(&mp-- > mx)) != 0) { + nni_panic("pthread_mutex_destroy failed: %s", strerror(rv)); + } +} -struct nni_cond { - pthread_cond_t cv; - pthread_mutex_t * mx; -}; int nni_mutex_create(nni_mutex_t *mp) @@ -109,8 +122,8 @@ nni_mutex_tryenter(nni_mutex_t m) } -int -cond_attr(pthread_condattr_t **attrpp) +static int +nni_cond_attr(pthread_condattr_t **attrpp) { #if defined(NNG_USE_GETTIMEOFDAY) || NNG_USE_CLOCKID == CLOCK_REALTIME *attrpp = NULL; diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c index 98b42d5c..8928974c 100644 --- a/src/platform/posix/posix_thread.c +++ b/src/platform/posix/posix_thread.c @@ -1,22 +1,13 @@ -/* - * Copyright 2016 Garrett D'Amore <garrett@damore.org> - * - * This software is supplied under the terms of the MIT License, a - * copy of which should be located in the distribution where this - * file was obtained (LICENSE.txt). A copy of the license may also be - * found online at https://opensource.org/licenses/MIT. - */ - -/* - * This is more of a direct #include of a .c rather than .h file. - * But having it be a .h makes compiler rules work out properly. Do - * not include this more than once into your program, or you will - * get multiple symbols defined. - */ - -/* - * POSIX threads. - */ +// +// Copyright 2016 Garrett D'Amore <garrett@damore.org> +// +// This software is supplied under the terms of the MIT License, a +// copy of which should be located in the distribution where this +// file was obtained (LICENSE.txt). A copy of the license may also be +// found online at https://opensource.org/licenses/MIT. +// + +// POSIX threads. #include "core/nng_impl.h" @@ -95,10 +86,10 @@ nni_plat_init(int (*helper)(void)) nni_panic("nng is fork-reentrant safe"); } if (plat_init) { - return (0); /* fast path */ + return (0); // fast path } pthread_mutex_lock(&plat_lock); - if (plat_init) { /* check again under the lock to be sure */ + if (plat_init) { // check again under the lock to be sure pthread_mutex_unlock(&plat_lock); return (0); } @@ -118,7 +109,7 @@ nni_plat_init(int (*helper)(void)) void nni_plat_fini(void) { - /* XXX: NOTHING *YET* */ + // XXX: NOTHING *YET* } |
