SyncWaitlist impl

Implements SyncWaitlist.

Summary
SyncWaitlist implImplements SyncWaitlist.
CopyrightThis program is free software.
Files
C-kern/api/task/syncwlist.hHeader file SyncWaitlist.
C-kern/task/syncwlist.cImplementation file SyncWaitlist impl.
Types
struct wlistentry_tExport wlistentry_t into global namespace.
wlistentry_tType of entry stored in syncwlist_t.
Macros
wlistentry_FREEStatic initializer.
Functions
initmove_wlistentryMoves src to dest.
syncwlist_t
static variables
s_syncwlist_errtimerAllows to introduce artificial errors during test.
helper
dlist_IMPLEMENT _wlistImplements interface to manage wlistentry_t in a double linked list of type dlist_t.
compiletime_assertEnsures that syncwlist_t and wlistentry_t can be cast into dlist_node_t without changing the address of the pointer.
lifetime
init_syncwlistThe double linked list dlist_t will not be stored.
query
update
syncwlist_iterator_t
test

Copyright

This program is free software.  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2013 Jörg Seebohn

Files

C-kern/api/task/syncwlist.h

Header file SyncWaitlist.

C-kern/task/syncwlist.c

Implementation file SyncWaitlist impl.

Types

struct wlistentry_t

typedef struct wlistentry_t wlistentry_t

Export wlistentry_t into global namespace.

wlistentry_t

struct wlistentry_t

Type of entry stored in syncwlist_t.  It embeds a dlist_node_t and a syncevent_t.

Summary
Macros
wlistentry_FREEStatic initializer.
Functions
initmove_wlistentryMoves src to dest.

Macros

wlistentry_FREE

#define wlistentry_FREE { 0, 0, syncevent_FREE }

Static initializer.

Functions

initmove_wlistentry

void initmove_wlistentry(/*out*/wlistentry_t *dest,
wlistentry_t *src)

Moves src to dest.  Consider src uninitialized after this operation.

syncwlist_t

Summary
static variables
s_syncwlist_errtimerAllows to introduce artificial errors during test.
helper
dlist_IMPLEMENT _wlistImplements interface to manage wlistentry_t in a double linked list of type dlist_t.
compiletime_assertEnsures that syncwlist_t and wlistentry_t can be cast into dlist_node_t without changing the address of the pointer.
lifetime
init_syncwlistThe double linked list dlist_t will not be stored.
query
update

static variables

s_syncwlist_errtimer

static test_errortimer_t s_syncwlist_errtimer

Allows to introduce artificial errors during test.

helper

dlist_IMPLEMENT _wlist

Implements interface to manage wlistentry_t in a double linked list of type dlist_t.  The generated functions have name YYY_wlist (init_wlist...) instead of YYY_dlist (init_dlist...).

compiletime_assert

static inline void compiletime_assert(void)

Ensures that syncwlist_t and wlistentry_t can be cast into dlist_node_t without changing the address of the pointer.  This also ensures that syncwlist_t can be cast into wlistentry_t.

lifetime

init_syncwlist

void init_syncwlist(/*out*/syncwlist_t *wlist)

Implementation notes

The double linked list dlist_t will not be stored.  Instead wlist is considered as the last node in it and therefore has a prev and next pointer instead of a single last pointer.  This allows to move objects of type wlistentry_t in their queue and to fill any gaps created during removal of nodes.  If a node is removed from the queue function <initmove_wlistentry> is called during execution of remove_syncqueue which allows to compact memory.

Reason

If the moved node would be the last node of a dlist_t the last pointer would become invalid.  But making wlist part of the list (as dummy node) function <initmove_wlistentry> will adapt the pointers prev or next in case a node will be moved before or after node wlist.

query

update

syncwlist_iterator_t

test

Exports type syncwlist_t which implements a list of syncevent_t to support more than one waiting syncthread_t.
Implements SyncWaitlist.
typedef struct wlistentry_t wlistentry_t
Export wlistentry_t into global namespace.
struct wlistentry_t
Type of entry stored in syncwlist_t.
#define wlistentry_FREE { 0, 0, syncevent_FREE }
Static initializer.
void initmove_wlistentry(/*out*/wlistentry_t *dest,
wlistentry_t *src)
Moves src to dest.
static test_errortimer_t s_syncwlist_errtimer
Allows to introduce artificial errors during test.
struct dlist_t
Double linked circular list.
static inline void compiletime_assert(void)
Ensures that syncwlist_t and wlistentry_t can be cast into dlist_node_t without changing the address of the pointer.
struct dlist_node_t
Provides the means for linking an object to two others of the same type.
void init_syncwlist(/*out*/syncwlist_t *wlist)
The double linked list dlist_t will not be stored.
struct syncevent_t
Event type stores a pointer to a single waiting syncwait_t.
#define remove_syncqueue(
   syncqueue,
   elem,
   initmove_elem
) ( __extension__ ({ syncqueue_t * _sq = (syncqueue) ; typeof(elem) _elem = (elem) ; typeof(elem) _lastentry = last_queue( genericcast_queue(_sq), sizeof(*_elem)) ; if (_lastentry && _lastentry != _elem) { (initmove_elem)(_elem, _lastentry) ; } int _err = removelast_queue( genericcast_queue(_sq), sizeof(*_elem)) ; _sq->nrelements -= (_err == 0) ; _err ; }))
Implements syncqueue_t.remove_syncqueue.
Close