sig.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "libaio.h"
#include <dlfcn.h>
int __sigio_pending = 0; /* count of pending SIGIO signals */
int _sigio_enabled = 0; /* set if SIGIO has a signal handler */
static sig_act_t next_sigaction;
int
{
int *aio_workerscnt;
void *(*func)(void *);
int error;
/*
* Put the new worker thread in the right queue.
*/
switch (mode) {
case AIOWRITE:
workers = &__workers_wr;
break;
case AIOREAD:
workers = &__workers_rd;
break;
case AIOSIGEV:
workers = &__workers_si;
}
return (-1);
if (rp) {
}
if (error) {
if (rp) {
}
return (-1);
}
(void) mutex_lock(&__aio_mutex);
(*aio_workerscnt)++;
*nextworker = aiowp;
} else {
}
(void) mutex_unlock(&__aio_mutex);
return (0);
}
void
{
}
void
{
aiowp->work_cancel_flg = 0;
}
/*
* resend a SIGIO signal that was sent while the
* __aio_mutex was locked.
*
* This function is called from _aio_unlock() when previously SIGIO was
* detected and deferred (signal caught).
* There could be several threads calling _aio_lock() - _aio_unlock() and
* therefore __aiosendsig() must make sure that "kill" is being called
* only one time here.
*
*/
void
__aiosendsig(void)
{
int send_sigio;
(void) mutex_lock(&__sigio_pendinglock);
__sigio_pending = 0;
(void) mutex_unlock(&__sigio_pendinglock);
if (send_sigio)
}
/*
* this is the low-level handler for SIGIO. the application
* handler will not be called if the signal is being blocked.
*/
static void
{
int blocked;
/*
* SIGIO signal is being blocked if either _sigio_masked
* or sigio_maskedcnt is set or if both these variables
* are clear and the _aio_mutex is locked. the last
* condition can only happen when _aio_mutex is being
* unlocked. this is a very small window where the mask
* is clear and the lock is about to be unlocked, however,
* it`s still set and so the signal should be defered.
* mutex_trylock() will be used now to check the ownership
* of the lock (instead of MUTEX_HELD). This is necessary because
* there is a window where the owner of the lock is deleted
* and the thread could become preempted. In that case MUTEX_HELD()
* will not detect the -still- ownership of the lock.
*/
if (mutex_trylock(&__aio_mutex) == 0)
(void) mutex_unlock(&__aio_mutex);
else
blocked = 1;
}
if (blocked) {
/*
* aio_lock() is supposed to be non re-entrant with
* respect to SIGIO signals. if a SIGIO signal
* interrupts a region of code locked by _aio_mutex
* the SIGIO signal should be deferred until this
* mutex is unlocked. a flag is set, sigio_pending,
* to indicate that a SIGIO signal is pending and
* should be resent to the process via a kill().
* The libaio handler must be reinstalled here, otherwise
* the disposition gets the default status and the
* next SIGIO signal would terminate the process.
*/
(void) mutex_lock(&__sigio_pendinglock);
__sigio_pending = 1;
(void) mutex_unlock(&__sigio_pendinglock);
} else {
/*
* call the real handler.
*/
}
}
void
{
struct aio_worker *aiowp;
_aiopanic("aiosigcancelhndlr, thr_getspecific()\n");
if (aiowp->work_cancel_flg)
}
}
int
{
if (next_sigaction == NULL)
/*
* Only interpose on SIGIO when it is given a disposition other
* than SIG_IGN, or SIG_DFL. Because SIGAIOCANCEL is SIGPROF,
* this signal always should be interposed on, so that SIGPROF
* can also be used by the application for profiling.
*/
if (oact) {
else
}
return (0);
_sigio_enabled = 0;
} else {
_sigio_enabled = 1;
}
return (-1);
}
} else {
return (-1);
}
}
return (0);
}
}