Annotation of embedaddon/strongswan/src/libstrongswan/processing/processor.h, revision 1.1
1.1 ! misho 1: /*
! 2: * Copyright (C) 2012 Tobias Brunner
! 3: * Copyright (C) 2005-2007 Martin Willi
! 4: * Copyright (C) 2005 Jan Hutter
! 5: * HSR Hochschule fuer Technik Rapperswil
! 6: *
! 7: * This program is free software; you can redistribute it and/or modify it
! 8: * under the terms of the GNU General Public License as published by the
! 9: * Free Software Foundation; either version 2 of the License, or (at your
! 10: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
! 11: *
! 12: * This program is distributed in the hope that it will be useful, but
! 13: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
! 14: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
! 15: * for more details.
! 16: */
! 17:
! 18: /**
! 19: * @defgroup processor processor
! 20: * @{ @ingroup processing
! 21: */
! 22:
! 23: #ifndef PROCESSOR_H_
! 24: #define PROCESSOR_H_
! 25:
! 26: #include <utils/utils.h>
! 27:
! 28: typedef struct processor_t processor_t;
! 29:
! 30: #include <stdlib.h>
! 31:
! 32: #include <library.h>
! 33: #include <processing/jobs/job.h>
! 34:
! 35: /**
! 36: * The processor uses threads to process queued jobs.
! 37: */
! 38: struct processor_t {
! 39:
! 40: /**
! 41: * Get the total number of threads used by the processor.
! 42: *
! 43: * @return size of thread pool
! 44: */
! 45: u_int (*get_total_threads) (processor_t *this);
! 46:
! 47: /**
! 48: * Get the number of threads currently waiting for work.
! 49: *
! 50: * @return number of idle threads
! 51: */
! 52: u_int (*get_idle_threads) (processor_t *this);
! 53:
! 54: /**
! 55: * Get the number of threads currently working, per priority class.
! 56: *
! 57: * @param priority to check
! 58: * @return number of threads in priority working
! 59: */
! 60: u_int (*get_working_threads)(processor_t *this, job_priority_t prio);
! 61:
! 62: /**
! 63: * Get the number of queued jobs for a specified priority.
! 64: *
! 65: * @param prio priority class to get job load for
! 66: * @return number of items in queue
! 67: */
! 68: u_int (*get_job_load) (processor_t *this, job_priority_t prio);
! 69:
! 70: /**
! 71: * Adds a job to the queue.
! 72: *
! 73: * This function is non blocking and adds a job_t to the queue.
! 74: *
! 75: * @param job job to add to the queue
! 76: */
! 77: void (*queue_job) (processor_t *this, job_t *job);
! 78:
! 79: /**
! 80: * Directly execute a job with an idle worker thread.
! 81: *
! 82: * If no idle thread is available, the job gets executed by the calling
! 83: * thread.
! 84: *
! 85: * @param job job, gets destroyed
! 86: */
! 87: void (*execute_job)(processor_t *this, job_t *job);
! 88:
! 89: /**
! 90: * Set the number of threads to use in the processor.
! 91: *
! 92: * If the number of threads is smaller than number of currently running
! 93: * threads, thread count is decreased. Use 0 to disable the processor.
! 94: *
! 95: * This call does not block and wait for threads to terminate if the number
! 96: * of threads is reduced. Instead use cancel() for that during shutdown.
! 97: *
! 98: * @param count number of threads to allocate
! 99: */
! 100: void (*set_threads)(processor_t *this, u_int count);
! 101:
! 102: /**
! 103: * Sets the number of threads to 0 and cancels all blocking jobs, then waits
! 104: * for all threads to be terminated.
! 105: */
! 106: void (*cancel)(processor_t *this);
! 107:
! 108: /**
! 109: * Destroy a processor object.
! 110: */
! 111: void (*destroy) (processor_t *processor);
! 112: };
! 113:
! 114: /**
! 115: * Create the thread pool without any threads.
! 116: *
! 117: * Use the set_threads method to start processing jobs.
! 118: *
! 119: * @return processor_t object
! 120: */
! 121: processor_t *processor_create();
! 122:
! 123: #endif /** PROCESSOR_H_ @}*/
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>