You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rb...@hyperreal.org on 1999/05/10 19:53:05 UTC
cvs commit: apache-apr/apr/threadproc/unix thread.c threadcancel.c threadpriv.c
rbb 99/05/10 10:53:04
Added: apr/threadproc/unix thread.c threadcancel.c threadpriv.c
Log:
First pass at the threading stuff.
Revision Changes Path
1.1 apache-apr/apr/threadproc/unix/thread.c
Index: thread.c
===================================================================
/* ====================================================================
* Copyright (c) 1999 The Apache Group. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* 4. The names "Apache Server" and "Apache Group" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Group.
* For more information on the Apache Group and the Apache HTTP server
* project, please see <http://www.apache.org/>.
*
*/
#include "apr_thread_proc.h"
#include "apr_general.h"
ap_threadattr_t *ap_create_threadattr(ap_context_t *cont)
{
ap_threadattr_t *new;
new = (ap_threadattr_t *)ap_palloc(cont->pool, sizeof(ap_threadattr_t));
new->attr = (pthread_attr_t *)ap_palloc(cont->pool, sizeof(pthread_attr_t));
pthread_attr_init(new->attr);
}
ap_status_t ap_setthreadattr_detach(ap_context_t *cont, ap_threadattr_t *attr, ap_int32_t on)
{
if (pthread_attr_setdetachstate(attr->attr, on) == 0) {
return APR_SUCCESS;
}
else {
return APR_FAILURE;
}
}
ap_status_t ap_getthreadattr_detach(ap_context_t *cont, ap_threadattr_t *attr)
{
int state;
pthread_attr_getdetachstate(attr->attr, &state);
if (state == 1)
return APR_SUCCESS;
return APR_FAILURE;
}
ap_thread_t *ap_create_thread(ap_context_t *cont, ap_threadattr_t *attr, ap_thread_start_t func, void *data)
{
ap_thread_t *new;
new = (ap_thread_t *)ap_palloc(cont->pool, sizeof(ap_thread_t));
if (pthread_create(new->td, attr->attr, func, data) == 0) {
return new;
}
else {
return NULL;
}
}
void ap_thread_exit(ap_context_t *cont, ap_status_t *retval)
{
pthread_exit(retval);
}
ap_status_t ap_thread_join(ap_context_t *cont, ap_thread_t *thd, ap_status_t *retval)
{
if (pthread_join(*thd->td,(void *)&retval) == 0) {
return APR_SUCCESS;
}
else {
return APR_FAILURE;
}
}
ap_status_t ap_thread_detach(ap_context_t *cont, ap_thread_t *thd)
{
if (pthread_detach(*thd->td) == 0) {
return APR_SUCCESS;
}
else {
return APR_FAILURE;
}
}
1.1 apache-apr/apr/threadproc/unix/threadcancel.c
Index: threadcancel.c
===================================================================
/* ====================================================================
* Copyright (c) 1999 The Apache Group. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* 4. The names "Apache Server" and "Apache Group" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Group.
* For more information on the Apache Group and the Apache HTTP server
* project, please see <http://www.apache.org/>.
*
*/
#include "apr_thread_proc.h"
#include "apr_general.h"
ap_status_t ap_cancel_thread(ap_context_t *cont, ap_thread_t *thd)
{
if (pthread_cancel(*thd->td) == 0) {
return APR_SUCCESS;
}
else {
return APR_FAILURE;
}
}
ap_status_t ap_setcanceltype(ap_context_t *cont, ap_int32_t type)
{
if (pthread_setcanceltype(type, NULL) == 0) {
return APR_SUCCESS;
}
else {
return APR_FAILURE;
}
}
ap_status_t ap_setcancelstate(ap_context_t *cont, ap_int32_t type)
{
if (pthread_setcanceltype(type, NULL) == 0) {
return APR_SUCCESS;
}
else {
return APR_FAILURE;
}
}
1.1 apache-apr/apr/threadproc/unix/threadpriv.c
Index: threadpriv.c
===================================================================
/* ====================================================================
* Copyright (c) 1999 The Apache Group. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* 4. The names "Apache Server" and "Apache Group" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Group.
* For more information on the Apache Group and the Apache HTTP server
* project, please see <http://www.apache.org/>.
*
*/
#include "apr_thread_proc.h"
#include "apr_general.h"
#include "apr_errno.h"
ap_key_t *ap_create_thread_private(ap_context_t *cont, void (*dest)(void *))
{
ap_key_t *key;
key = (ap_key_t *)ap_palloc(cont->pool, sizeof(ap_key_t));
if (pthread_key_create(key, dest) == 0) {
return key;
}
return NULL;
}
void *ap_get_thread_private(ap_context_t *cont, ap_key_t key)
{
return pthread_getspecific(key);
}
ap_status_t ap_set_thread_private(ap_context_t *cont, ap_key_t key, void *priv)
{
if (pthread_setspecific(key, priv)== 0) {
return APR_SUCCESS;
}
else {
return APR_FAILURE;
}
}
ap_status_t ap_delete_thread_private(ap_context_t *cont, ap_key_t key)
{
if (pthread_key_delete(key) == 0) {
return APR_SUCCESS;
}
return APR_FAILURE;
}