diff options
| author | Garrett D'Amore <garrett@damore.org> | 2016-12-21 00:38:26 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2016-12-21 00:38:26 -0800 |
| commit | 5db7f0f969fb05cb0783acd187857b7b06b09b8b (patch) | |
| tree | 421d2fdaf2830e961ab9cd50dc518e22803b62ec /src/platform/posix | |
| parent | 529c84d6a1bf2400170263c9e68d9433a70cc43d (diff) | |
| download | nng-5db7f0f969fb05cb0783acd187857b7b06b09b8b.tar.gz nng-5db7f0f969fb05cb0783acd187857b7b06b09b8b.tar.bz2 nng-5db7f0f969fb05cb0783acd187857b7b06b09b8b.zip | |
Uncrustify configuration, and shorter copyright banners, plus reformat
code with uncrustify. (Minor adjustments.) No more arguments!
Diffstat (limited to 'src/platform/posix')
| -rw-r--r-- | src/platform/posix/posix_alloc.c | 26 | ||||
| -rw-r--r-- | src/platform/posix/posix_clock.c | 44 | ||||
| -rw-r--r-- | src/platform/posix/posix_config.h | 35 | ||||
| -rw-r--r-- | src/platform/posix/posix_debug.c | 25 | ||||
| -rw-r--r-- | src/platform/posix/posix_impl.h | 23 | ||||
| -rw-r--r-- | src/platform/posix/posix_synch.c | 43 | ||||
| -rw-r--r-- | src/platform/posix/posix_thread.c | 39 | ||||
| -rw-r--r-- | src/platform/posix/posix_vsnprintf.c | 24 |
8 files changed, 92 insertions, 167 deletions
diff --git a/src/platform/posix/posix_alloc.c b/src/platform/posix/posix_alloc.c index b47a95b2..16b2dce3 100644 --- a/src/platform/posix/posix_alloc.c +++ b/src/platform/posix/posix_alloc.c @@ -1,23 +1,10 @@ /* * Copyright 2016 Garrett D'Amore <garrett@damore.org> * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * 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. */ /* @@ -36,13 +23,13 @@ /* * POSIX memory allocation. This is pretty much standard C. */ - void * nni_alloc(size_t size) { return (malloc(size)); } + void nni_free(void *ptr, size_t size) { @@ -50,4 +37,5 @@ nni_free(void *ptr, size_t size) free(ptr); } -#endif
\ No newline at end of file + +#endif diff --git a/src/platform/posix/posix_clock.c b/src/platform/posix/posix_clock.c index c772263c..4307fa89 100644 --- a/src/platform/posix/posix_clock.c +++ b/src/platform/posix/posix_clock.c @@ -1,23 +1,10 @@ /* * Copyright 2016 Garrett D'Amore <garrett@damore.org> * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * 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. */ /* @@ -38,17 +25,16 @@ #include <errno.h> #include <string.h> -#ifndef NNG_USE_GETTIMEOFDAY +#ifndef NNG_USE_GETTIMEOFDAY /* * Use POSIX realtime stuff. */ - uint64_t nni_clock(void) { - struct timespec ts; - uint64_t usec; + struct timespec ts; + uint64_t usec; if (clock_gettime(NNG_USE_CLOCKID, &ts) != 0) { /* This should never ever occur. */ @@ -76,7 +62,8 @@ nni_usleep(uint64_t usec) } } -#else /* NNG_USE_GETTIMEOFDAY */ + +#else /* NNG_USE_GETTIMEOFDAY */ /* * If you're here, its because you don't have a modern clock_gettime with @@ -98,6 +85,7 @@ nni_clock(void) uint64_t usec; struct timeval tv; + if (gettimeofday(&tv, NULL) != 0) { nni_panic("gettimeofday failed: %s", strerror(errno)); } @@ -108,6 +96,7 @@ nni_clock(void) return (usec); } + void nni_usleep(uint64_t usec) { @@ -133,7 +122,7 @@ nni_usleep(uint64_t usec) pfd.fd = -1; pfd.events = 0; - now = nni_clock(); + now = nni_clock(); expire = now + usec; while (now < expire) { @@ -144,11 +133,12 @@ nni_usleep(uint64_t usec) * early. So this gives us a better chance to avoid adding * nearly an extra unneeded millisecond to the wait. */ - (void) poll(&pfd, 0, (int)((expire - now) / 1000)); - now = nni_clock(); + (void) poll(&pfd, 0, (int) ((expire - now) / 1000)); + now = nni_clock(); } } -#endif /* NNG_USE_GETTIMEOFDAY */ -#endif /* PLATFORM_POSIX_CLOCK */ +#endif /* NNG_USE_GETTIMEOFDAY */ + +#endif /* PLATFORM_POSIX_CLOCK */ diff --git a/src/platform/posix/posix_config.h b/src/platform/posix/posix_config.h index 1e83a948..a8da8ccd 100644 --- a/src/platform/posix/posix_config.h +++ b/src/platform/posix/posix_config.h @@ -1,23 +1,10 @@ /* * Copyright 2016 Garrett D'Amore <garrett@damore.org> * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * 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. */ /* @@ -35,7 +22,7 @@ * This value may be ignored on platforms that don't use POSIX clocks. * * #define NNG_USE_CLOCKID - * This macro may be defined to a different clock id (see + * This macro may be defined to a different clock id (see * clock_gettime()). By default we use CLOCK_MONOTONIC if it exists, * or CLOCK_REALTIME otherwise. This is ignored if NNG_USE_GETTIMEOFDAY * is defined. Platforms that don't use POSIX clocks will probably @@ -49,12 +36,12 @@ #include <time.h> -#ifndef CLOCK_REALTIME -#define NNG_USE_GETTIMEOFDAY +#ifndef CLOCK_REALTIME +#define NNG_USE_GETTIMEOFDAY #elif !defined(NNG_USE_CLOCKID) -#ifdef CLOCK_MONOTONIC -#define NNG_USE_CLOCKID CLOCK_MONOTONIC +#ifdef CLOCK_MONOTONIC +#define NNG_USE_CLOCKID CLOCK_MONOTONIC #else -#define NNG_USE_CLOCKID CLOCK_REALTIME +#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 6b2d875a..37c0af66 100644 --- a/src/platform/posix/posix_debug.c +++ b/src/platform/posix/posix_debug.c @@ -1,23 +1,10 @@ /* * Copyright 2016 Garrett D'Amore <garrett@damore.org> * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * 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" @@ -33,10 +20,12 @@ nni_plat_abort(void) abort(); } + void nni_plat_println(const char *message) { (void) fprintf(stderr, "%s\n", message); } -#endif /* PLATFORM_POSIX_DEBUG */
\ No newline at end of file + +#endif /* PLATFORM_POSIX_DEBUG */ diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h index 48b6e99b..c18af983 100644 --- a/src/platform/posix/posix_impl.h +++ b/src/platform/posix/posix_impl.h @@ -1,23 +1,10 @@ /* * Copyright 2016 Garrett D'Amore <garrett@damore.org> * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * 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. */ /* @@ -30,7 +17,7 @@ * functionality. */ -#ifdef PLATFORM_POSIX +#ifdef PLATFORM_POSIX #define PLATFORM_POSIX_ALLOC #define PLATFORM_POSIX_DEBUG #define PLATFORM_POSIX_CLOCK diff --git a/src/platform/posix/posix_synch.c b/src/platform/posix/posix_synch.c index cb8b30dd..555da36b 100644 --- a/src/platform/posix/posix_synch.c +++ b/src/platform/posix/posix_synch.c @@ -1,23 +1,10 @@ /* * Copyright 2016 Garrett D'Amore <garrett@damore.org> * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * 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. */ /* @@ -40,12 +27,12 @@ #include <time.h> struct nni_mutex { - pthread_mutex_t mx; + pthread_mutex_t mx; }; struct nni_cond { - pthread_cond_t cv; - pthread_mutex_t *mx; + pthread_cond_t cv; + pthread_mutex_t * mx; }; int @@ -83,6 +70,7 @@ nni_mutex_create(nni_mutex_t *mp) return (0); } + void nni_mutex_destroy(nni_mutex_t m) { @@ -92,6 +80,7 @@ nni_mutex_destroy(nni_mutex_t m) nni_free(m, sizeof (*m)); } + void nni_mutex_enter(nni_mutex_t m) { @@ -100,6 +89,7 @@ nni_mutex_enter(nni_mutex_t m) } } + void nni_mutex_exit(nni_mutex_t m) { @@ -108,6 +98,7 @@ nni_mutex_exit(nni_mutex_t m) } } + int nni_mutex_tryenter(nni_mutex_t m) { @@ -117,12 +108,14 @@ nni_mutex_tryenter(nni_mutex_t m) return (0); } + int cond_attr(pthread_condattr_t **attrpp) { #if defined(NNG_USE_GETTIMEOFDAY) || NNG_USE_CLOCKID == CLOCK_REALTIME *attrpp = NULL; return (0); + #else /* In order to make this fast, avoid reinitializing attrs. */ static pthread_condattr_t attr; @@ -156,9 +149,11 @@ cond_attr(pthread_condattr_t **attrpp) (void) pthread_mutex_unlock(&mx); *attrpp = &attr; return (0); + #endif } + int nni_cond_create(nni_cond_t *cvp, nni_mutex_t mx) { @@ -186,6 +181,7 @@ nni_cond_create(nni_cond_t *cvp, nni_mutex_t mx) return (0); } + void nni_cond_destroy(nni_cond_t c) { @@ -195,6 +191,7 @@ nni_cond_destroy(nni_cond_t c) nni_free(c, sizeof (*c)); } + void nni_cond_signal(nni_cond_t c) { @@ -203,6 +200,7 @@ nni_cond_signal(nni_cond_t c) } } + void nni_cond_broadcast(nni_cond_t c) { @@ -211,6 +209,7 @@ nni_cond_broadcast(nni_cond_t c) } } + void nni_cond_wait(nni_cond_t c) { @@ -219,6 +218,7 @@ nni_cond_wait(nni_cond_t c) } } + int nni_cond_timedwait(nni_cond_t c, uint64_t usec) { @@ -240,4 +240,5 @@ nni_cond_timedwait(nni_cond_t c, uint64_t usec) return (0); } -#endif
\ No newline at end of file + +#endif diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c index a41c7e7c..98b42d5c 100644 --- a/src/platform/posix/posix_thread.c +++ b/src/platform/posix/posix_thread.c @@ -1,23 +1,10 @@ /* * Copyright 2016 Garrett D'Amore <garrett@damore.org> * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * 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. */ /* @@ -41,8 +28,8 @@ struct nni_thread { pthread_t tid; - void *arg; - void (*func)(void *); + void * arg; + void (*func)(void *); }; static pthread_mutex_t plat_lock = PTHREAD_MUTEX_INITIALIZER; @@ -58,6 +45,7 @@ thrfunc(void *arg) return (NULL); } + int nni_thread_create(nni_thread_t *tp, void (*fn)(void *), void *arg) { @@ -78,34 +66,39 @@ nni_thread_create(nni_thread_t *tp, void (*fn)(void *), void *arg) return (0); } + void nni_thread_reap(nni_thread_t thr) { int rv; + if ((rv = pthread_join(thr->tid, NULL)) != 0) { nni_panic("pthread_thread: %s", strerror(errno)); } nni_free(thr, sizeof (*thr)); } + void atfork_child(void) { plat_fork = 1; } + int nni_plat_init(int (*helper)(void)) { int rv; + if (plat_fork) { 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); } @@ -121,10 +114,12 @@ nni_plat_init(int (*helper)(void)) return (rv); } + void nni_plat_fini(void) { /* XXX: NOTHING *YET* */ } -#endif
\ No newline at end of file + +#endif diff --git a/src/platform/posix/posix_vsnprintf.c b/src/platform/posix/posix_vsnprintf.c index 42367b4c..d8191a90 100644 --- a/src/platform/posix/posix_vsnprintf.c +++ b/src/platform/posix/posix_vsnprintf.c @@ -1,23 +1,10 @@ /* * Copyright 2016 Garrett D'Amore <garrett@damore.org> * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. + * 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" @@ -33,4 +20,5 @@ nni_plat_vsnprintf(char *dst, size_t sz, const char *fmt, va_list va) (void) vsnprintf(dst, sz, fmt, va); } -#endif
\ No newline at end of file + +#endif |
