mirror of
https://github.com/schoebel/mars
synced 2025-03-03 11:57:45 +00:00
infra: wrapper for generic_{dis,}connect with locking
This commit is contained in:
parent
f0381455cb
commit
0c76f0f1fd
@ -130,6 +130,9 @@ extern void mars_free_dent_all(struct mars_global *global, struct list_head *anc
|
||||
|
||||
// low-level brick instantiation
|
||||
|
||||
int mars_connect(struct mars_input *a, struct mars_output *b);
|
||||
int mars_disconnect(struct mars_input *a);
|
||||
|
||||
extern struct mars_brick *mars_find_brick(struct mars_global *global, const void *brick_type, const char *path);
|
||||
extern struct mars_brick *mars_make_brick(struct mars_global *global, struct mars_dent *belongs, const void *_brick_type, const char *path, const char *name);
|
||||
extern int mars_free_brick(struct mars_brick *brick);
|
||||
|
@ -1194,6 +1194,59 @@ EXPORT_SYMBOL_GPL(mars_free_dent_all);
|
||||
|
||||
// low-level brick instantiation
|
||||
|
||||
int mars_connect(struct mars_input *a, struct mars_output *b)
|
||||
{
|
||||
struct mars_brick *a_brick = a->brick;
|
||||
struct mars_global *a_global = a_brick->global;
|
||||
struct mars_brick *b_brick = b->brick;
|
||||
struct mars_global *b_global = b_brick->global;
|
||||
int status;
|
||||
|
||||
if (a_global)
|
||||
down_write(&a_global->brick_mutex);
|
||||
if (b_global && b_global != a_global)
|
||||
down_write(&b_global->brick_mutex);
|
||||
|
||||
status = generic_connect((void*)a, (void*)b);
|
||||
|
||||
if (b_global && b_global != a_global)
|
||||
up_write(&b_global->brick_mutex);
|
||||
if (a_global)
|
||||
up_write(&a_global->brick_mutex);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int mars_disconnect(struct mars_input *a)
|
||||
{
|
||||
struct mars_brick *a_brick = a->brick;
|
||||
struct mars_global *a_global = a_brick->global;
|
||||
struct mars_output *b;
|
||||
int status = 0;
|
||||
|
||||
if (a_global)
|
||||
down_write(&a_global->brick_mutex);
|
||||
|
||||
b = a->connect;
|
||||
if (b) {
|
||||
struct mars_brick *b_brick = b->brick;
|
||||
struct mars_global *b_global = b_brick->global;
|
||||
|
||||
if (b_global && b_global != a_global)
|
||||
down_write(&b_global->brick_mutex);
|
||||
|
||||
status = generic_disconnect((void*)a);
|
||||
|
||||
if (b_global && b_global != a_global)
|
||||
up_write(&b_global->brick_mutex);
|
||||
}
|
||||
|
||||
if (a_global)
|
||||
up_write(&a_global->brick_mutex);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
struct mars_brick *mars_find_brick(struct mars_global *global, const void *brick_type, const char *path)
|
||||
{
|
||||
struct list_head *tmp;
|
||||
|
Loading…
Reference in New Issue
Block a user