tech-kern archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Problem with SIMPLEQ_INSERT_TAIL
Okay, it was just a typo... hard to find by the compiler message.
It works now, thanks alot!
Am Mo., 22. Jan. 2024 um 12:37 Uhr schrieb J. Hannken-Illjes
<hannken%mailbox.org@localhost>:
>
> > On 22. Jan 2024, at 11:52, Stephan <stephanwib%googlemail.com@localhost> 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 - hannken%mailbox.org@localhost
Home |
Main Index |
Thread Index |
Old Index