summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2013-08-26 15:14:33 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2013-08-30 11:16:28 +0200
commit1215fd4d9426a59d568560e9a485628560363133 (patch)
tree1fa51c2c86080bdbf80d20386732f34f08e708be /cpukit/posix/src
parentsmptests/smpatomic08: Fix race conditions (diff)
downloadrtems-1215fd4d9426a59d568560e9a485628560363133.tar.bz2
sapi: SMP support for chains
Add ISR lock to chain control for proper SMP protection. Replace rtems_chain_extract() with rtems_chain_explicit_extract() and rtems_chain_insert() with rtems_chain_explicit_insert() on SMP configurations. Use rtems_chain_explicit_extract() and rtems_chain_explicit_insert() to provide SMP support.
Diffstat (limited to 'cpukit/posix/src')
-rw-r--r--cpukit/posix/src/aio_cancel.c18
-rw-r--r--cpukit/posix/src/aio_misc.c32
2 files changed, 29 insertions, 21 deletions
diff --git a/cpukit/posix/src/aio_cancel.c b/cpukit/posix/src/aio_cancel.c
index 561e2f8776..aec554eec8 100644
--- a/cpukit/posix/src/aio_cancel.c
+++ b/cpukit/posix/src/aio_cancel.c
@@ -26,6 +26,8 @@
int aio_cancel(int fildes, struct aiocb *aiocbp)
{
+ rtems_chain_control *idle_req_chain = &aio_request_queue.idle_req;
+ rtems_chain_control *work_req_chain = &aio_request_queue.work_req;
rtems_aio_request_chain *r_chain;
int result;
@@ -40,12 +42,12 @@ int aio_cancel(int fildes, struct aiocb *aiocbp)
if (aiocbp == NULL) {
AIO_printf ("Cancel all requests\n");
- r_chain = rtems_aio_search_fd (&aio_request_queue.work_req, fildes, 0);
+ r_chain = rtems_aio_search_fd (work_req_chain, fildes, 0);
if (r_chain == NULL) {
AIO_printf ("Request chain not on [WQ]\n");
- if (!rtems_chain_is_empty (&aio_request_queue.idle_req)) {
- r_chain = rtems_aio_search_fd (&aio_request_queue.idle_req, fildes, 0);
+ if (!rtems_chain_is_empty (idle_req_chain)) {
+ r_chain = rtems_aio_search_fd (idle_req_chain, fildes, 0);
if (r_chain == NULL) {
pthread_mutex_unlock(&aio_request_queue.mutex);
return AIO_ALLDONE;
@@ -53,7 +55,7 @@ int aio_cancel(int fildes, struct aiocb *aiocbp)
AIO_printf ("Request chain on [IQ]\n");
- rtems_chain_extract (&r_chain->next_fd);
+ rtems_chain_explicit_extract (idle_req_chain, &r_chain->next_fd);
rtems_aio_remove_fd (r_chain);
pthread_mutex_destroy (&r_chain->mutex);
pthread_cond_destroy (&r_chain->mutex);
@@ -70,7 +72,7 @@ int aio_cancel(int fildes, struct aiocb *aiocbp)
AIO_printf ("Request chain on [WQ]\n");
pthread_mutex_lock (&r_chain->mutex);
- rtems_chain_extract (&r_chain->next_fd);
+ rtems_chain_explicit_extract (work_req_chain, &r_chain->next_fd);
rtems_aio_remove_fd (r_chain);
pthread_mutex_unlock (&r_chain->mutex);
pthread_mutex_unlock (&aio_request_queue.mutex);
@@ -83,10 +85,10 @@ int aio_cancel(int fildes, struct aiocb *aiocbp)
rtems_set_errno_and_return_minus_one (EINVAL);
}
- r_chain = rtems_aio_search_fd (&aio_request_queue.work_req, fildes, 0);
+ r_chain = rtems_aio_search_fd (work_req_chain, fildes, 0);
if (r_chain == NULL) {
- if (!rtems_chain_is_empty (&aio_request_queue.idle_req)) {
- r_chain = rtems_aio_search_fd (&aio_request_queue.idle_req, fildes, 0);
+ if (!rtems_chain_is_empty (idle_req_chain)) {
+ r_chain = rtems_aio_search_fd (idle_req_chain, fildes, 0);
if (r_chain == NULL) {
pthread_mutex_unlock (&aio_request_queue.mutex);
rtems_set_errno_and_return_minus_one (EINVAL);
diff --git a/cpukit/posix/src/aio_misc.c b/cpukit/posix/src/aio_misc.c
index e4c40df84e..656ba41bab 100644
--- a/cpukit/posix/src/aio_misc.c
+++ b/cpukit/posix/src/aio_misc.c
@@ -120,7 +120,9 @@ rtems_aio_search_fd (rtems_chain_control *chain, int fildes, int create)
if (rtems_chain_is_empty (chain))
rtems_chain_prepend (chain, &r_chain->next_fd);
else
- rtems_chain_insert (rtems_chain_previous (node), &r_chain->next_fd);
+ rtems_chain_explicit_insert (chain,
+ rtems_chain_previous (node),
+ &r_chain->next_fd);
r_chain->new_fd = 1;
r_chain->fildes = fildes;
@@ -144,19 +146,22 @@ rtems_aio_search_fd (rtems_chain_control *chain, int fildes, int create)
static void
rtems_aio_move_to_work (rtems_aio_request_chain *r_chain)
{
+ rtems_chain_control *work_req_chain = &aio_request_queue.work_req;
rtems_aio_request_chain *temp;
rtems_chain_node *node;
-
- node = rtems_chain_first (&aio_request_queue.work_req);
+
+ node = rtems_chain_first (work_req_chain);
temp = (rtems_aio_request_chain *) node;
- while (temp->fildes < r_chain->fildes &&
- !rtems_chain_is_tail (&aio_request_queue.work_req, node)) {
+ while (temp->fildes < r_chain->fildes &&
+ !rtems_chain_is_tail (work_req_chain, node)) {
node = rtems_chain_next (node);
temp = (rtems_aio_request_chain *) node;
}
-
- rtems_chain_insert (rtems_chain_previous (node), &r_chain->next_fd);
+
+ rtems_chain_explicit_insert (work_req_chain,
+ rtems_chain_previous (node),
+ &r_chain->next_fd);
}
@@ -195,7 +200,7 @@ rtems_aio_insert_prio (rtems_chain_control *chain, rtems_aio_request *req)
prio = ((rtems_aio_request *) node)->aiocbp->aio_reqprio;
}
- rtems_chain_insert (node->previous, &req->next_prio);
+ rtems_chain_explicit_insert (chain, node->previous, &req->next_prio);
}
}
@@ -221,7 +226,7 @@ void rtems_aio_remove_fd (rtems_aio_request_chain *r_chain)
while (!rtems_chain_is_tail (chain, node))
{
- rtems_chain_extract (node);
+ rtems_chain_explicit_extract (chain, node);
rtems_aio_request *req = (rtems_aio_request *) node;
node = rtems_chain_next (node);
req->aiocbp->error_code = ECANCELED;
@@ -265,7 +270,7 @@ int rtems_aio_remove_req (rtems_chain_control *chain, struct aiocb *aiocbp)
return AIO_NOTCANCELED;
else
{
- rtems_chain_extract (node);
+ rtems_chain_explicit_extract (chain, node);
current->aiocbp->error_code = ECANCELED;
current->aiocbp->return_value = -1;
free (current);
@@ -440,7 +445,7 @@ rtems_aio_handle (void *arg)
param.sched_priority = req->priority;
pthread_setschedparam (pthread_self(), req->policy, &param);
- rtems_chain_extract (node);
+ rtems_chain_explicit_extract (chain, node);
pthread_mutex_unlock (&r_chain->mutex);
@@ -506,7 +511,8 @@ rtems_aio_handle (void *arg)
/* If no requests were added to the chain we delete the fd chain from
the queue and start working with idle fd chains */
if (result == ETIMEDOUT) {
- rtems_chain_extract (&r_chain->next_fd);
+ rtems_chain_explicit_extract (&aio_request_queue.work_req,
+ &r_chain->next_fd);
pthread_mutex_destroy (&r_chain->mutex);
pthread_cond_destroy (&r_chain->cond);
free (r_chain);
@@ -542,7 +548,7 @@ rtems_aio_handle (void *arg)
++aio_request_queue.active_threads;
node = rtems_chain_first (&aio_request_queue.idle_req);
- rtems_chain_extract (node);
+ rtems_chain_explicit_extract (&aio_request_queue.idle_req, node);
r_chain = (rtems_aio_request_chain *) node;
rtems_aio_move_to_work (r_chain);