Loading...
Searching...
No Matches
XrdFfsQueue.hh File Reference
`#include <pthread.h>`
Include dependency graph for XrdFfsQueue.hh:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Classes

struct | XrdFfsQueueTasks

## Functions

unsigned int | XrdFfsQueue_count_tasks ()
int | XrdFfsQueue_count_workers ()
struct XrdFfsQueueTasks * | XrdFfsQueue_create_task (void *(*func)(void *), void **args, short initstat)
int | XrdFfsQueue_create_workers (int n)
void | XrdFfsQueue_free_task (struct XrdFfsQueueTasks *task)
int | XrdFfsQueue_remove_workers (int n)
void | XrdFfsQueue_wait_task (struct XrdFfsQueueTasks *task)

## Class Documentation

## XrdFfsQueueTasks

struct XrdFfsQueueTasks

Definition at line 36 of file XrdFfsQueue.hh.

Collaboration diagram for XrdFfsQueueTasks:

Class Members
void ** | args |
pthread_cond_t | cond |
short | done |
void *(*)(void *) | func |
unsigned int | id |
pthread_mutex_t | mutex |
struct XrdFfsQueueTasks * | next |
struct XrdFfsQueueTasks * | prev |

## Function Documentation

## XrdFfsQueue_count_tasks()

unsigned int XrdFfsQueue_count_tasks | ( |  | ) |

Definition at line 131 of file XrdFfsQueue.cc.

{
unsigned int que_len = 0;
pthread_mutex_lock(&XrdFfsQueueTaskque_mutex);
if (XrdFfsQueueTaskque_head != NULL && XrdFfsQueueTaskque_tail != NULL) {
if (XrdFfsQueueTaskque_tail->id > XrdFfsQueueTaskque_head->id)
que_len = XrdFfsQueueTaskque_tail->id - XrdFfsQueueTaskque_head->id;
else
// this is wrong:
// que_len = (unsigned int)2147483647 - (XrdFfsQueueTaskque_head->id - XrdFfsQueueTaskque_tail->id) + 1;
//not accepted by c89
// que_len = (unsigned int)4294967295 - (XrdFfsQueueTaskque_head->id - XrdFfsQueueTaskque_tail->id) + 1;
//this is not quite correct, but I imagine that the queue will never by so long >= 2147483647
que_len = (unsigned int)2147483647 - (XrdFfsQueueTaskque_head->id - XrdFfsQueueTaskque_tail->id) + 1+(unsigned int)2147483647+1;
}
pthread_mutex_unlock(&XrdFfsQueueTaskque_mutex);
return que_len;
}
XrdFfsQueueTaskque_head
struct XrdFfsQueueTasks * XrdFfsQueueTaskque_head
Definition XrdFfsQueue.cc:39
XrdFfsQueueTaskque_mutex
pthread_mutex_t XrdFfsQueueTaskque_mutex
Definition XrdFfsQueue.cc:42
XrdFfsQueueTaskque_tail
struct XrdFfsQueueTasks * XrdFfsQueueTaskque_tail
Definition XrdFfsQueue.cc:40

References XrdFfsQueueTaskque_head, XrdFfsQueueTaskque_mutex, and XrdFfsQueueTaskque_tail.

Referenced by XrdFfsPosix_statall().

Here is the caller graph for this function:

## XrdFfsQueue_count_workers()

int XrdFfsQueue_count_workers | ( |  | ) |

Definition at line 254 of file XrdFfsQueue.cc.

{
int i;
pthread_mutex_lock(&XrdFfsQueueWorker_mutex);
i = XrdFfsQueueNworkers;
pthread_mutex_unlock(&XrdFfsQueueWorker_mutex);
return i;
}
XrdFfsQueueWorker_mutex
pthread_mutex_t XrdFfsQueueWorker_mutex
Definition XrdFfsQueue.cc:188
XrdFfsQueueNworkers
unsigned short XrdFfsQueueNworkers
Definition XrdFfsQueue.cc:189

References XrdFfsQueueNworkers, and XrdFfsQueueWorker_mutex.

Referenced by XrdFfsMisc_xrd_init(), xrootdfs_getxattr(), xrootdfs_init(), and xrootdfs_setxattr().

Here is the caller graph for this function:

## XrdFfsQueue_create_task()

struct XrdFfsQueueTasks * XrdFfsQueue_create_task | ( | void *(* | func )(void *),
|  | void ** | args,
|  | short | initstat )

Definition at line 97 of file XrdFfsQueue.cc.

{
struct XrdFfsQueueTasks *task = (struct XrdFfsQueueTasks*) malloc(sizeof(struct XrdFfsQueueTasks));
task->func = func;
task->args = args;
task->done = ( (initstat == -1)? -1 : 0); /* -1 means this task is meant to kill a worker thread */
pthread_mutex_init(&task->mutex, NULL);
pthread_cond_init(&task->cond, NULL);
XrdFfsQueue_enqueue(task);
return task;
}
XrdFfsQueue_enqueue
void XrdFfsQueue_enqueue(struct XrdFfsQueueTasks *task)
Definition XrdFfsQueue.cc:45
XrdFfsQueueTasks::args
void ** args
Definition XrdFfsQueue.hh:41
XrdFfsQueueTasks::cond
pthread_cond_t cond
Definition XrdFfsQueue.hh:38
XrdFfsQueueTasks::mutex
pthread_mutex_t mutex
Definition XrdFfsQueue.hh:37
XrdFfsQueueTasks::func
void *(* func)(void *)
Definition XrdFfsQueue.hh:40
XrdFfsQueueTasks::done
short done
Definition XrdFfsQueue.hh:39
XrdFfsQueueTasks
Definition XrdFfsQueue.hh:36

References XrdFfsQueueTasks::args, XrdFfsQueueTasks::cond, XrdFfsQueueTasks::done, XrdFfsQueueTasks::func, XrdFfsQueueTasks::mutex, and XrdFfsQueue_enqueue().

Referenced by XrdFfsPosix_deleteall(), XrdFfsPosix_readdirall(), XrdFfsPosix_statall(), XrdFfsPosix_statvfsall(), and XrdFfsQueue_remove_workers().

Here is the call graph for this function:
Here is the caller graph for this function:

## XrdFfsQueue_create_workers()

int XrdFfsQueue_create_workers | ( | int | n | ) |

Definition at line 192 of file XrdFfsQueue.cc.

{
int i, rc, *id;
pthread_t *thread;
pthread_attr_t attr;
size_t stacksize = 2*1024*1024;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, stacksize);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_mutex_lock(&XrdFfsQueueWorker_mutex);
for (i = 0; i < n; i++)
{
id = (int*) malloc(sizeof(int));
*id = XrdFfsQueueWorker_id++;
thread = (pthread_t*) malloc(sizeof(pthread_t));
if (thread == NULL)
{
XrdFfsQueueWorker_id--;
break;
}
rc = pthread_create(thread, &attr, XrdFfsQueue_worker, id);
if (rc != 0)
{
XrdFfsQueueWorker_id--;
break;
}
pthread_detach(*thread);
free(thread);
}
pthread_attr_destroy(&attr);
XrdFfsQueueNworkers += i;
pthread_mutex_unlock(&XrdFfsQueueWorker_mutex);
return i;
}
XrdFfsQueueWorker_id
unsigned int XrdFfsQueueWorker_id
Definition XrdFfsQueue.cc:190
XrdFfsQueue_worker
void * XrdFfsQueue_worker(void *x)
Definition XrdFfsQueue.cc:154

References XrdFfsQueueTasks::id, XrdFfsQueue_worker(), XrdFfsQueueNworkers, XrdFfsQueueWorker_id, and XrdFfsQueueWorker_mutex.

Referenced by XrdFfsMisc_xrd_init(), xrootdfs_init(), and xrootdfs_setxattr().

Here is the call graph for this function:
Here is the caller graph for this function:

## XrdFfsQueue_free_task()

void XrdFfsQueue_free_task | ( | struct XrdFfsQueueTasks * | task | ) |

Definition at line 111 of file XrdFfsQueue.cc.

{
pthread_mutex_destroy(&task->mutex);
pthread_cond_destroy(&task->cond);
task->func = NULL;
task->args = NULL;
task->next = NULL;
task->prev = NULL;
free(task);
task = NULL;
}
XrdFfsQueueTasks::prev
struct XrdFfsQueueTasks * prev
Definition XrdFfsQueue.hh:45
XrdFfsQueueTasks::next
struct XrdFfsQueueTasks * next
Definition XrdFfsQueue.hh:44

References XrdFfsQueueTasks::args, XrdFfsQueueTasks::cond, XrdFfsQueueTasks::func, XrdFfsQueueTasks::mutex, XrdFfsQueueTasks::next, and XrdFfsQueueTasks::prev.

Referenced by XrdFfsQueue_remove_workers().

Here is the caller graph for this function:

## XrdFfsQueue_remove_workers()

int XrdFfsQueue_remove_workers | ( | int | n | ) |

Definition at line 229 of file XrdFfsQueue.cc.

{
int i;
struct XrdFfsQueueTasks *task;
pthread_mutex_lock(&XrdFfsQueueWorker_mutex);
if (XrdFfsQueueNworkers == 0)
n = 0;
else if (n > XrdFfsQueueNworkers)
{
n = XrdFfsQueueNworkers;
XrdFfsQueueNworkers = 0;
}
else
XrdFfsQueueNworkers -= n;
for (i = 0; i < n; i++)
{
task = XrdFfsQueue_create_task(NULL, NULL, -1);
XrdFfsQueue_wait_task(task);
XrdFfsQueue_free_task(task);
}
pthread_mutex_unlock(&XrdFfsQueueWorker_mutex);
return n;
}
XrdFfsQueue_free_task
void XrdFfsQueue_free_task(struct XrdFfsQueueTasks *task)
Definition XrdFfsQueue.cc:111
XrdFfsQueue_create_task
struct XrdFfsQueueTasks * XrdFfsQueue_create_task(void *(*func)(void *), void **args, short initstat)
Definition XrdFfsQueue.cc:97
XrdFfsQueue_wait_task
void XrdFfsQueue_wait_task(struct XrdFfsQueueTasks *task)
Definition XrdFfsQueue.cc:123

References XrdFfsQueue_create_task(), XrdFfsQueue_free_task(), XrdFfsQueue_wait_task(), XrdFfsQueueNworkers, and XrdFfsQueueWorker_mutex.

Referenced by xrootdfs_setxattr().

Here is the call graph for this function:
Here is the caller graph for this function:

## XrdFfsQueue_wait_task()

void XrdFfsQueue_wait_task | ( | struct XrdFfsQueueTasks * | task | ) |

Definition at line 123 of file XrdFfsQueue.cc.

{
pthread_mutex_lock(&task->mutex);
if (task->done != 1)
pthread_cond_wait(&task->cond, &task->mutex);
pthread_mutex_unlock(&task->mutex);
}

References XrdFfsQueueTasks::cond, XrdFfsQueueTasks::done, and XrdFfsQueueTasks::mutex.

Referenced by XrdFfsQueue_remove_workers().

Here is the caller graph for this function: