Electroneum
locks.h File Reference
#include "util/log.h"
Include dependency graph for locks.h:
This graph shows which files directly or indirectly include this file:

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)
 

Detailed Description

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.

Macro Definition Documentation

◆ checklock_start

#define checklock_start ( )    /* nop */

Definition at line 89 of file locks.h.

◆ checklock_stop

#define checklock_stop ( )    /* nop */

Definition at line 90 of file locks.h.

◆ lock_basic_destroy

#define lock_basic_destroy (   lock)    /* nop */

Definition at line 271 of file locks.h.

◆ lock_basic_init

#define lock_basic_init (   lock)    /* nop */

Definition at line 270 of file locks.h.

◆ lock_basic_lock

#define lock_basic_lock (   lock)    /* nop */

Definition at line 272 of file locks.h.

◆ lock_basic_unlock

#define lock_basic_unlock (   lock)    /* nop */

Definition at line 273 of file locks.h.

◆ lock_get_mem

#define lock_get_mem (   lock)    (0) /* nothing */

Definition at line 88 of file locks.h.

◆ lock_protect

#define lock_protect (   lock,
  area,
  size 
)    /* nop */

DEBUG: use thread debug whenever possible

Definition at line 86 of file locks.h.

◆ lock_quick_destroy

#define lock_quick_destroy (   lock)    /* nop */

Definition at line 278 of file locks.h.

◆ lock_quick_init

#define lock_quick_init (   lock)    /* nop */

Definition at line 277 of file locks.h.

◆ lock_quick_lock

#define lock_quick_lock (   lock)    /* nop */

Definition at line 279 of file locks.h.

◆ lock_quick_unlock

#define lock_quick_unlock (   lock)    /* nop */

Definition at line 280 of file locks.h.

◆ lock_rw_destroy

#define lock_rw_destroy (   lock)    /* nop */

Definition at line 263 of file locks.h.

◆ lock_rw_init

#define lock_rw_init (   lock)    /* nop */

Definition at line 262 of file locks.h.

◆ lock_rw_rdlock

#define lock_rw_rdlock (   lock)    /* nop */

Definition at line 264 of file locks.h.

◆ lock_rw_unlock

#define lock_rw_unlock (   lock)    /* nop */

Definition at line 266 of file locks.h.

◆ lock_rw_wrlock

#define lock_rw_wrlock (   lock)    /* nop */

Definition at line 265 of file locks.h.

◆ lock_unprotect

#define lock_unprotect (   lock,
  area 
)    /* nop */

Definition at line 87 of file locks.h.

◆ LOCKRET

#define LOCKRET (   func)
Value:
do {\
int lockret_err; \
if( (lockret_err=(func)) != 0) \
log_err("%s at %d could not " #func ": %s", \
__FILE__, __LINE__, strerror(lockret_err)); \
} while(0)

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.

Definition at line 67 of file locks.h.

◆ THREADS_DISABLED

#define THREADS_DISABLED   1

Definition at line 259 of file locks.h.

◆ ub_thread_create

#define ub_thread_create (   thr,
  func,
  arg 
)    ub_thr_fork_create(thr, func, arg)

ub_thread_create is simulated with fork (extremely heavy threads, with no shared memory).

Definition at line 286 of file locks.h.

◆ ub_thread_join

#define ub_thread_join (   thread)    ub_thr_fork_wait(thread)

Definition at line 289 of file locks.h.

◆ ub_thread_key_create

#define ub_thread_key_create (   key,
 
)    (*(key)) = NULL

Definition at line 293 of file locks.h.

◆ ub_thread_key_get

#define ub_thread_key_get (   key)    (key)

Definition at line 295 of file locks.h.

◆ ub_thread_key_set

#define ub_thread_key_set (   key,
 
)    (key) = (v)

Definition at line 294 of file locks.h.

◆ ub_thread_self

#define ub_thread_self ( )    getpid()

Definition at line 288 of file locks.h.

Typedef Documentation

◆ lock_basic_type

typedef int lock_basic_type

define locks to do nothing

Definition at line 269 of file locks.h.

◆ lock_quick_type

typedef int lock_quick_type

define locks to do nothing

Definition at line 276 of file locks.h.

◆ lock_rw_type

typedef int lock_rw_type

In case there is no thread support, define locks to do nothing

Definition at line 261 of file locks.h.

◆ ub_thread_key_type

typedef void* ub_thread_key_type

Definition at line 292 of file locks.h.

◆ ub_thread_type

typedef pid_t ub_thread_type

Thread creation, threads do not exist

Definition at line 283 of file locks.h.

Function Documentation

◆ ub_thr_fork_create()

void ub_thr_fork_create ( ub_thread_type thr,
void *(*)(void *)  func,
void *  arg 
)

◆ ub_thr_fork_wait()

void ub_thr_fork_wait ( ub_thread_type  thread)

◆ ub_thread_blocksigs()

void ub_thread_blocksigs ( void  )

Block all signals for this thread. fatal exit on error.

◆ ub_thread_sig_unblock()

void ub_thread_sig_unblock ( int  sig)

unblock one signal for this thread.