Re: Problem with SIMPLEQ_INSERT_TAIL
"J. Hannken-Illjes" <[email protected]>
| Newsgroups | gmane.os.netbsd.devel.kernel |
|---|---|
| Message-ID | <[email protected]> |
> On 22. Jan 2024, at 11:52, Stephan <[email protected]> wrote: > > Hello, > > I am working on the semaphore part of my Haiku compat layer. I took > uipc_sem.c as a reference, where control structures are organized in a > dynamically allocated array and not as part of a list. > > However, I like to maintain a "free list" in the form of a SIMPLEQ, on > which unused semaphores are maintained for fast allocation. > > There is an issue in the initialization function, where each structure > is inserted into the free queue. I spent some time on this, but have > been unable to find the cause. Maybe I am overlooking something > trivial or there is something special I just don´t know. > > The compiler says: > > In file included from /home/stephan/src/sys/sys/siginfo.h:38, > from /home/stephan/src/sys/sys/signal.h:112, > from ./machine/frame.h:75, > from ./x86/cpu.h:56, > from ./machine/cpu.h:42, > from ./machine/param.h:11, > from /home/stephan/src/sys/sys/param.h:142, > from /home/stephan/src/sys/kern/uipc_hsem.c:32: > /home/stephan/src/sys/kern/uipc_hsem.c: In function 'khsem_init': > /home/stephan/src/sys/sys/queue.h:347:19: error: assignment to 'struct > khsem **' from incompatible pointer type 'struct kshem **' > [-Werror=incompatible-pointer-types] > 347 | (head)->sqh_last = &(elm)->field.sqe_next; \ > | ^ > /home/stephan/src/sys/kern/uipc_hsem.c:68:9: note: in expansion of > macro 'SIMPLEQ_INSERT_TAIL' > 68 | SIMPLEQ_INSERT_TAIL(&khsem_freeq, &hsems[i], khs_entry); > | ^~~~~~~~~~~~~~~~~~~ > > > > The relevant code snippet is this: > > const int khsem_max = 8192; > > static kmutex_t khsem_mutex __cacheline_aligned; > static struct khsem *hsems __read_mostly; > static SIMPLEQ_HEAD(, khsem) khsem_freeq; > > > int > khsem_init(void) > { > int i, sz; > > SIMPLEQ_INIT(&khsem_freeq); > mutex_init(&khsem_mutex, MUTEX_DEFAULT, IPL_NONE); > > sz = ALIGN(khsem_max * sizeof(struct khsem)); > sz = round_page(sz); > > // XXX allocate memory > > for (i = 0; i < khsem_max; i++) { > hsems[i].khs_id = i; > mutex_init(&hsems[i].khs_interlock, MUTEX_DEFAULT, IPL_NONE); > cv_init(&hsems[i].khs_cv, "acquire_sem"); > > SIMPLEQ_INSERT_TAIL(&khsem_freeq, &hsems[i], khs_entry); // > <<---- DOES NOT COMPILE > } > > } > > > The control structure looks like this: > > struct khsem { > sem_id khs_id; /* id of this semaphore */ > SIMPLEQ_ENTRY(kshem) khs_entry; /* free list entry */ Use SIMPLEQ_ENTRY(khsem) here ( s/sh/hs/ )? > kmutex_t khs_interlock; /* lock on this semaphore */ > kcondvar_t khs_cv; /* CV for wait events */ > pid_t khs_owner; /* owning process */ > char *khs_name; /* name of this semaphore */ > size_t khs_namelen; /* length of name */ > int khs_state; /* state of this port */ > int khs_waiters; > int khs_count; /* current count */ > lwpid_t khs_latest_holder; /* latest holder LWP id */ > uid_t khs_uid; /* creator uid */ > gid_t khs_gid; /* creator gid */ > }; > > > > Any help is appreciated ;) > > Thanks, > > Stephan -- J. Hannken-Illjes - [email protected]
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEyLVMkhxs8fxixv+2IOocBq6p/bMFAmWuU3IACgkQIOocBq6p /bMdfRAAhnwTjK8ByxD8VZggxiXK1rOSL9E98qXIkyNjPfhm+V383stRIaH5o3G5 OfUVikhG8XqXQO1P20GciZDEElQucrltb3YbwhMzQGsNjTyRTrL/l8cJlRwY7/A+ fSHb0+EFcyOX5swwoTBiGkMluydZEQ8l49EoOczbAunPjUIJ/LEltPPz15CiohUb IHG+AB6EsSEPQzpJiOa3aLRbNxrQ0v0e0Dqbfm2Glx00qiNWRXKZ3zpRy/evn/BI EU6Fe/yWAaUKOt6RokzGt9nT4b/lA6/cMF8NsY1Cmq41XUCRAKx03KHVvJVhPZ9z lW6T2SHqd0x3KJupsk3+CegIN9jatCPNmhqg42JpBkPT0TNwcMm2iaN0bmdGiWLX JQMyecgC0NLI+wD8jQmAw4Pj/jr3hb1dE/poIBnxR+A7NIEvdAI9XZBnOp9FcQa+ YMk+ITgnPafJtIPyknsVj2j5FOGtrg6mwF4mDwkg3xd4JRNDV2lUo5GvumvJn++G b4DZGOZ5SoX04my35QXJ+ex1nAwwifMDu++k/ap0IJrhwP+byto4xU9PMHPIfttF 3vE+yki/D0wJsK7XjkJAJ1Rt0LI4KgRhHiq7iDMYJAMbLzQd2fFNbqZlhyKCD5dq QSiSGQVQmUurb0DsmZiKjxEsH86cBzoRGMG1WjJU3g5LnvsCYpo= =5UNL -----END PGP SIGNATURE-----