Module: xenomai-forge Branch: master Commit: a739260b1d94c0dd15df5f80ddd63d122f2c74ed URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=a739260b1d94c0dd15df5f80ddd63d122f2c74ed
Author: Philippe Gerum <r...@xenomai.org> Date: Wed Dec 14 19:00:44 2011 +0100 copperplate/syncobj: prevent concurrent locking while a deletion is pending --- include/copperplate/syncobj.h | 3 +++ lib/copperplate/syncobj.c | 9 +++++++++ 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/include/copperplate/syncobj.h b/include/copperplate/syncobj.h index 5112c02..e3f0b01 100644 --- a/include/copperplate/syncobj.h +++ b/include/copperplate/syncobj.h @@ -41,6 +41,8 @@ #define SYNCOBJ_BLOCK 0x1 #define SYNCOBJ_RESUME 0x2 +#define SYNCOBJ_MAGIC 0xf9f99f9f + struct threadobj; struct syncstate { @@ -63,6 +65,7 @@ struct syncobj_corespec { #endif /* CONFIG_XENO_MERCURY */ struct syncobj { + unsigned int magic; int flags; int release_count; struct list pend_list; diff --git a/lib/copperplate/syncobj.c b/lib/copperplate/syncobj.c index a70a7d2..c3323ea 100644 --- a/lib/copperplate/syncobj.c +++ b/lib/copperplate/syncobj.c @@ -223,6 +223,7 @@ void syncobj_init(struct syncobj *sobj, int flags, sobj->drain_count = 0; sobj->release_count = 0; sobj->finalizer = finalizer; + sobj->magic = SYNCOBJ_MAGIC; syncobj_init_corespec(sobj); } @@ -232,6 +233,13 @@ int syncobj_lock(struct syncobj *sobj, struct syncstate *syns) assert(threadobj_current() != NULL); + /* + * This magic prevents concurrent locking while a deletion is + * in progress, waiting for the release count to drop to zero. + */ + if (sobj->magic != SYNCOBJ_MAGIC) + return -EINVAL; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); ret = monitor_enter(sobj); @@ -561,6 +569,7 @@ int syncobj_destroy(struct syncobj *sobj, struct syncstate *syns) __syncobj_check_locked(sobj); + sobj->magic = ~SYNCOBJ_MAGIC; ret = syncobj_flush(sobj, SYNCOBJ_DELETED); if (ret == 0) { /* No thread awaken - we may dispose immediately. */ _______________________________________________ Xenomai-git mailing list Xenomai-git@gna.org https://mail.gna.org/listinfo/xenomai-git