}
}
- (void) pthread_mutex_init(&inst->worker_mutex, NULL);
-
return 0;
}
-/** Detach the application
- *
- *
- * @param[in] instance Ctx data for this application.
- * @return
- * - 0 on success.
- * - -1 on failure.
- */
-static int mod_detach(void *instance)
-{
- proto_detail_t *inst = talloc_get_type_abort(instance, proto_detail_t);
-
- pthread_mutex_destroy(&inst->worker_mutex);
-
- return 0;
-}
fr_app_t proto_detail = {
.magic = RLM_MODULE_INIT,
.bootstrap = mod_bootstrap,
.instantiate = mod_instantiate,
- .detach = mod_detach,
.open = mod_open,
.decode = mod_decode,
.encode = mod_encode,
fr_listen_t *listen; //!< The listener structure which describes
//!< the I/O path.
- pthread_mutex_t worker_mutex; //!< for the workers
- int num_workers; //!< number of workers
-
} proto_detail_t;
fr_event_list_t *el; //!< for various timers
fr_network_t *nr; //!< for Linux-specific callbacks
fr_listen_t *listen; //!< talloc_parent() is slow
+ struct proto_detail_work_thread_t *file_parent; //!< thread instance of the directory reader that spawned us
char const *filename_work; //!< work file name
fr_dlist_head_t list; //!< for retransmissions
off_t read_offset; //!< where we're reading from in filename_work
fr_event_timer_t const *ev; //!< for detail file timers.
+
+ pthread_mutex_t worker_mutex; //!< for the workers
+ int num_workers; //!< number of workers
} proto_detail_work_thread_t;
typedef struct proto_detail_process_t {
static void mod_vnode_extend(fr_listen_t *li, UNUSED uint32_t fflags)
{
- proto_detail_file_t const *inst = talloc_get_type_abort_const(li->app_io_instance, proto_detail_file_t);
proto_detail_file_thread_t *thread = talloc_get_type_abort(li->thread_instance, proto_detail_file_thread_t);
bool has_worker = false;
- pthread_mutex_lock(&inst->parent->worker_mutex);
- has_worker = (inst->parent->num_workers != 0);
- pthread_mutex_unlock(&inst->parent->worker_mutex);
+ pthread_mutex_lock(&thread->worker_mutex);
+ has_worker = (thread->num_workers != 0);
+ pthread_mutex_unlock(&thread->worker_mutex);
if (has_worker) return;
thread->inst = inst;
thread->name = talloc_typed_asprintf(inst, "proto_detail polling for files matching %s", inst->filename);
thread->vnode_fd = -1;
+ pthread_mutex_init(&thread->worker_mutex, NULL);
DEBUG("Listening on %s bound to virtual server %s FD %d",
thread->name, cf_section_name2(inst->parent->server_cs), thread->fd);
li->app_io_instance = inst->parent->work_io_instance;
work->inst = li->app_io_instance;
+ work->file_parent = li->thread_instance;
work->ev = NULL;
li->fd = work->fd = dup(fd);
li->default_message_size = inst->parent->max_packet_size;
li->num_messages = inst->parent->num_messages;
- pthread_mutex_lock(&inst->parent->worker_mutex);
- inst->parent->num_workers++;
- pthread_mutex_unlock(&inst->parent->worker_mutex);
+ pthread_mutex_lock(&thread->worker_mutex);
+ thread->num_workers++;
+ pthread_mutex_unlock(&thread->worker_mutex);
/*
* Open the detail.work file.
int fd, rcode;
bool has_worker;
- pthread_mutex_lock(&inst->parent->worker_mutex);
- has_worker = (inst->parent->num_workers != 0);
- pthread_mutex_unlock(&inst->parent->worker_mutex);
+ pthread_mutex_lock(&thread->worker_mutex);
+ has_worker = (thread->num_workers != 0);
+ pthread_mutex_unlock(&thread->worker_mutex);
/*
* The worker is still processing the file, poll until
}
close(thread->vnode_fd);
thread->vnode_fd = -1;
+
+ pthread_mutex_destroy(&thread->worker_mutex);
}
return 0;
* hacks in proto_detail which let us start up with
* "transport = work" for debugging purposes.
*/
- pthread_mutex_lock(&inst->parent->worker_mutex);
- inst->parent->work_io_instance = NULL;
- if (inst->parent->num_workers > 0) inst->parent->num_workers--;
- pthread_mutex_unlock(&inst->parent->worker_mutex);
+ if (thread->file_parent) {
+ pthread_mutex_lock(&thread->file_parent->worker_mutex);
+ inst->parent->work_io_instance = NULL;
+ if (thread->file_parent->num_workers > 0) thread->file_parent->num_workers--;
+ pthread_mutex_unlock(&thread->file_parent->worker_mutex);
+ }
DEBUG("Closing and deleting detail worker file %s", thread->name);