core: use reference counting for line file descriptors
authorBartosz Golaszewski <bartekgola@gmail.com>
Thu, 12 Apr 2018 10:28:18 +0000 (12:28 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Thu, 12 Apr 2018 12:47:28 +0000 (14:47 +0200)
commit5ab6ccbd4939ad3076df95f822953c885522c3d2
tree398f33d7da18fc1469bb0207252263d1cae42eb0
parent0a9faf3abfa7f739882b5a825db3a93fd2b4cb4c
core: use reference counting for line file descriptors

In v0.x series we were using a separate, refcounted structure for
storing the file descriptor returned by the linehandle request ioctl().
We also had a separate mechanism for event file descriptors. This was
quite complicated and was replaced by a simpler structure in v1.x
series.

It turned out however that we're now calling close() on already closed
descriptors when releasing a set of simultaneously requested lines.

In order to fix that we need to go back to having a refcounted file
descriptor handle. This time we're using the same structure for storing
both values and events file descriptors (even though there can't be
more than one line per descriptor requested for events) for simplicity.

This patch also adds a test case that verifies the reference counting
works as expected.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
src/lib/core.c
tests/tests-line.c