Remove a few unused opr/util components

A few pieces of opr and util have no callers, have never been used
since they were added, and are not expected to be used in the near
future. Remove the unused code; if we ever want to use any of this
again, it can be re-added when we actually need it.

Specifically, this removes:

- 'stoupper' in src/opr/casestrcpy.c, added in e117599f
  (fileserver-hates-pruclient-20060626)

- 'opr_ffsll' and 'opr_flsll' in src/opr/ffs.h, added in d4369917
  (opr: implement the BSD ffs() functions)

- src/util/thread_pool.c and related headers, added in 4ca57f3f
  (Provide an abstract thread pool object)

Change-Id: Id098cb86318ac9e2412937f4b63b5d99e35be568
Reviewed-on: https://gerrit.openafs.org/14547
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
This commit is contained in:
Andrew Deason 2021-03-03 12:24:27 -06:00 committed by Benjamin Kaduk
parent fd5aa52ef8
commit 926c026db8
11 changed files with 0 additions and 697 deletions

View File

@ -66,17 +66,6 @@ stolower(char *s)
return;
}
void
stoupper(char *s)
{
while (*s) {
if (islower(*s))
*s = toupper(*s);
s++;
}
return;
}
/* strcompose - concatenate strings passed to it.
* Input:
* buf: storage for the composed string. Any data in it will be lost.

View File

@ -55,25 +55,6 @@ opr_ffs(int value)
/* NOTREACHED */
}
static_inline int
opr_ffsll(long long value)
{
afs_int32 i;
afs_uint64 tmp = value;
if (tmp == 0)
return 0;
/* This loop must terminate because tmp is nonzero and thus has at least
* one bit set. */
for (i = 1;; ++i) {
if (tmp & 1ull)
return i;
else
tmp >>= 1;
}
/* NOTREACHED */
}
static_inline int
opr_fls(int value)
{
@ -94,24 +75,4 @@ opr_fls(int value)
/* NOTREACHED */
}
static_inline int
opr_flsll(long long value)
{
afs_int32 i;
/* tmp must be unsigned to avoid undefined behavior. */
afs_uint64 tmp = value;
if (tmp == 0)
return 0;
/* This loop must terminate because tmp is nonzero and thus has at least
* one bit set. */
for (i = 64;; --i) {
if (tmp & 0x8000000000000000ull)
return i;
else
tmp <<= 1;
}
/* NOTREACHED */
}
#endif /* OPENAFS_OPR_FFS_H */

View File

@ -12,7 +12,6 @@ opr_rbtree_remove
opr_rbtree_replace
opr_rbtree_replace
opr_stolower
opr_stoupper
opr_strcompose
opr_threadname_set
opr_ucstring

View File

@ -64,14 +64,12 @@ extern void opr_AssertionFailed(const char *, int) AFS_NORETURN;
#define lcstring opr_lcstring
#define ucstring opr_ucstring
#define stolower opr_stolower
#define stoupper opr_stoupper
/* XXX str* is in the implementation namespace when <string.h> is included */
#define strcompose opr_strcompose
extern char *opr_lcstring(char *d, const char *s, int n) AFS_NONNULL((1,2));
extern char *opr_ucstring(char *d, const char *s, int n) AFS_NONNULL((1,2));
extern void opr_stolower(char *s) AFS_NONNULL((1));
extern void opr_stoupper(char *s) AFS_NONNULL((1));
extern char *opr_strcompose(char *buf, size_t len, ...) AFS_NONNULL((1));
/* threadname.c */

View File

@ -38,8 +38,6 @@ includes = \
${TOP_INCDIR}/afs/afs_lhash.h \
${TOP_INCDIR}/afs/work_queue.h \
${TOP_INCDIR}/afs/work_queue_types.h \
${TOP_INCDIR}/afs/thread_pool.h \
${TOP_INCDIR}/afs/thread_pool_types.h \
${TOP_INCDIR}/afs/tabular_output.h
all: ${includes} \
@ -106,12 +104,6 @@ ${TOP_INCDIR}/afs/work_queue.h: ${srcdir}/work_queue.h
${TOP_INCDIR}/afs/work_queue_types.h: ${srcdir}/work_queue_types.h
${INSTALL_DATA} $? $@
${TOP_INCDIR}/afs/thread_pool.h: ${srcdir}/thread_pool.h
${INSTALL_DATA} $? $@
${TOP_INCDIR}/afs/thread_pool_types.h: ${srcdir}/thread_pool_types.h
${INSTALL_DATA} $? $@
${TOP_INCDIR}/afs/tabular_output.h: ${srcdir}/tabular_output.h
${INSTALL_DATA} $? $@
@ -172,8 +164,6 @@ install: dirpath.h util.a sys
${INSTALL_DATA} ${srcdir}/afs_lhash.h ${DESTDIR}${includedir}/afs/afs_lhash.h
${INSTALL_DATA} ${srcdir}/work_queue.h ${DESTDIR}${includedir}/afs/work_queue.h
${INSTALL_DATA} ${srcdir}/work_queue_types.h ${DESTDIR}${includedir}/afs/work_queue_types.h
${INSTALL_DATA} ${srcdir}/thread_pool.h ${DESTDIR}${includedir}/afs/thread_pool.h
${INSTALL_DATA} ${srcdir}/thread_pool_types.h ${DESTDIR}${includedir}/afs/thread_pool_types.h
${INSTALL_DATA} ${srcdir}/tabular_output.h ${DESTDIR}${includedir}/afs/tabular_output.h
${INSTALL_DATA} util.a ${DESTDIR}${libdir}/afs/util.a
${INSTALL_DATA} util.a ${DESTDIR}${libdir}/afs/libafsutil.a
@ -196,8 +186,6 @@ dest: dirpath.h util.a sys
${INSTALL_DATA} ${srcdir}/afs_lhash.h ${DEST}/include/afs/afs_lhash.h
${INSTALL_DATA} ${srcdir}/work_queue.h ${DEST}/include/afs/work_queue.h
${INSTALL_DATA} ${srcdir}/work_queue_types.h ${DEST}/include/afs/work_queue_types.h
${INSTALL_DATA} ${srcdir}/thread_pool.h ${DEST}/include/afs/thread_pool.h
${INSTALL_DATA} ${srcdir}/thread_pool_types.h ${DEST}/include/afs/thread_pool_types.h
${INSTALL_DATA} ${srcdir}/tabular_output.h ${DEST}/include/afs/tabular_output.h
${INSTALL_DATA} util.a ${DEST}/lib/afs/util.a
${INSTALL_DATA} util.a ${DEST}/lib/afs/libafsutil.a

View File

@ -1,472 +0,0 @@
/*
* Copyright 2008-2010, Sine Nomine Associates and others.
* All Rights Reserved.
*
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
*/
#include <afsconfig.h>
#include <afs/param.h>
#include <roken.h>
#include <afs/opr.h>
#include <lock.h>
#include <afs/afsutil.h>
#include <lwp.h>
#include <afs/afsint.h>
#define __AFS_THREAD_POOL_IMPL 1
#include "work_queue.h"
#include "thread_pool.h"
#include "thread_pool_impl.h"
/**
* public interfaces for thread_pool.
*/
/**
* allocate a thread pool object.
*
* @param[inout] pool_out address in which to store pool object pointer
*
* @return operation status
* @retval 0 success
* @retval ENOMEM out of memory
*
* @internal
*/
static int
_afs_tp_alloc(struct afs_thread_pool ** pool_out)
{
int ret = 0;
struct afs_thread_pool * pool;
*pool_out = pool = malloc(sizeof(*pool));
if (pool == NULL) {
ret = ENOMEM;
goto error;
}
error:
return ret;
}
/**
* free a thread pool object.
*
* @param[in] pool thread pool object
*
* @return operation status
* @retval 0 success
*
* @internal
*/
static int
_afs_tp_free(struct afs_thread_pool * pool)
{
int ret = 0;
free(pool);
return ret;
}
/**
* allocate a thread worker object.
*
* @param[inout] worker_out address in which to store worker object pointer
*
* @return operation status
* @retval 0 success
* @retval ENOMEM out of memory
*
* @internal
*/
static int
_afs_tp_worker_alloc(struct afs_thread_pool_worker ** worker_out)
{
int ret = 0;
struct afs_thread_pool_worker * worker;
*worker_out = worker = malloc(sizeof(*worker));
if (worker == NULL) {
ret = ENOMEM;
goto error;
}
queue_NodeInit(&worker->worker_list);
error:
return ret;
}
/**
* free a thread worker object.
*
* @param[in] worker thread worker object
*
* @return operation status
* @retval 0 success
*
* @internal
*/
static int
_afs_tp_worker_free(struct afs_thread_pool_worker * worker)
{
int ret = 0;
free(worker);
return ret;
}
/**
* low-level thread entry point.
*
* @param[in] rock opaque pointer to thread worker object
*
* @return opaque return pointer from pool entry function
*
* @internal
*/
static void *
_afs_tp_worker_run(void * rock)
{
struct afs_thread_pool_worker * worker = rock;
struct afs_thread_pool * pool = worker->pool;
/* register worker with pool */
opr_mutex_enter(&pool->lock);
queue_Append(&pool->thread_list, worker);
pool->nthreads++;
opr_mutex_exit(&pool->lock);
/* call high-level entry point */
worker->ret = (*pool->entry)(pool, worker, pool->work_queue, pool->rock);
/* adjust pool live thread count */
opr_mutex_enter(&pool->lock);
opr_Assert(pool->nthreads);
queue_Remove(worker);
pool->nthreads--;
if (!pool->nthreads) {
opr_cv_broadcast(&pool->shutdown_cv);
pool->state = AFS_TP_STATE_STOPPED;
}
opr_mutex_exit(&pool->lock);
_afs_tp_worker_free(worker);
return NULL;
}
/**
* default high-level thread entry point.
*
* @internal
*/
static void *
_afs_tp_worker_default(struct afs_thread_pool *pool,
struct afs_thread_pool_worker *worker,
struct afs_work_queue *queue,
void *rock)
{
int code = 0;
while (code == 0 && afs_tp_worker_continue(worker)) {
code = afs_wq_do(queue, NULL /* no call rock */);
}
return NULL;
}
/**
* start a worker thread.
*
* @param[in] pool thread pool object
* @param[inout] worker_out address in which to store worker thread object pointer
*
* @return operation status
* @retval 0 success
* @retval ENOMEM out of memory
*/
static int
_afs_tp_worker_start(struct afs_thread_pool * pool,
struct afs_thread_pool_worker ** worker_out)
{
int ret = 0;
pthread_attr_t attrs;
struct afs_thread_pool_worker * worker;
ret = _afs_tp_worker_alloc(worker_out);
if (ret) {
goto error;
}
worker = *worker_out;
worker->pool = pool;
worker->req_shutdown = 0;
opr_Verify(pthread_attr_init(&attrs) == 0);
opr_Verify(pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED) == 0);
ret = pthread_create(&worker->tid, &attrs, &_afs_tp_worker_run, worker);
error:
return ret;
}
/**
* create a thread pool.
*
* @param[inout] pool_out address in which to store pool object pointer.
* @param[in] queue work queue serviced by thread pool
*
* @return operation status
* @retval 0 success
* @retval ENOMEM out of memory
*/
int
afs_tp_create(struct afs_thread_pool ** pool_out,
struct afs_work_queue * queue)
{
int ret = 0;
struct afs_thread_pool * pool;
ret = _afs_tp_alloc(pool_out);
if (ret) {
goto error;
}
pool = *pool_out;
opr_mutex_init(&pool->lock);
opr_cv_init(&pool->shutdown_cv);
queue_Init(&pool->thread_list);
pool->work_queue = queue;
pool->entry = &_afs_tp_worker_default;
pool->rock = NULL;
pool->nthreads = 0;
pool->max_threads = 4;
pool->state = AFS_TP_STATE_INIT;
error:
return ret;
}
/**
* destroy a thread pool.
*
* @param[in] pool thread pool object to be destroyed
*
* @return operation status
* @retval 0 success
* @retval AFS_TP_ERROR pool not in a quiescent state
*/
int
afs_tp_destroy(struct afs_thread_pool * pool)
{
int ret = 0;
opr_mutex_enter(&pool->lock);
switch (pool->state) {
case AFS_TP_STATE_INIT:
case AFS_TP_STATE_STOPPED:
_afs_tp_free(pool);
break;
default:
ret = AFS_TP_ERROR;
opr_mutex_exit(&pool->lock);
}
return ret;
}
/**
* set the number of threads to spawn.
*
* @param[in] pool thread pool object
* @param[in] threads number of threads to spawn
*
* @return operation status
* @retval 0 success
* @retval AFS_TP_ERROR thread pool has already been started
*/
int
afs_tp_set_threads(struct afs_thread_pool *pool,
afs_uint32 threads)
{
int ret = 0;
opr_mutex_enter(&pool->lock);
if (pool->state != AFS_TP_STATE_INIT) {
ret = AFS_TP_ERROR;
} else {
pool->max_threads = threads;
}
opr_mutex_exit(&pool->lock);
return ret;
}
/**
* set a custom thread entry point.
*
* @param[in] pool thread pool object
* @param[in] entry thread entry function pointer
* @param[in] rock opaque pointer passed to thread
*
* @return operation status
* @retval 0 success
* @retval AFS_TP_ERROR thread pool has already been started
*/
int
afs_tp_set_entry(struct afs_thread_pool * pool,
afs_tp_worker_func_t * entry,
void * rock)
{
int ret = 0;
opr_mutex_enter(&pool->lock);
if (pool->state != AFS_TP_STATE_INIT) {
ret = AFS_TP_ERROR;
} else {
pool->entry = entry;
pool->rock = rock;
}
opr_mutex_exit(&pool->lock);
return ret;
}
/**
* start a thread pool.
*
* @param[in] pool thread pool object
*
* @return operation status
* @retval 0 success
* @retval AFS_TP_ERROR thread create failure
*/
int
afs_tp_start(struct afs_thread_pool * pool)
{
int code, ret = 0;
struct afs_thread_pool_worker * worker;
afs_uint32 i;
opr_mutex_enter(&pool->lock);
if (pool->state != AFS_TP_STATE_INIT) {
ret = AFS_TP_ERROR;
goto done_sync;
}
pool->state = AFS_TP_STATE_STARTING;
opr_mutex_exit(&pool->lock);
for (i = 0; i < pool->max_threads; i++) {
code = _afs_tp_worker_start(pool, &worker);
if (code) {
ret = code;
}
}
opr_mutex_enter(&pool->lock);
pool->state = AFS_TP_STATE_RUNNING;
done_sync:
opr_mutex_exit(&pool->lock);
return ret;
}
/**
* shut down all threads in pool.
*
* @param[in] pool thread pool object
* @param[in] block wait for all threads to terminate, if asserted
*
* @return operation status
* @retval 0 success
*/
int
afs_tp_shutdown(struct afs_thread_pool * pool,
int block)
{
int ret = 0;
struct afs_thread_pool_worker * worker, *nn;
opr_mutex_enter(&pool->lock);
if (pool->state == AFS_TP_STATE_STOPPED
|| pool->state == AFS_TP_STATE_STOPPING) {
goto done_stopped;
}
if (pool->state != AFS_TP_STATE_RUNNING) {
ret = AFS_TP_ERROR;
goto done_sync;
}
pool->state = AFS_TP_STATE_STOPPING;
for (queue_Scan(&pool->thread_list, worker, nn, afs_thread_pool_worker)) {
worker->req_shutdown = 1;
}
if (!pool->nthreads) {
pool->state = AFS_TP_STATE_STOPPED;
}
/* need to drop lock to get a membar here */
opr_mutex_exit(&pool->lock);
ret = afs_wq_shutdown(pool->work_queue);
if (ret) {
goto error;
}
opr_mutex_enter(&pool->lock);
done_stopped:
if (block) {
while (pool->nthreads) {
opr_cv_wait(&pool->shutdown_cv, &pool->lock);
}
}
done_sync:
opr_mutex_exit(&pool->lock);
error:
return ret;
}
/**
* check whether thread pool is online.
*
* @param[in] pool thread pool object
*
* @return whether pool is online
* @retval 1 pool is online
* @retval 0 pool is not online
*/
int
afs_tp_is_online(struct afs_thread_pool * pool)
{
int ret;
opr_mutex_enter(&pool->lock);
ret = (pool->state == AFS_TP_STATE_RUNNING);
opr_mutex_exit(&pool->lock);
return ret;
}
/**
* check whether a given worker thread can continue to run.
*
* @param[in] worker worker thread object pointer
*
* @return whether thread can continue to execute
* @retval 1 execution can continue
* @retval 0 shutdown has been requested
*/
int
afs_tp_worker_continue(struct afs_thread_pool_worker * worker)
{
return !worker->req_shutdown;
}

View File

@ -1,38 +0,0 @@
/*
* Copyright 2008-2010, Sine Nomine Associates and others.
* All Rights Reserved.
*
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
*/
#ifndef AFS_UTIL_THREAD_POOL_H
#define AFS_UTIL_THREAD_POOL_H 1
#include "thread_pool_types.h"
/**
* public interfaces for thread_pool.
*/
/* XXX move these into an et */
#define AFS_TP_ERROR -1 /**< fatal error in thread_pool package */
extern int afs_tp_create(struct afs_thread_pool **,
struct afs_work_queue *);
extern int afs_tp_destroy(struct afs_thread_pool *);
extern int afs_tp_set_threads(struct afs_thread_pool *, afs_uint32 threads);
extern int afs_tp_set_entry(struct afs_thread_pool *,
afs_tp_worker_func_t *,
void * rock);
extern int afs_tp_start(struct afs_thread_pool *);
extern int afs_tp_shutdown(struct afs_thread_pool *,
int block);
extern int afs_tp_is_online(struct afs_thread_pool *);
extern int afs_tp_worker_continue(struct afs_thread_pool_worker *);
#endif /* AFS_UTIL_THREAD_POOL_H */

View File

@ -1,20 +0,0 @@
/*
* Copyright 2008-2010, Sine Nomine Associates and others.
* All Rights Reserved.
*
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
*/
#ifndef AFS_UTIL_THREAD_POOL_IMPL_H
#define AFS_UTIL_THREAD_POOL_IMPL_H 1
#include "thread_pool.h"
#include "thread_pool_impl_types.h"
/**
* implementation-private interfaces for thread_pool.
*/
#endif /* AFS_UTIL_THREAD_POOL_IMPL_H */

View File

@ -1,64 +0,0 @@
/*
* Copyright 2008-2010, Sine Nomine Associates and others.
* All Rights Reserved.
*
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
*/
#ifndef AFS_UTIL_THREAD_POOL_IMPL_TYPES_H
#define AFS_UTIL_THREAD_POOL_IMPL_TYPES_H 1
#ifndef __AFS_THREAD_POOL_IMPL
#error "do not include this file outside of the thread pool implementation"
#endif
#include "thread_pool_types.h"
#include <rx/rx_queue.h>
/**
*
* implementation-private type definitions for thread_pool.
*/
/**
* thread_pool worker state.
*/
typedef enum {
AFS_TP_STATE_INIT, /**< initial state */
AFS_TP_STATE_STARTING, /**< pool is starting up */
AFS_TP_STATE_RUNNING, /**< pool is running normally */
AFS_TP_STATE_STOPPING, /**< stop requested */
AFS_TP_STATE_STOPPED, /**< pool is shut down */
/* add new states above this line */
AFS_TP_STATE_TERMINAL
} afs_tp_state_t;
/**
* thread_pool worker.
*/
struct afs_thread_pool_worker {
struct rx_queue worker_list; /**< linked list of thread workers. */
struct afs_thread_pool * pool; /**< associated thread pool */
void * ret; /**< return value from worker thread entry point */
pthread_t tid; /**< thread id */
int req_shutdown; /**< request shutdown of this thread */
};
/**
* thread pool.
*/
struct afs_thread_pool {
struct rx_queue thread_list; /**< linked list of threads */
struct afs_work_queue * work_queue; /**< work queue serviced by this thread pool. */
afs_tp_worker_func_t * entry; /**< worker thread entry point */
void * rock; /**< opaque pointer passed to worker thread entry point */
afs_uint32 nthreads; /**< current pool size */
afs_tp_state_t state; /**< pool state */
afs_uint32 max_threads; /**< pool options */
pthread_mutex_t lock; /**< pool global state lock */
pthread_cond_t shutdown_cv; /**< thread shutdown cv */
};
#endif /* AFS_UTIL_THREAD_POOL_IMPL_TYPES_H */

View File

@ -1,37 +0,0 @@
/*
* Copyright 2008-2010, Sine Nomine Associates and others.
* All Rights Reserved.
*
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
*/
#ifndef AFS_UTIL_THREAD_POOL_TYPES_H
#define AFS_UTIL_THREAD_POOL_TYPES_H 1
/**
* public type definitions for thread_pool.
*/
/* forward declare opaque types */
struct afs_thread_pool_worker;
struct afs_thread_pool;
struct afs_work_queue;
/**
* thread_pool worker thread entry function.
*
* @param[in] pool thread pool object pointer
* @param[in] worker worker thread object pointer
* @param[in] queue work queue object pointer
* @param[in] rock opaque pointer
*
* @return opaque pointer
*/
typedef void * afs_tp_worker_func_t(struct afs_thread_pool * pool,
struct afs_thread_pool_worker * worker,
struct afs_work_queue * queue,
void * rock);
#endif /* AFS_UTIL_THREAD_POOL_TYPES_H */

View File

@ -64,7 +64,6 @@
#ifdef AFS_SALSRV_ENV
#include <pthread.h>
#include <afs/work_queue.h>
#include <afs/thread_pool.h>
#include <vol/vol-salvage.h>
#endif