Commit 3ad4f3d3 authored by Greg Williams's avatar Greg Williams
Browse files

Disabled counting semaphore with ifdefs, since it is casuing a deadlock and...

Disabled counting semaphore with ifdefs, since it is casuing a deadlock and very likely unnecessary altogether.
parent 8a407c39
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -45,9 +45,11 @@ KineticStatus KineticOperation_SendRequest(KineticOperation* const operation)
    assert(operation->connection != NULL);
    assert(operation->request != NULL);

#if COUNTING_SEMAPHORE_ENABLED
    KineticCountingSemaphore * const sem = operation->connection->outstandingOperations;

    KineticCountingSemaphore_Take(sem);
#endif
    
    KineticStatus status = KineticOperation_SendRequestInner(operation);
    if (status != KINETIC_STATUS_SUCCESS)
    {
@@ -57,7 +59,9 @@ KineticStatus KineticOperation_SendRequest(KineticOperation* const operation)
            free(request->message.message.commandBytes.data);
            request->message.message.commandBytes.data = NULL;
        }
#if COUNTING_SEMAPHORE_ENABLED
        KineticCountingSemaphore_Give(sem);
#endif
    }
    return status;
}
@@ -774,8 +778,9 @@ void KineticOperation_Complete(KineticOperation* operation, KineticStatus status
    assert(operation != NULL);
    // ExecuteOperation should ensure a callback exists (either a user supplied one, or the a default)
    KineticCompletionData completionData = {.status = status};

#if COUNTING_SEMAPHORE_ENABLED
    KineticCountingSemaphore_Give(operation->connection->outstandingOperations);
#endif

    if(operation->closure.callback != NULL) {
        operation->closure.callback(&completionData, operation->closure.clientData);
+4 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ KineticStatus KineticSession_Create(KineticSession * const session, KineticClien
        return KINETIC_STATUS_MEMORY_ERROR;
    }

#if COUNTING_SEMAPHORE_ENABLED
    session->connection->outstandingOperations =
        KineticCountingSemaphore_Create(KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION);
    if (session->connection->outstandingOperations == NULL) {
@@ -63,6 +64,7 @@ KineticStatus KineticSession_Create(KineticSession * const session, KineticClien
        KineticAllocator_FreeConnection(session->connection);
        return KINETIC_STATUS_MEMORY_ERROR;
    }
#endif

    return KINETIC_STATUS_SUCCESS;
}
@@ -75,7 +77,9 @@ KineticStatus KineticSession_Destroy(KineticSession * const session)
    if (session->connection == NULL) {
        return KINETIC_STATUS_SESSION_INVALID;
    }
#if COUNTING_SEMAPHORE_ENABLED
    KineticCountingSemaphore_Destroy(session->connection->outstandingOperations);
#endif
    KineticAllocator_FreeConnection(session->connection);
    session->connection = NULL;
    return KINETIC_STATUS_SUCCESS;
+3 −0
Original line number Diff line number Diff line
@@ -30,7 +30,10 @@
#include <time.h>
#include <pthread.h>

#define COUNTING_SEMAPHORE_ENABLED 0
#if COUNTING_SEMAPHORE_ENABLED
#define KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION (10)
#endif
#define KINETIC_SOCKET_DESCRIPTOR_INVALID (-1)
#define KINETIC_CONNECTION_INITIAL_STATUS_TIMEOUT_SECS (3)
#define KINETIC_OPERATION_TIMEOUT_SECS (20)
+8 −1
Original line number Diff line number Diff line
@@ -41,7 +41,9 @@
#include <sys/time.h>

static KineticConnection Connection;
#if COUNTING_SEMAPHORE_ENABLED
static KineticCountingSemaphore Semaphore;
#endif
static KineticSession Session;
static KineticPDU Request, Response;
static int OperationCompleteCallbackCount;
@@ -61,7 +63,9 @@ void setUp(void)
    Client.bus = &MessageBus;

    KineticAllocator_NewConnection_ExpectAndReturn(&MessageBus, &Session, &Connection);
#if COUNTING_SEMAPHORE_ENABLED
    KineticCountingSemaphore_Create_ExpectAndReturn(KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION, &Semaphore);
#endif
    
    KineticStatus status = KineticSession_Create(&Session, &Client);

@@ -105,16 +109,19 @@ void test_KineticSession_Create_should_allocate_and_destroy_KineticConnections(v
    KineticConnection connection;
    memset(&connection, 0, sizeof(connection));
    connection.pSession = &session;
    // session.connection = &connection;

    KineticAllocator_NewConnection_ExpectAndReturn(&MessageBus, &session, &connection);
#if COUNTING_SEMAPHORE_ENABLED
    KineticCountingSemaphore_Create_ExpectAndReturn(KINETIC_MAX_OUTSTANDING_OPERATIONS_PER_SESSION, &Semaphore);
#endif
    KineticStatus status = KineticSession_Create(&session, &Client);
    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);
    TEST_ASSERT_EQUAL_PTR(&connection, session.connection);
    TEST_ASSERT_FALSE(session.connection->connected);

#if COUNTING_SEMAPHORE_ENABLED
    KineticCountingSemaphore_Destroy_Expect(&Semaphore);
#endif
    KineticAllocator_FreeConnection_Expect(&connection);
    status = KineticSession_Destroy(&session);
    TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status);