|
Electroneum
|
#include "util/log.h"

Go to the source code of this file.
Macros | |
| #define | LOCKRET(func) |
| #define | lock_protect(lock, area, size) /* nop */ |
| #define | lock_unprotect(lock, area) /* nop */ |
| #define | lock_get_mem(lock) (0) /* nothing */ |
| #define | checklock_start() /* nop */ |
| #define | checklock_stop() /* nop */ |
| #define | THREADS_DISABLED 1 |
| #define | lock_rw_init(lock) /* nop */ |
| #define | lock_rw_destroy(lock) /* nop */ |
| #define | lock_rw_rdlock(lock) /* nop */ |
| #define | lock_rw_wrlock(lock) /* nop */ |
| #define | lock_rw_unlock(lock) /* nop */ |
| #define | lock_basic_init(lock) /* nop */ |
| #define | lock_basic_destroy(lock) /* nop */ |
| #define | lock_basic_lock(lock) /* nop */ |
| #define | lock_basic_unlock(lock) /* nop */ |
| #define | lock_quick_init(lock) /* nop */ |
| #define | lock_quick_destroy(lock) /* nop */ |
| #define | lock_quick_lock(lock) /* nop */ |
| #define | lock_quick_unlock(lock) /* nop */ |
| #define | ub_thread_create(thr, func, arg) ub_thr_fork_create(thr, func, arg) |
| #define | ub_thread_self() getpid() |
| #define | ub_thread_join(thread) ub_thr_fork_wait(thread) |
| #define | ub_thread_key_create(key, f) (*(key)) = NULL |
| #define | ub_thread_key_set(key, v) (key) = (v) |
| #define | ub_thread_key_get(key) (key) |
Typedefs | |
| typedef int | lock_rw_type |
| typedef int | lock_basic_type |
| typedef int | lock_quick_type |
| typedef pid_t | ub_thread_type |
| typedef void * | ub_thread_key_type |
Functions | |
| void | ub_thr_fork_wait (ub_thread_type thread) |
| void | ub_thr_fork_create (ub_thread_type *thr, void *(*func)(void *), void *arg) |
| void | ub_thread_blocksigs (void) |
| void | ub_thread_sig_unblock (int sig) |
util/locks.h - unbound locking primitives
Copyright (c) 2007, NLnet Labs. All rights reserved.
This software is open source.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the NLNET LABS nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Locking primitives. If pthreads is available, these are used. If no locking exists, they do nothing.
The idea is to have different sorts of locks for different tasks. This allows the locking code to be ported more easily.
Types of locks that are supported. o lock_rw: lock that has many readers and one writer (to a data entry). o lock_basic: simple mutex. Blocking, one person has access only. This lock is meant for non performance sensitive uses. o lock_quick: speed lock. For performance sensitive locking of critical sections. Could be implemented by a mutex or a spinlock.
Also thread creation and deletion functions are defined here.
Definition in file locks.h.
| #define lock_protect | ( | lock, | |
| area, | |||
| size | |||
| ) | /* nop */ |
| #define LOCKRET | ( | func | ) |
The following macro is used to check the return value of the pthread calls. They return 0 on success and an errno on error. The errno is logged to the logfile with a descriptive comment.
| #define ub_thread_create | ( | thr, | |
| func, | |||
| arg | |||
| ) | ub_thr_fork_create(thr, func, arg) |
| #define ub_thread_join | ( | thread | ) | ub_thr_fork_wait(thread) |
| typedef int lock_basic_type |
| typedef int lock_quick_type |
| typedef int lock_rw_type |
| typedef void* ub_thread_key_type |
| typedef pid_t ub_thread_type |
| void ub_thr_fork_create | ( | ub_thread_type * | thr, |
| void *(*)(void *) | func, | ||
| void * | arg | ||
| ) |
| void ub_thr_fork_wait | ( | ub_thread_type | thread | ) |
| void ub_thread_blocksigs | ( | void | ) |
Block all signals for this thread. fatal exit on error.
| void ub_thread_sig_unblock | ( | int | sig | ) |
unblock one signal for this thread.