diff --git a/rtl/mqueue.pas b/rtl/mqueue.pas index 5d89afa5..00f08f98 100644 --- a/rtl/mqueue.pas +++ b/rtl/mqueue.pas @@ -44,9 +44,9 @@ type procedure TAILQ_INIT (head:Pointer); inline; function TAILQ_EMPTY (head:Pointer):Boolean; inline; function TAILQ_FIRST (head:Pointer):Pointer; inline; -function TAILQ_LAST (head,headname:Pointer):Pointer; inline; +function TAILQ_LAST (head:Pointer):Pointer; inline; function TAILQ_NEXT (elm,field:Pointer):Pointer; inline; -function TAILQ_PREV (elm,headname,field:Pointer):Pointer; inline; +function TAILQ_PREV (elm,field:Pointer):Pointer; inline; procedure TAILQ_INSERT_HEAD (head,elm,field:Pointer); inline; procedure TAILQ_INSERT_TAIL (head,elm,field:Pointer); inline; procedure TAILQ_INSERT_AFTER (head,listelm,elm,field:Pointer); inline; @@ -63,6 +63,7 @@ procedure LIST_REMOVE (elm,field:Pointer); inline; procedure STAILQ_INIT(head:Pointer); inline; function STAILQ_EMPTY(head:Pointer):Boolean; inline; function STAILQ_FIRST(head:Pointer):Pointer; inline; +function STAILQ_LAST(head,field:Pointer):Pointer; inline; function STAILQ_NEXT(elm,field:Pointer):Pointer; inline; procedure STAILQ_INSERT_AFTER(head,tqelm,elm,field:Pointer); inline; procedure STAILQ_INSERT_HEAD(head,elm,field:Pointer); inline; @@ -89,9 +90,9 @@ begin Result:=P_TAILQ_HEAD(head)^.tqh_first; end; -function TAILQ_LAST(head,headname:Pointer):Pointer; inline; +function TAILQ_LAST(head:Pointer):Pointer; inline; begin - Result:=P_TAILQ_HEAD(P_TAILQ_HEAD(head)^.tqh_last+ptruint(headname))^.tqh_last^; + Result:=P_TAILQ_HEAD(P_TAILQ_HEAD(head)^.tqh_last)^.tqh_last^; end; function TAILQ_NEXT(elm,field:Pointer):Pointer; inline; @@ -99,17 +100,17 @@ begin Result:=P_TAILQ_ENTRY(field)^.tqe_next; end; -function TAILQ_PREV(elm,headname,field:Pointer):Pointer; inline; +function TAILQ_PREV(elm,field:Pointer):Pointer; inline; begin - Result:=P_TAILQ_HEAD(P_TAILQ_ENTRY(field)^.tqe_prev+ptruint(headname))^.tqh_last^; + Result:=P_TAILQ_HEAD(P_TAILQ_ENTRY(field)^.tqe_prev)^.tqh_last^; end; procedure TAILQ_INSERT_HEAD(head,elm,field:Pointer); inline; var offset:ptruint; begin - if (P_TAILQ_ENTRY(field)^.tqe_next=P_TAILQ_HEAD(head)^.tqh_first) and - (P_TAILQ_HEAD(head)^.tqh_first<>nil) then + P_TAILQ_ENTRY(field)^.tqe_next:=P_TAILQ_HEAD(head)^.tqh_first; + if (P_TAILQ_ENTRY(field)^.tqe_next<>nil) then begin offset:=ptruint(field-elm); P_TAILQ_ENTRY(P_TAILQ_HEAD(head)^.tqh_first+offset)^.tqe_prev:=@P_TAILQ_ENTRY(field)^.tqe_next; @@ -198,7 +199,8 @@ procedure LIST_INSERT_HEAD(head,elm,field:Pointer); inline; var offset:ptruint; begin - if (P_LIST_ENTRY(field)^.le_next=PPointer(head)^) and (PPointer(head)^<>nil) then + P_LIST_ENTRY(field)^.le_next:=PPointer(head)^; + if (P_LIST_ENTRY(field)^.le_next<>nil) then begin offset:=ptruint(field-elm); P_LIST_ENTRY(PPointer(head)^+offset)^.le_prev:=@P_LIST_ENTRY(field)^.le_next; @@ -237,6 +239,17 @@ begin Result:=P_STAILQ_HEAD(head)^.stqh_first; end; +function STAILQ_LAST(head,field:Pointer):Pointer; inline; +begin + if (P_STAILQ_HEAD(head)^.stqh_first=nil) then + begin + Result:=nil; + end else + begin + Result:=Pointer(P_STAILQ_HEAD(head)^.stqh_last)-ptruint(@P_STAILQ_ENTRY(field)^.stqe_next); + end; +end; + function STAILQ_NEXT(elm,field:Pointer):Pointer; inline; begin Result:=P_STAILQ_ENTRY(field)^.stqe_next; diff --git a/sys/test/project1.lpr b/sys/test/project1.lpr index d3d25b71..dc039b31 100644 --- a/sys/test/project1.lpr +++ b/sys/test/project1.lpr @@ -713,6 +713,153 @@ begin end; +type + p_test_tailq=^test_tailq; + test_tailq=packed record + stub:array[0..2] of qword; + entry:TAILQ_ENTRY; + name:PChar; + end; + +procedure tailq; +var + list:TAILQ_HEAD; + e,n:p_test_tailq; +begin + TAILQ_INIT(@list); + + e:=AllocMem(SizeOf(test_tailq)); + e^.name:='one'; + //TAILQ_INSERT_TAIL(@list,e,@e^.entry); + TAILQ_INSERT_HEAD(@list,e,@e^.entry); + + e:=AllocMem(SizeOf(test_tailq)); + e^.name:='two'; + //TAILQ_INSERT_TAIL(@list,e,@e^.entry); + TAILQ_INSERT_HEAD(@list,e,@e^.entry); + + e:=AllocMem(SizeOf(test_tailq)); + e^.name:='thr'; + //TAILQ_INSERT_TAIL(@list,e,@e^.entry); + TAILQ_INSERT_HEAD(@list,e,@e^.entry); + + Writeln('TAILQ_FIRST'); + e:=TAILQ_FIRST(@list); + while (e<>nil) do + begin + Writeln(e^.name); + e:=TAILQ_NEXT(e,@e^.entry); + end; + + Writeln('TAILQ_LAST'); + e:=TAILQ_LAST(@list); + while (e<>nil) do + begin + Writeln(e^.name); + e:=TAILQ_PREV(e,@e^.entry); + end; + + Writeln('TAILQ_REMOVE'); + e:=TAILQ_FIRST(@list); + while (e<>nil) do + begin + n:=TAILQ_NEXT(e,@e^.entry); + // + TAILQ_REMOVE(@list,e,@e^.entry); + Writeln(e^.name); + FreeMem(e); + // + e:=n; + end; + + // + + LIST_INIT(@list); + + e:=AllocMem(SizeOf(test_tailq)); + e^.name:='one'; + LIST_INSERT_HEAD(@list,e,@e^.entry); + + e:=AllocMem(SizeOf(test_tailq)); + e^.name:='two'; + LIST_INSERT_HEAD(@list,e,@e^.entry); + + e:=AllocMem(SizeOf(test_tailq)); + e^.name:='thr'; + LIST_INSERT_HEAD(@list,e,@e^.entry); + + Writeln('LIST_FIRST'); + e:=LIST_FIRST(@list); + while (e<>nil) do + begin + Writeln(e^.name); + e:=LIST_NEXT(e,@e^.entry); + end; + + //REMOVE + Writeln('LIST_REMOVE'); + e:=LIST_FIRST(@list); + while (e<>nil) do + begin + n:=LIST_NEXT(e,@e^.entry); + // + LIST_REMOVE(e,@e^.entry); + Writeln(e^.name); + FreeMem(e); + // + e:=n; + end; + + // + + STAILQ_INIT(@list); + + e:=AllocMem(SizeOf(test_tailq)); + e^.name:='one'; + STAILQ_INSERT_TAIL(@list,e,@e^.entry); + //STAILQ_INSERT_HEAD(@list,e,@e^.entry); + + e:=AllocMem(SizeOf(test_tailq)); + e^.name:='two'; + STAILQ_INSERT_TAIL(@list,e,@e^.entry); + //STAILQ_INSERT_HEAD(@list,e,@e^.entry); + + e:=AllocMem(SizeOf(test_tailq)); + e^.name:='thr'; + STAILQ_INSERT_TAIL(@list,e,@e^.entry); + //STAILQ_INSERT_HEAD(@list,e,@e^.entry); + + Writeln('STAILQ_FIRST'); + e:=STAILQ_FIRST(@list); + while (e<>nil) do + begin + Writeln(e^.name); + e:=STAILQ_NEXT(e,@e^.entry); + end; + writeln; + + Writeln('STAILQ_LAST'); + e:=STAILQ_LAST(@list,@p_test_tailq(nil)^.entry); + Writeln(e^.name); + + Writeln('STAILQ_REMOVE'); + e:=STAILQ_FIRST(@list); + while (e<>nil) do + begin + n:=STAILQ_NEXT(e,@e^.entry); + // + STAILQ_REMOVE(@list,e,@e^.entry); + Writeln(e^.name); + FreeMem(e); + // + e:=n; + end; + + // + + writeln; +end; + var ThreadHandle:THandle; v:Integer; @@ -727,6 +874,8 @@ var _thr_param:thr_param; begin + tailq; + //test_map; sys_init; diff --git a/sys/vfs/vfs_mount.pas b/sys/vfs/vfs_mount.pas index 1d416407..261e069e 100644 --- a/sys/vfs/vfs_mount.pas +++ b/sys/vfs/vfs_mount.pas @@ -187,24 +187,24 @@ procedure vfs_sanitizeopts(opts:p_vfsoptlist); var opt,opt2,tmp:p_vfsopt; begin - opt:=TAILQ_LAST(opts,nil); + opt:=TAILQ_LAST(opts); while (opt<>nil) do begin - opt2:=TAILQ_PREV(opt,nil,@opt^.link); + opt2:=TAILQ_PREV(opt,@opt^.link); while (opt2<>nil) do begin if (vfs_equalopts(opt^.name, opt2^.name)<>0) then begin - tmp:=TAILQ_PREV(opt2,nil,@opt^.link); + tmp:=TAILQ_PREV(opt2,@opt^.link); vfs_freeopt(opts, opt2); opt2:=tmp; end else begin - opt2:=TAILQ_PREV(opt2,nil,@opt^.link); + opt2:=TAILQ_PREV(opt2,@opt^.link); end; end; // - opt:=TAILQ_PREV(opt,nil,@opt^.link); + opt:=TAILQ_PREV(opt,@opt^.link); end; end;