mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
queue_signalled: pthread attributes only need to exist during initialisation of their belonging objects
See: http://stackoverflow.com/questions/11062292/are-pthread-attribute-objects-required-to-exist-for-the-lifetime-of-the-object-t
This commit is contained in:
parent
d8d9f00ee6
commit
bb547ffaf8
2 changed files with 14 additions and 8 deletions
|
@ -15,9 +15,7 @@
|
|||
struct queue_signalled {
|
||||
struct queue q; /**< Actual underlying queue. */
|
||||
pthread_cond_t ready; /**< Condition variable to signal writes to the queue. */
|
||||
pthread_condattr_t readyattr;
|
||||
pthread_mutex_t mt; /**< Mutex for ready. */
|
||||
pthread_mutexattr_t mtattr;
|
||||
};
|
||||
|
||||
int queue_signalled_init(struct queue_signalled *qs, size_t size, struct memtype *mem);
|
||||
|
|
|
@ -12,15 +12,23 @@ int queue_signalled_init(struct queue_signalled *qs, size_t size, struct memtype
|
|||
int ret;
|
||||
|
||||
ret = queue_init(&qs->q, size, mem);
|
||||
|
||||
pthread_condattr_t cvattr;
|
||||
pthread_mutexattr_t mtattr;
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
pthread_mutexattr_init(&qs->mtattr);
|
||||
pthread_mutexattr_setpshared(&qs->mtattr, PTHREAD_PROCESS_SHARED);
|
||||
pthread_condattr_init(&qs->readyattr);
|
||||
pthread_condattr_setpshared(&qs->readyattr, PTHREAD_PROCESS_SHARED);
|
||||
pthread_mutex_init(&qs->mt, &qs->mtattr);
|
||||
pthread_cond_init(&qs->ready, &qs->readyattr);
|
||||
pthread_mutexattr_init(&mtattr);
|
||||
pthread_condattr_init(&cvattr);
|
||||
|
||||
pthread_mutexattr_setpshared(&mtattr, PTHREAD_PROCESS_SHARED);
|
||||
pthread_condattr_setpshared(&cvattr, PTHREAD_PROCESS_SHARED);
|
||||
|
||||
pthread_mutex_init(&qs->mutex, &mtattr);
|
||||
pthread_cond_init(&qs->ready, &cvattr);
|
||||
|
||||
pthread_mutexattr_destroy(&mtattr);
|
||||
pthread_condattr_destroy(&cvattr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue