Waitlist Linuximpl

Implements Waitlist.

Summary
Waitlist LinuximplImplements Waitlist.
CopyrightThis program is free software.
Files
C-kern/api/platform/sync/waitlist.hHeader file of Waitlist.
C-kern/platform/Linux/sync/waitlist.cLinux specific implementation file Waitlist Linuximpl.
waitlist_t
helper
INTERFACE_wlistUse macro slist_IMPLEMENT to generate an adapted interface of slist_t to thread_t.
lifetime
query
synchronize
lockflag_waitlistWait until wlist->lockflag is cleared and set it atomically.
unlockflag_waitlistClear wlist->lockflag.
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

© 2011 Jörg Seebohn

Files

C-kern/api/platform/sync/waitlist.h

Header file of Waitlist.

C-kern/platform/Linux/sync/waitlist.c

Linux specific implementation file Waitlist Linuximpl.

waitlist_t

Summary
helper
INTERFACE_wlistUse macro slist_IMPLEMENT to generate an adapted interface of slist_t to thread_t.
lifetime
query
synchronize
lockflag_waitlistWait until wlist->lockflag is cleared and set it atomically.
unlockflag_waitlistClear wlist->lockflag.
test

helper

INTERFACE_wlist

Use macro slist_IMPLEMENT to generate an adapted interface of slist_t to thread_t.

lifetime

query

synchronize

lockflag_waitlist

static inline void lockflag_waitlist(waitlist_t *wlist)

Wait until wlist->lockflag is cleared and set it atomically.  Includes an acuire memory barrier.  Calling thread can see what was written by other threads before the flag was set.

unlockflag_waitlist

static inline void unlockflag_waitlist(waitlist_t *wlist)

Clear wlist->lockflag.  Include a release memory barrier.  All other threads can see what was written before flag was cleared.

test

Allows threads of a single process to wait for a certain condition.
Implements Waitlist.
#define slist_IMPLEMENT(
   _fsuffix,
   object_t,
   name_nextptr
) typedef slist_iterator_t iteratortype##_fsuffix ; typedef object_t * iteratedtype##_fsuffix ; static inline int initfirst##_fsuffix##iterator(slist_iterator_t * iter, slist_t * list) __attribute__ ((always_inline)) ; static inline int free##_fsuffix##iterator(slist_iterator_t * iter) __attribute__ ((always_inline)) ; static inline bool next##_fsuffix##iterator(slist_iterator_t * iter, object_t ** node) __attribute__ ((always_inline)) ; static inline void init##_fsuffix(slist_t * list) __attribute__ ((always_inline)) ; static inline int free##_fsuffix(slist_t * list, struct typeadapt_t * typeadp) __attribute__ ((always_inline)) ; static inline int isempty##_fsuffix(const slist_t * list) __attribute__ ((always_inline)) ; static inline object_t * first##_fsuffix(const slist_t * list) __attribute__ ((always_inline)) ; static inline object_t * last##_fsuffix(const slist_t * list) __attribute__ ((always_inline)) ; static inline object_t * next##_fsuffix(object_t * node) __attribute__ ((always_inline)) ; static inline bool isinlist##_fsuffix(object_t * node) __attribute__ ((always_inline)) ; static inline void insertfirst##_fsuffix(slist_t * list, object_t * new_node) __attribute__ ((always_inline)) ; static inline void insertlast##_fsuffix(slist_t * list, object_t * new_node) __attribute__ ((always_inline)) ; static inline void insertafter##_fsuffix(slist_t * list, object_t * prev_node, object_t * new_node) __attribute__ ((always_inline)) ; static inline int removefirst##_fsuffix(slist_t * list, object_t ** removed_node) __attribute__ ((always_inline)) ; static inline int removeafter##_fsuffix(slist_t * list, object_t * prev_node, object_t ** removed_node) __attribute__ ((always_inline)) ; static inline int removeall##_fsuffix(slist_t * list, struct typeadapt_t * typeadp) __attribute__ ((always_inline)) ; static inline slist_node_t * asnode##_fsuffix(object_t * object) { static_assert(&((object_t*)0)->name_nextptr == (slist_node_t**)offsetof(object_t, name_nextptr), "correct type") ; return (slist_node_t *) ((uintptr_t)object + offsetof(object_t, name_nextptr)) ; } static inline object_t * asobject##_fsuffix(slist_node_t * node) { return (object_t *) ((uintptr_t)node - offsetof(object_t, name_nextptr)) ; } static inline object_t * asobjectnull##_fsuffix(slist_node_t * node) { return node ? (object_t *) ((uintptr_t)node - offsetof(object_t, name_nextptr)) : 0 ; } static inline void init##_fsuffix(slist_t * list) { init_slist(list) ; } static inline void initsingle##_fsuffix(slist_t * list, object_t * node) { initsingle_slist(list, asnode##_fsuffix(node)) ; } static inline int free##_fsuffix(slist_t * list, struct typeadapt_t * typeadp) { return free_slist(list, offsetof(object_t, name_nextptr), typeadp) ; } static inline int isempty##_fsuffix(const slist_t * list) { return isempty_slist(list) ; } static inline object_t * first##_fsuffix(const slist_t * list) { return asobjectnull##_fsuffix(first_slist(list)) ; } static inline object_t * last##_fsuffix(const slist_t * list) { return asobjectnull##_fsuffix(last_slist(list)) ; } static inline object_t * next##_fsuffix(object_t * node) { return asobject##_fsuffix(next_slist(asnode##_fsuffix(node))) ; } static inline bool isinlist##_fsuffix(object_t * node) { return isinlist_slist(asnode##_fsuffix(node)) ; } static inline void insertfirst##_fsuffix(slist_t * list, object_t * new_node) { insertfirst_slist(list, asnode##_fsuffix(new_node)) ; } static inline void insertlast##_fsuffix(slist_t * list, object_t * new_node) { insertlast_slist(list, asnode##_fsuffix(new_node)) ; } static inline void insertafter##_fsuffix(slist_t * list, object_t * prev_node, object_t * new_node) { insertafter_slist(list, asnode##_fsuffix(prev_node), asnode##_fsuffix(new_node)) ; } static inline int removefirst##_fsuffix(slist_t * list, object_t ** removed_node) { int err = removefirst_slist(list, (slist_node_t**)removed_node) ; if (!err) *removed_node = asobject##_fsuffix(*(slist_node_t**)removed_node) ; return err ; } static inline int removeafter##_fsuffix(slist_t * list, object_t * prev_node, object_t ** removed_node) { int err = removeafter_slist(list, asnode##_fsuffix(prev_node), (slist_node_t**)removed_node) ; if (!err) *removed_node = asobject##_fsuffix(*(slist_node_t**)removed_node) ; return err ; } static inline int removeall##_fsuffix(slist_t * list, struct typeadapt_t * typeadp) { return removeall_slist(list, offsetof(object_t, name_nextptr), typeadp) ; } static inline int initfirst##_fsuffix##iterator(slist_iterator_t * iter, slist_t * list) { return initfirst_slistiterator(iter, list) ; } static inline int free##_fsuffix##iterator(slist_iterator_t * iter) { return free_slistiterator(iter) ; } static inline bool next##_fsuffix##iterator(slist_iterator_t * iter, object_t ** node) { bool isNext = next_slistiterator(iter, (slist_node_t**)node) ; if (isNext) *node = asobject##_fsuffix(*(slist_node_t**)node) ; return isNext ; }
Implements slist_t.slist_IMPLEMENT.
static inline void lockflag_waitlist(waitlist_t *wlist)
Wait until wlist->lockflag is cleared and set it atomically.
static inline void unlockflag_waitlist(waitlist_t *wlist)
Clear wlist->lockflag.
Close