123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569 |
- #include "OSAL.h"
- #include "list_slst.h"
- #ifdef LIST_SLST_DEFS_LOGS_TAG
- #define log_err(fmt, ...) \
- logs_logs_err(LIST_SLST_DEFS_LOGS_TAG, fmt, ##__VA_ARGS__)
- #define log_war(fmt, ...) \
- logs_logs_war(LIST_SLST_DEFS_LOGS_TAG, fmt, ##__VA_ARGS__)
- #define log_inf(fmt, ...) \
- logs_logs_inf(LIST_SLST_DEFS_LOGS_TAG, fmt, ##__VA_ARGS__)
- #define log_ver(fmt, ...) \
- logs_logs_ver(LIST_SLST_DEFS_LOGS_TAG, fmt, ##__VA_ARGS__)
- #define log_ent(fmt, ...) \
- logs_logs_ent(fmt, ##__VA_ARGS__)
- #define log_exi(fmt, ...) \
- logs_logs_exi(fmt, ##__VA_ARGS__)
- #else
- #define log_err(fmt, ...)
- #define log_war(fmt, ...)
- #define log_inf(fmt, ...)
- #define log_ver(fmt, ...)
- #define log_ent(fmt, ...)
- #define log_exi(fmt, ...)
- #endif
- static signed int
- list_snod_ini_lin(list_snod_t* snod)
- {
- signed int rslt = 0;
-
- if ( 0 == snod ) {
-
- rslt = 0;
- } else {
- snod->next = 0;
- rslt = 1;
- }
-
- return ( rslt );
- }
- static signed int
- list_snod_ini_cir(list_snod_t* snod)
- {
- signed int rslt = 0;
-
- if ( 0 == snod ) {
-
- rslt = 0;
- } else {
- snod->next = snod;
- rslt = 1;
- }
- return ( rslt );
- }
- static signed int
- list_snod_ins_aft(list_snod_t* nod0, list_snod_t* nod1)
- {
- signed int rslt = 0;
-
-
- if ( 0 == nod0 || 0 == nod1 ) {
- rslt = 0;
- goto ERR_INV;
- }
-
- nod1->next = nod0->next;
- nod0->next = nod1;
-
- rslt = 1;
- goto ERR_SUC;
- ERR_INV:
- ERR_SUC:
- return ( rslt );
- }
- static signed int
- list_snod_rmv_aft(list_snod_t* snod)
- {
- signed int rslt = 0;
-
-
- if ( 0 == snod ) {
- rslt = 0;
- goto ERR_INV;
- }
- if ( 0 != snod->next ) {
- snod->next = snod->next->next;
- }
-
- rslt = 1;
- goto ERR_SUC;
- ERR_INV:
- ERR_SUC:
- return ( rslt );
- }
- signed int
- list_snod_ini(list_snod_t* snod, list_snod_e type)
- {
- signed int rslt = 0;
- if ( list_slst_enum_snod_lin == type ) {
- rslt = list_snod_ini_lin(snod);
- } else
- if ( list_slst_enum_snod_cir == type ) {
- rslt = list_snod_ini_cir(snod);
- }
-
- return ( rslt );
- }
- signed int
- list_slst_ini(list_slst_t* slst)
- {
- signed int rslt = 0;
-
-
- if ( 0 == slst ) {
- rslt = 0;
- goto ERR_INV;
- }
- slst->head = 0;
- slst->tail = 0;
- slst->iter = 0;
- slst->coun = 0;
-
-
- rslt = 1;
- goto ERR_SUC;
- ERR_INV:
- ERR_SUC:
- return ( rslt );
- }
- signed int
- list_slst_add(list_slst_t* slst, list_snod_t* snod)
- {
- signed int rslt = 0;
- list_snod_t* curr = 0;
-
- if ( 0 == snod ) {
- rslt = 0;
- goto ERR_INV;
- }
- list_slst_emu(slst);
- while ( 1 ) {
- curr = list_slst_nxt(slst);
- if ( 0 == curr ) {
- if ( 0 >= slst->coun ) {
- slst->head = snod;
- slst->tail = snod;
- } else {
-
- list_snod_ins_aft(slst->tail, snod);
- slst->tail = snod;
- }
- slst->coun ++;
- rslt = 1;
- goto ERR_SUC;
- } else
- if ( snod == curr ) {
- rslt = 0;
- goto ERR_DOE;
- }
- }
- ERR_DOE:
- ERR_INV:
- ERR_SUC:
- return ( rslt );
- }
- signed int
- list_slst_rmv(list_slst_t* slst, list_snod_t* snod)
- {
- signed int rslt = 0;
- list_snod_t* prev = 0;
- list_snod_t* curr = 0;
-
-
- if ( 0 == snod ) {
- rslt = 0;
- goto ERR_INV;
- }
-
- list_slst_emu(slst);
- while ( 1 ) {
- curr = list_slst_nxt(slst);
- if ( 0 == curr ) {
- rslt = 0;
- goto ERR_NOF;
- } else
- if ( snod == curr ) {
- slst->coun --;
- if ( 0 >= slst->coun ) {
- slst->tail = slst->head = 0;
- } else
- if ( snod == slst->head ) {
- slst->head = snod->next;
- } else
- if ( snod == slst->tail ) {
- slst->tail = prev;
- }
-
- if ( 0 != prev ) {
- list_snod_rmv_aft(prev);
- }
- rslt = 1;
- goto ERR_SUC;
- }
- prev = curr;
- }
- ERR_NOF:
- ERR_INV:
- ERR_SUC:
- return ( rslt );
- }
- signed int
- list_slst_has(list_slst_t* slst, const list_snod_t* snod)
- {
- signed int rslt = 0;
- list_snod_t* curr = 0;
-
-
- if ( 0 == snod ) {
- rslt = 0;
- goto ERR_INV;
- }
- list_slst_emu(slst);
- while ( 1 ) {
- curr = list_slst_nxt(slst);
- if ( 0 == curr ) {
- rslt = 0;
- break;
- } else
- if ( snod == curr ) {
- rslt = 1;
- break;
- }
- }
- ERR_INV:
- return ( rslt );
- }
- signed int
- list_slst_emu(list_slst_t* slst)
- {
- return ( 0 != (slst->iter = slst->head) ? 1 : 0 );
- }
- list_snod_t*
- list_slst_nxt(list_slst_t* slst)
- {
- list_snod_t* rslt = 0;
-
- if ( 0 != slst ) {
- rslt = slst->iter;
- }
- if ( 0 != rslt ) {
- slst->iter = rslt->next;
- }
- if ( slst->iter == slst->head ) {
- rslt = 0;
- }
-
- return ( rslt );
- }
- signed int
- list_sque_ini(list_sque_t* sque)
- {
- signed int rslt = 0;
- if ( 0 == sque ) {
- rslt = 0;
- goto ERR_INV;
- }
-
- list_slst_ini(&sque->list);
-
- sque->post = 0;
- sque->pend = 0;
- sque->coun = 0;
-
- rslt = 1;
- goto ERR_SUC;
- ERR_INV:
- ERR_SUC:
- return ( rslt );
- }
- signed int
- list_sque_fsh(list_sque_t* sque)
- {
- signed int rslt = 0;
-
- if ( 0 == sque ) {
- rslt = 0;
- goto ERR_INV;
- }
- sque->post = sque->list.head;
- sque->pend = sque->list.head;
- sque->coun = 0;
-
- rslt = 1;
- goto ERR_SUC;
- ERR_INV:
- ERR_SUC:
- return ( rslt );
- }
- signed int
- list_sque_pop(list_sque_t* sque, void* data, unsigned int size)
- {
- signed int rslt = 0;
-
-
-
- if ( 0 == sque ) {
- rslt = 0;
- goto ERR_INV;
- }
-
- if ( 0 >= sque->coun ) {
- rslt = 0;
- goto ERR_INV;
- }
-
- if ( sque->list.head != sque->list.tail->next ) {
- rslt = 0;
- goto ERR_INV;
- }
- osal_memcpy(data, sque->post+1, size);
-
-
- sque->post = sque->post->next;
- sque->coun --;
-
-
- rslt = 1;
- goto ERR_SUC;
- ERR_INV:
- ERR_SUC:
- return ( rslt );
- }
- signed int
- list_sque_psh(list_sque_t* sque, void* data, unsigned int size)
- {
- signed int rslt = 0;
-
-
-
- if ( 0 == sque ) {
- rslt = 0;
- goto ERR_INV;
- }
-
- if ( sque->coun >= sque->list.coun ) {
- rslt = 0;
- goto ERR_INV;
- }
-
- if ( sque->list.head != sque->list.tail->next ) {
- rslt = 0;
- goto ERR_INV;
- }
-
- osal_memcpy(sque->pend+1, data, size);
- sque->pend = sque->pend->next;
- sque->coun ++;
-
-
- rslt = 1;
- goto ERR_SUC;
- ERR_INV:
- ERR_SUC:
- return ( rslt );
- }
|