Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 242cebd2 authored by Pavlin Radoslavov's avatar Pavlin Radoslavov Committed by Scott James Remnant
Browse files

GKI cleanup - Moved functions GKI_disable() and GKI_enable() to OSI

Added new functions mutex_global_lock() and mutex_global_unlock()
within the OSI module, and replaced GKI_disable() and GKI_enable()
with those functions.

Also, minor cleanup in the gki.h header file.

Change-Id: I5f410e3174541224fcf30f37e1524ef099c25193
parent 649585db
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -33,8 +33,6 @@ typedef void (TIMER_CBACK)(void *p_tle);
*/
typedef struct _tle
{
    struct _tle  *p_next;
    struct _tle  *p_prev;
    TIMER_CBACK  *p_cback;
    INT32         ticks;
    INT32         ticks_initial;
@@ -54,9 +52,6 @@ typedef struct
    UINT16   _count;
} BUFFER_Q;

#define GKI_PUBLIC_POOL         0       /* General pool accessible to GKI_getbuf() */
#define GKI_RESTRICTED_POOL     1       /* Inaccessible pool to GKI_getbuf() */

/***********************************************************************
** Function prototypes
*/
@@ -79,8 +74,3 @@ void GKI_init_q (BUFFER_Q *);
UINT16  GKI_queue_length(BUFFER_Q *);
BOOLEAN GKI_queue_is_empty(BUFFER_Q *);
void   *GKI_remove_from_queue (BUFFER_Q *, void *);

/* Disable Interrupts, Enable Interrupts
*/
void    GKI_enable(void);
void    GKI_disable(void);
+10 −13
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <stdlib.h>

#include "osi/include/allocator.h"
#include "osi/include/mutex.h"
#include "gki_int.h"

#if (GKI_NUM_TOTAL_BUF_POOLS > 16)
@@ -190,10 +191,6 @@ void GKI_init_q (BUFFER_Q *p_q)
** Description      Called by an application to get a free buffer which
**                  is of size greater or equal to the requested size.
**
**                  Note: This routine only takes buffers from public pools.
**                        It will not use any buffers from pools
**                        marked GKI_RESTRICTED_POOL.
**
** Parameters       size - (input) number of bytes needed.
**
** Returns          A pointer to the buffer, or NULL if none available
@@ -261,7 +258,7 @@ void GKI_enqueue (BUFFER_Q *p_q, void *p_buf)
    BUFFER_HDR_T *p_hdr = (BUFFER_HDR_T *) ((UINT8 *) p_buf - BUFFER_HDR_SIZE);
    assert(p_hdr->status == BUF_STATUS_UNLINKED);

    GKI_disable();
    mutex_global_lock();

    /* Since the queue is exposed (C vs C++), keep the pointers in exposed format */
    if (p_q->_p_last)
@@ -278,7 +275,7 @@ void GKI_enqueue (BUFFER_Q *p_q, void *p_buf)
    p_hdr->p_next = NULL;
    p_hdr->status = BUF_STATUS_QUEUED;

    GKI_enable();
    mutex_global_unlock();
}

/*******************************************************************************
@@ -296,11 +293,11 @@ void *GKI_dequeue (BUFFER_Q *p_q)
{
    BUFFER_HDR_T    *p_hdr;

    GKI_disable();
    mutex_global_lock();

    if (!p_q || !p_q->_count)
    {
        GKI_enable();
        mutex_global_unlock();
        return (NULL);
    }

@@ -321,7 +318,7 @@ void *GKI_dequeue (BUFFER_Q *p_q)
    p_hdr->p_next = NULL;
    p_hdr->status = BUF_STATUS_UNLINKED;

    GKI_enable();
    mutex_global_unlock();

    return ((UINT8 *)p_hdr + BUFFER_HDR_SIZE);
}
@@ -343,11 +340,11 @@ void *GKI_remove_from_queue (BUFFER_Q *p_q, void *p_buf)
    BUFFER_HDR_T    *p_prev;
    BUFFER_HDR_T    *p_buf_hdr;

    GKI_disable();
    mutex_global_lock();

    if (p_buf == p_q->_p_first)
    {
        GKI_enable();
        mutex_global_unlock();
        return (GKI_dequeue (p_q));
    }

@@ -372,12 +369,12 @@ void *GKI_remove_from_queue (BUFFER_Q *p_q, void *p_buf)
            p_buf_hdr->p_next = NULL;
            p_buf_hdr->status = BUF_STATUS_UNLINKED;

            GKI_enable();
            mutex_global_unlock();
            return (p_buf);
        }
    }

    GKI_enable();
    mutex_global_unlock();
    return (NULL);
}

+0 −3
Original line number Diff line number Diff line
@@ -18,13 +18,10 @@

#pragma once

#include <pthread.h>

#include "gki_common.h"

typedef struct
{
    pthread_mutex_t lock;
    tGKI_COM_CB com;
} tGKI_CB;

+0 −15
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@
#define LOG_TAG "bt_gki"

#include <assert.h>
#include <pthread.h>
#include <string.h>

#include "btcore/include/module.h"
@@ -32,11 +31,6 @@ tGKI_CB gki_cb;
static future_t *init(void) {
  memset(&gki_cb, 0, sizeof(gki_cb));

  pthread_mutexattr_t attr;
  pthread_mutexattr_init(&attr);
  pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
  pthread_mutex_init(&gki_cb.lock, &attr);

  gki_buffer_init();
  return NULL;
}
@@ -44,7 +38,6 @@ static future_t *init(void) {
static future_t *clean_up(void) {
  gki_buffer_cleanup();

  pthread_mutex_destroy(&gki_cb.lock);
  return NULL;
}

@@ -59,11 +52,3 @@ EXPORT_SYMBOL const module_t gki_module = {
    NULL
  }
};

void GKI_enable(void) {
  pthread_mutex_unlock(&gki_cb.lock);
}

void GKI_disable(void) {
  pthread_mutex_lock(&gki_cb.lock);
}
+9 −2
Original line number Diff line number Diff line
@@ -23,16 +23,23 @@
#include "osi/include/alarm.h"
#include "osi/include/future.h"
#include "osi/include/log.h"
#include "osi/include/mutex.h"
#include "osi/include/osi.h"

future_t *osi_init(void) {
  mutex_init();
  return future_new_immediate(FUTURE_SUCCESS);
}

future_t *osi_clean_up(void) {
  alarm_cleanup();
  return NULL;
  mutex_cleanup();
  return future_new_immediate(FUTURE_SUCCESS);
}

const module_t osi_module = {
  .name = OSI_MODULE,
  .init = NULL,
  .init = osi_init,
  .start_up = NULL,
  .shut_down = NULL,
  .clean_up = osi_clean_up,
Loading