*/
linked_list_t *protocols;
+ /**
+ * rwlock to lock the TNCCS protocol entries
+ */
+ rwlock_t *protocol_lock;
+
/**
* connection ID counter
*/
linked_list_t *connections;
/**
- * rwlock to lock TNCCS protocol and connection entries
+ * rwlock to lock TNCCS connection entries
*/
- rwlock_t *lock;
+ rwlock_t *connection_lock;
};
private_tnccs_manager_t *this, tnccs_type_t type,
tnccs_constructor_t constructor)
{
- tnccs_entry_t *entry = malloc_thing(tnccs_entry_t);
+ tnccs_entry_t *entry;
+ entry = malloc_thing(tnccs_entry_t);
entry->type = type;
entry->constructor = constructor;
- this->lock->write_lock(this->lock);
+ this->protocol_lock->write_lock(this->protocol_lock);
this->protocols->insert_last(this->protocols, entry);
- this->lock->unlock(this->lock);
+ this->protocol_lock->unlock(this->protocol_lock);
}
METHOD(tnccs_manager_t, remove_method, void,
enumerator_t *enumerator;
tnccs_entry_t *entry;
- this->lock->write_lock(this->lock);
+ this->protocol_lock->write_lock(this->protocol_lock);
enumerator = this->protocols->create_enumerator(this->protocols);
while (enumerator->enumerate(enumerator, &entry))
{
}
}
enumerator->destroy(enumerator);
- this->lock->unlock(this->lock);
+ this->protocol_lock->unlock(this->protocol_lock);
}
METHOD(tnccs_manager_t, create_instance, tnccs_t*,
tnccs_entry_t *entry;
tnccs_t *protocol = NULL;
- this->lock->read_lock(this->lock);
+ this->protocol_lock->read_lock(this->protocol_lock);
enumerator = this->protocols->create_enumerator(this->protocols);
while (enumerator->enumerate(enumerator, &entry))
{
}
}
enumerator->destroy(enumerator);
- this->lock->unlock(this->lock);
+ this->protocol_lock->unlock(this->protocol_lock);
+
return protocol;
}
tnccs_send_message_t send_message,
tnccs_provide_recommendation_t provide_recommendation)
{
- tnccs_connection_entry_t *entry = malloc_thing(tnccs_connection_entry_t);
+ tnccs_connection_entry_t *entry;
- entry->id = ++this->connection_id;
+ entry = malloc_thing(tnccs_connection_entry_t);
entry->tnccs = tnccs;
entry->send_message = send_message;
entry->provide_recommendation = provide_recommendation;
- this->lock->write_lock(this->lock);
+ this->connection_lock->write_lock(this->connection_lock);
+ entry->id = ++this->connection_id;
this->connections->insert_last(this->connections, entry);
- this->lock->unlock(this->lock);
+ this->connection_lock->unlock(this->connection_lock);
DBG1(DBG_TNC, "assigned TNCCS Connection ID %u", entry->id);
return entry->id;
enumerator_t *enumerator;
tnccs_connection_entry_t *entry;
- this->lock->write_lock(this->lock);
+ this->connection_lock->write_lock(this->connection_lock);
enumerator = this->connections->create_enumerator(this->connections);
while (enumerator->enumerate(enumerator, &entry))
{
}
}
enumerator->destroy(enumerator);
- this->lock->unlock(this->lock);
+ this->connection_lock->unlock(this->connection_lock);
}
METHOD(tnccs_manager_t, send_message, TNC_Result,
tnccs_send_message_t send_message = NULL;
tnccs_t *tnccs = NULL;
- this->lock->write_lock(this->lock);
+ this->connection_lock->read_lock(this->connection_lock);
enumerator = this->connections->create_enumerator(this->connections);
while (enumerator->enumerate(enumerator, &entry))
{
}
}
enumerator->destroy(enumerator);
- this->lock->unlock(this->lock);
+ this->connection_lock->unlock(this->connection_lock);
if (tnccs && send_message)
{
tnccs_provide_recommendation_t provide_recommendation = NULL;
tnccs_t *tnccs = NULL;
- this->lock->write_lock(this->lock);
+ this->connection_lock->read_lock(this->connection_lock);
enumerator = this->connections->create_enumerator(this->connections);
while (enumerator->enumerate(enumerator, &entry))
{
}
}
enumerator->destroy(enumerator);
- this->lock->unlock(this->lock);
+ this->connection_lock->unlock(this->connection_lock);
if (tnccs && provide_recommendation)
{
private_tnccs_manager_t *this)
{
this->protocols->destroy_function(this->protocols, free);
+ this->protocol_lock->destroy(this->protocol_lock);
this->connections->destroy_function(this->connections, free);
- this->lock->destroy(this->lock);
+ this->connection_lock->destroy(this->connection_lock);
free(this);
}
},
.protocols = linked_list_create(),
.connections = linked_list_create(),
- .lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
+ .protocol_lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
+ .connection_lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
);
return &this->public;