Commit 138d22b3 authored by Bob Halley's avatar Bob Halley
Browse files

update

parent 0dbe3d9c
#ifndef BOOLEAN_H
#define BOOLEAN_H 1
#ifndef SOLARIS
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
typedef enum { false=FALSE, true=TRUE } boolean_t;
#else
#define true B_TRUE
#define false B_FALSE
#endif
#endif /* BOOLEAN_H */
/*
* Copyright (c) 1997, 1998 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#ifndef MEMCLUSTER_H
#define MEMCLUSTER_H 1
#include <stdio.h>
#include <stddef.h>
typedef struct mem_context * mem_context_t;
#define mem_context_create __mem_context_create
#define mem_context_destroy __mem_context_destroy
#ifdef MEMCLUSTER_DEBUG
#define mem_get(c, s) __mem_get_debug(c, s, __FILE__, __LINE__)
#define mem_put(c, p, s) __mem_put_debug(c, p, s, __FILE__, __LINE__)
#else
#define mem_get __mem_get
#define mem_put __mem_put
#endif
#define mem_valid __mem_valid
#define mem_stats __mem_stats
#define mem_allocate __mem_allocate
#define mem_free __mem_free
int mem_context_create(size_t, size_t,
mem_context_t *);
void mem_context_destroy(mem_context_t *);
void * __mem_get(mem_context_t, size_t);
void __mem_put(mem_context_t, void *, size_t);
void * __mem_get_debug(mem_context_t, size_t,
const char *, int);
void __mem_put_debug(mem_context_t, void *, size_t,
const char *, int);
int mem_valid(mem_context_t, void *);
void mem_stats(mem_context_t, FILE *);
void * mem_allocate(mem_context_t, size_t);
void mem_free(mem_context_t, void *);
/*
* Legacy.
*/
#define meminit __meminit
#define mem_default_context __mem_default_context
#ifdef MEMCLUSTER_DEBUG
#define memget(s) __memget_debug(s, __FILE__, __LINE__)
#define memput(p, s) __memput_debug(p, s, __FILE__, __LINE__)
#else
#define memget __memget
#define memput __memput
#endif
#define memvalid __memvalid
#define memstats __memstats
int meminit(size_t, size_t);
mem_context_t mem_default_context(void);
void * __memget(size_t);
void __memput(void *, size_t);
void * __memget_debug(size_t, const char *, int);
void __memput_debug(void *, size_t, const char *,
int);
int memvalid(void *);
void memstats(FILE *);
#endif /* MEMCLUSTER_H */
#ifndef TASK_H
#define TASK_H 1
#include <stddef.h>
#include <isc/list.h>
#include "memcluster.h"
#include "mutex.h"
#include "condition.h"
#include "boolean.h"
/***
*** Core Types.
***/
typedef struct generic_event * generic_event_t;
typedef struct task * task_t;
typedef struct task_manager * task_manager_t;
/***
*** Events.
***/
/*
* Negative event types are reserved for use by the task manager.
*/
typedef int event_type_t;
typedef boolean_t (*event_action_t)(task_t, void *,
generic_event_t);
/*
* Unlike other type names, which are prefixed with the module's name,
* event types have a suffix of "_event_t". All event types must start
* with the same fields as the generic event.
*/
struct generic_event {
mem_context_t mctx;
size_t size;
event_type_t type;
event_action_t action;
LINK(struct generic_event) link;
};
#define TASK_NOP_EVENT (-1)
typedef generic_event_t nop_event_t;
typedef LIST(struct generic_event) event_list_t;
void * event_get(mem_context_t,
event_type_t,
event_action_t,
size_t);
void event_put(void *);
/***
*** Tasks.
***/
typedef enum {
task_state_idle, task_state_ready, task_state_running,
task_state_shutdown
} task_state_t;
#define TASK_MAGIC 0x5441534BU /* TASK. */
struct task {
/* Not locked. */
unsigned int magic;
struct task_manager * manager;
os_mutex_t lock;
/* Locked by task lock. */
task_state_t state;
unsigned int references;
event_list_t events;
unsigned int quantum;
boolean_t shutdown_pending;
event_action_t shutdown_action;
void * arg;
/* Locked by task manager lock. */
LINK(struct task) link;
LINK(struct task) ready_link;
};
boolean_t task_create(task_manager_t,
void *,
event_action_t,
unsigned int,
task_t *);
boolean_t task_attach(task_t, task_t *);
void task_detach(task_t *);
boolean_t task_send_event(task_t,
generic_event_t);
void task_shutdown(task_t);
void task_destroy(task_t *);
/***
*** Task Manager.
***/
#define TASK_MANAGER_MAGIC 0x54534B4DU /* TSKM. */
struct task_manager {
/* Not locked. */
unsigned int magic;
mem_context_t mctx;
os_mutex_t lock;
/* Locked by task manager lock. */
unsigned int default_quantum;
LIST(struct task) tasks;
LIST(struct task) ready_tasks;
os_condition_t work_available;
boolean_t exiting;
unsigned int workers;
os_condition_t no_workers;
};
unsigned int task_manager_create(mem_context_t,
unsigned int,
unsigned int,
task_manager_t *);
boolean_t task_manager_destroy(task_manager_t *);
#endif /* TASK_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment