SANEI_THREAD proposal

Yuri Dario (mc6530@mclink.it)
Sat, 01 Aug 1998 19:46:30 +0100

--_=_=_=IMA.BOUNDARY.EX1BDI138764=_=_=_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

Hi,

I have wrote an initial API for thread support. It consist of 3 functions

extern int sanei_thread_begin( void (*start)(void *arg),
unsigned stack_size,
void *arg_list);
extern int sanei_thread_kill( int pid, int sig);
extern int sanei_thread_wait( int pid, int *stat_loc, int options);

that should replace fork(), kill() and waitpid(). They have the same parameters, except for thread_begin that require a
pointer to a function, a stack size and a pointer to data.

I have included also the patches to the Umax backend as example. There is only one problem: the call to close(fds[1]),
must be avoided when using threads. I think it could be removed also on other platforms, because file handles are
closed automatically at process exit.
I have also added reader_fds to Umax_Scanner structure, so I don't need to create another data structure, as I wrote in
the past.

If you find that changes useful, I will add them also to Mustek,Tamarack, SnapScan, Coolscan backends. Without that
changes, those backends wont work under OS/2.

I have tested the code on an Umax Astra 610S, connected to my (old!) Adaptec 1542CF.

Bye,

Yuri Dario

/*
* member of TeamOS/2 - Italy
*/

--_=_=_=IMA.BOUNDARY.EX1BDI138764=_=_=_
Content-Type: application/octet-stream; name="sanei_thread.c"
Content-Transfer-Encoding: base64

Lyogc2FuZSAtIFNjYW5uZXIgQWNjZXNzIE5vdyBFYXN5LgogICBDb3B5cmlnaHQgKEMpIDE5OTgg
WXVyaSBEYXJpbwogICBUaGlzIGZpbGUgaXMgcGFydCBvZiB0aGUgU0FORSBwYWNrYWdlLgoKICAg
VGhpcyBwcm9ncmFtIGlzIGZyZWUgc29mdHdhcmU7IHlvdSBjYW4gcmVkaXN0cmlidXRlIGl0IGFu
ZC9vcgogICBtb2RpZnkgaXQgdW5kZXIgdGhlIHRlcm1zIG9mIHRoZSBHTlUgR2VuZXJhbCBQdWJs
aWMgTGljZW5zZSBhcwogICBwdWJsaXNoZWQgYnkgdGhlIEZyZWUgU29mdHdhcmUgRm91bmRhdGlv
bjsgZWl0aGVyIH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oPgoKI2luY2x1ZGUgPHN0ZGlvLmg+CiNp
bmNsdWRlIDxzdGRsaWIuaD4KI2lmZGVmIEhBVkVfVU5JU1REX0gKIyBpbmNsdWRlIDx1bmlzdGQu
aD4KI2VuZGlmCgojaWZkZWYgX19FTVhfXwojZGVmaW5lIElOQ0xfRE9TUFJPQ0VTUwojaW5jbHVk
ZSA8b3MyLmg+CiNlbmRpZgoKI2luY2x1ZGUgPHNhbmUvc2FuZWlfdGhyZWFkLmg+CgppbnQKc2Fu
ZWlfdGhyZWFkX2JlZ2luKCB2b2lkICgqc3RhcnQpKHZvaWQgKmFyZyksIAogICAgICAgICAgICAg
ICAgICAgIHVuc2lnbmVkIHN0YWNrX3NpemUsIAogICAgICAgICAgICAgICAgICAgIHZvaWQgKmFy
Z19saXN0KQp7CiNpZmRlZiBfX0VNWF9fCiAgIHJldHVybiBfYmVnaW50aHJlYWQoIHN0YXJ0LCBO
VUxMLCBzdGFja19zaXplLCBhcmdfbGlzdCk7CiNlbHNlCiAgIHJldHVybiBmb3JrKCk7CiNlbmRp
Zgp9CgppbnQKc2FuZWlfdGhyZWFkX2tpbGwoIGludCBwaWQsIGludCBzaWcpCnsKI2lmZGVmIF9f
RU1YX18KICAgcmV0dXJuIERvc0tpbGxUaHJlYWQoIHBpZCk7CiNlbHNlCiAgIHJldHVybiBraWxs
KCBwaWQsIHNpZyk7CiNlbmRpZgp9CgppbnQKc2FuZWlfdGhyZWFkX3dhaXQoIGludCBwaWQsIGlu
dCAqc3RhdF9sb2MsIGludCBvcHRpb25zKQp7CiNpZmRlZiBfX0VNWF9fCiAgIHJldHVybiAwOyAv
KiBEb3NXYWl0VGhyZWFkKCAoVElEKikgJnBpZCwgRENXV19XQUlUKTsqLwojZWxzZQogICByZXR1
cm4gd2FpdHBpZCggcGlkLCBzaWcpOwojZW5kaWYKfQoK

--_=_=_=IMA.BOUNDARY.EX1BDI138764=_=_=_
Content-Type: application/octet-stream; name="sanei_thread.h"
Content-Transfer-Encoding: base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YnJpZGdlLCBNQSAwMjEzOSwg
VVNBLgoKICAgVGhpcyBmaWxlIGRlY2xhcmVzIFNBTkUgYXBwbGljYXRpb24gaW50ZXJmYWNlLiAg
U2VlIHRoZSBTQU5FCiAgIHN0YW5kYXJkIGZvciBhIGRldGFpbGVkIGV4cGxhbmF0aW9uIG9mIHRo
ZSBpbnRlcmZhY2UuICAqLwogICAKI2lmbmRlZiBzYW5laV90aHJlYWRfaAojZGVmaW5lIHNhbmVp
X3RocmVhZF9oCgpleHRlcm4gaW50IHNhbmVpX3RocmVhZF9iZWdpbiggdm9pZCAoKnN0YXJ0KSh2
b2lkICphcmcpLCAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHVuc2lnbmVkIHN0YWNr
X3NpemUsIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdm9pZCAqYXJnX2xpc3QpOwpl
eHRlcm4gaW50IHNhbmVpX3RocmVhZF9raWxsKCBpbnQgcGlkLCBpbnQgc2lnKTsKZXh0ZXJuIGlu
dCBzYW5laV90aHJlYWRfd2FpdCggaW50IHBpZCwgaW50ICpzdGF0X2xvYywgaW50IG9wdGlvbnMp
OwoKI2VuZGlmIC8qIHNhbmVpX3RocmVhZF9oICovCg==

--_=_=_=IMA.BOUNDARY.EX1BDI138764=_=_=_
Content-Type: application/octet-stream; name="patch.umax"
Content-Transfer-Encoding: base64

ZGlmZiAtdSAuL3VtYXguYyAuL3VtYXguYw0KLS0tIC4vdW1heC5jCVR1ZSBKdWwgMjggMDQ6NTU6
MDYgMTk5OA0KKysrIC4vdW1heC5jCVNhdCBBdWcgIDEgMTk6Mzk6NTYgMTk5OA0KQEAgLTEzNyw2
ICsxMzcsNyBAQA0KICNpbmNsdWRlICJzYW5lL3NhbmVvcHRzLmgiDQogI2luY2x1ZGUgInNhbmUv
c2FuZWlfc2NzaS5oIg0KICNpbmNsdWRlICJzYW5lL3NhbmVpX2RlYnVnLmgiDQorI2luY2x1ZGUg
InNhbmUvc2FuZWlfdG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I2lmbmRlZiBIQVZFX09TMl9IDQogICBjbG9zZShmZHNb
MV0pOw0KKyNlbmRpZg0KKw0KICAgc2Nhbm5lci0+cGlwZSA9IGZkc1swXTsNCiANCiAgcmV0dXJu
IFNBTkVfU1RBVFVTX0dPT0Q7DQpkaWZmIC11IC4vdW1heC5oIC4vdW1heC5oDQotLS0gLi91bWF4
LmgJVHVlIEp1bCAyMSAwNDo1NToyMCAxOTk4DQorKysgLi91bWF4LmgJU2F0IEF1ZyAgMSAxNjo1
MDo1NiAxOTk4DQpAQCAtMzk0LDYgKzM5NCw3IEBADQogICBTQU5FX1BhcmFtZXRlcnMJCXBhcmFt
czsNCiANCiAgIHBpZF90CQkJCXJlYWRlcl9waWQ7DQorICBpbnQgIAkJCQlyZWFkZXJfZmRzOw0K
ICAgaW50CQkJCXBpcGU7DQogfSBVbWF4X1NjYW5uZXI7DQogDQo=

--_=_=_=IMA.BOUNDARY.EX1BDI138764=_=_=_--

--
Source code, list archive, and docs: http://www.mostang.com/sane/
To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com