Commit 0dbe3d9c authored by Bob Halley's avatar Bob Halley

checkpoint

parent 3a6202f1
#include "attribute.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
......@@ -7,8 +9,11 @@
#include "task.h"
/*ARGSUSED*/
boolean_t
my_callback(task_t task, void *arg, generic_event_t event) {
static boolean_t
my_callback(task_t __attribute__((unused)) task,
void *arg,
generic_event_t __attribute__((unused)) event)
{
int i, j;
char *name = arg;
......@@ -21,32 +26,17 @@ my_callback(task_t task, void *arg, generic_event_t event) {
}
/*ARGSUSED*/
boolean_t
my_shutdown(task_t task, void *arg, generic_event_t event) {
static boolean_t
my_shutdown(task_t __attribute__((unused)) task,
void *arg,
generic_event_t __attribute__((unused)) event)
{
char *name = arg;
printf("shutdown %s\n", name);
return (TRUE);
}
generic_event_t
event_allocate(mem_context_t mctx, event_type_t type, event_action_t action,
size_t size) {
generic_event_t event;
if (size < sizeof *event)
return (NULL);
event = mem_get(mctx, size);
if (event == NULL)
return (NULL);
event->mctx = mctx;
event->size = size;
event->type = type;
event->action = action;
return (event);
}
void
main(int argc, char *argv[]) {
mem_context_t mctx = NULL;
......@@ -65,23 +55,23 @@ main(int argc, char *argv[]) {
INSIST(task_manager_create(mctx, workers, 0, &manager) == workers);
INSIST(task_allocate(manager, "1", my_shutdown, 0, &t1));
INSIST(task_allocate(manager, "2", my_shutdown, 0, &t2));
event = event_allocate(mctx, 1, my_callback, sizeof *event);
INSIST(task_create(manager, "1", my_shutdown, 0, &t1));
INSIST(task_create(manager, "2", my_shutdown, 0, &t2));
event = event_get(mctx, 1, my_callback, sizeof *event);
task_send_event(t1, event);
event = event_allocate(mctx, 1, my_callback, sizeof *event);
event = event_get(mctx, 1, my_callback, sizeof *event);
task_send_event(t2, event);
event = event_allocate(mctx, 1, my_callback, sizeof *event);
event = event_get(mctx, 1, my_callback, sizeof *event);
task_send_event(t1, event);
event = event_allocate(mctx, 1, my_callback, sizeof *event);
event = event_get(mctx, 1, my_callback, sizeof *event);
task_send_event(t2, event);
event = event_allocate(mctx, 1, my_callback, sizeof *event);
event = event_get(mctx, 1, my_callback, sizeof *event);
task_send_event(t1, event);
event = event_allocate(mctx, 1, my_callback, sizeof *event);
event = event_get(mctx, 1, my_callback, sizeof *event);
task_send_event(t2, event);
event = event_allocate(mctx, 1, my_callback, sizeof *event);
event = event_get(mctx, 1, my_callback, sizeof *event);
task_send_event(t1, event);
event = event_allocate(mctx, 1, my_callback, sizeof *event);
event = event_get(mctx, 1, my_callback, sizeof *event);
task_send_event(t2, event);
task_shutdown(t1);
......
......@@ -15,8 +15,6 @@
* SOFTWARE.
*/
/* #include "port_before.h" */
#include <sys/types.h>
#include <stdio.h>
......@@ -30,10 +28,8 @@
#include "mutex.h"
#include "memcluster.h"
/* #include "port_after.h" */
#if !defined(LINT) && !defined(CODECENTER)
static char rcsid[] __attribute__((unused)) = "$Id: mem.c,v 1.1 1998/08/17 22:05:58 halley Exp $";
static char rcsid[] __attribute__((unused)) = "$Id: mem.c,v 1.2 1998/08/18 00:29:53 halley Exp $";
#endif /* not lint */
/*
......@@ -52,16 +48,16 @@ typedef struct {
} *size_info;
struct stats {
u_long gets;
u_long totalgets;
u_long blocks;
u_long freefrags;
unsigned long gets;
unsigned long totalgets;
unsigned long blocks;
unsigned long freefrags;
};
#ifdef MEMCLUSTER_RANGES
typedef struct range {
u_char * first;
u_char * last;
unsigned char * first;
unsigned char * last;
struct range * next;
} range;
#endif
......@@ -75,8 +71,8 @@ struct mem_context {
range * ranges;
range * freeranges;
#else
u_char * lowest;
u_char * highest;
unsigned char * lowest;
unsigned char * highest;
#endif
struct stats * stats;
os_mutex_t mutex;
......@@ -196,12 +192,12 @@ __mem_get(mem_context_t ctx, size_t size) {
int i, frags;
size_t total_size;
void *new;
u_char *curr, *next;
u_char *first;
unsigned char *curr, *next;
unsigned char *first;
#ifdef MEMCLUSTER_RANGES
range *r;
#else
u_char *last;
unsigned char *last;
#endif
if (ctx->basic_blocks == NULL) {
......@@ -340,7 +336,7 @@ __mem_get_debug(mem_context_t ctx, size_t size, const char *file, int line) {
void *ptr;
ptr = __mem_get(ctx, size);
fprintf(stderr, "%s:%d: mem_get(%p, %lu) -> %p\n", file, line,
ctx, (u_long)size, ptr);
ctx, (unsigned long)size, ptr);
return (ptr);
}
......@@ -349,7 +345,7 @@ __mem_put_debug(mem_context_t ctx, void *ptr, size_t size, const char *file,
int line)
{
fprintf(stderr, "%s:%d: mem_put(%p, %p, %lu)\n", file, line,
ctx, ptr, (u_long)size);
ctx, ptr, (unsigned long)size);
__mem_put(ctx, ptr, size);
}
......@@ -383,7 +379,7 @@ mem_stats(mem_context_t ctx, FILE *out) {
int
mem_valid(mem_context_t ctx, void *ptr) {
u_char *cp = ptr;
unsigned char *cp = ptr;
int ret;
#ifdef MEMCLUSTER_RANGES
range *r;
......@@ -475,14 +471,14 @@ __memget_debug(size_t size, const char *file, int line) {
void *ptr;
ptr = __memget(size);
fprintf(stderr, "%s:%d: memget(%lu) -> %p\n", file, line,
(u_long)size, ptr);
(unsigned long)size, ptr);
return (ptr);
}
void
__memput_debug(void *ptr, size_t size, const char *file, int line) {
fprintf(stderr, "%s:%d: memput(%p, %lu)\n", file, line,
ptr, (u_long)size);
ptr, (unsigned long)size);
__memput(ptr, size);
}
......
#include "attribute.h"
#include <isc/assertions.h>
#include "task.h"
......@@ -24,6 +26,37 @@
#define XTRACE(m)
#endif
/***
*** Tasks.
***/
void *
event_get(mem_context_t mctx, event_type_t type, event_action_t action,
size_t size) {
generic_event_t event;
if (size < sizeof *event)
return (NULL);
event = mem_get(mctx, size);
if (event == NULL)
return (NULL);
event->mctx = mctx;
event->size = size;
event->type = type;
event->action = action;
return (event);
}
void
event_put(void *target) {
generic_event_t event = target;
mem_put(event->mctx, event, event->size);
}
/***
*** Tasks.
***/
......@@ -53,9 +86,9 @@ task_free(task_t task) {
}
boolean_t
task_allocate(task_manager_t manager, void *arg,
event_action_t shutdown_action, unsigned int quantum,
task_t *taskp)
task_create(task_manager_t manager, void *arg,
event_action_t shutdown_action, unsigned int quantum,
task_t *taskp)
{
task_t task;
......@@ -105,7 +138,7 @@ task_attach(task_t task, task_t *taskp) {
return (TRUE);
}
boolean_t
void
task_detach(task_t *taskp) {
boolean_t free_task = FALSE;
task_manager_t manager;
......@@ -132,8 +165,6 @@ task_detach(task_t *taskp) {
task_free(task);
*taskp = NULL;
return (TRUE);
}
boolean_t
......@@ -165,7 +196,7 @@ task_send_event(task_t task, generic_event_t event) {
UNLOCK(&task->lock);
if (discard) {
mem_put(event->mctx, event, event->size);
event_put(event);
return (TRUE);
}
......@@ -213,7 +244,7 @@ task_send_event(task_t task, generic_event_t event) {
return (TRUE);
}
boolean_t
void
task_shutdown(task_t task) {
boolean_t was_idle = FALSE;
boolean_t discard = FALSE;
......@@ -239,7 +270,7 @@ task_shutdown(task_t task) {
UNLOCK(&task->lock);
if (discard)
return (TRUE);
return;
if (was_idle) {
boolean_t need_wakeup = FALSE;
......@@ -256,11 +287,19 @@ task_shutdown(task_t task) {
if (need_wakeup)
BROADCAST(&manager->work_available);
}
}
return (TRUE);
void
task_destroy(task_t *taskp) {
REQUIRE(taskp != NULL);
task_shutdown(*taskp);
task_detach(taskp);
}
/***
*** Task Manager.
***/
......@@ -403,8 +442,7 @@ void *task_manager_run(void *uap) {
* callback returned.
*/
if (event != NULL)
mem_put(event->mctx, event,
event->size);
event_put(event);
else
wants_shutdown = TRUE;
......@@ -465,8 +503,7 @@ void *task_manager_run(void *uap) {
event != NULL;
event = next_event) {
next_event = NEXT(event, link);
mem_put(event->mctx, event,
event->size);
event_put(event);
}
}
......
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