[PATCH v2 1/9] sync: Use a linked list instead of an array for SysCounterList.
Peter Hutterer
peter.hutterer at who-t.net
Wed Mar 14 21:10:22 PDT 2012
From: Jamey Sharp <jamey at minilop.net>
Signed-off-by: Jamey Sharp <jamey at minilop.net>
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
Changes to v1:
- new patch
Xext/sync.c | 56 ++++++++++++++------------------------------------------
Xext/syncsrv.h | 3 +++
2 files changed, 17 insertions(+), 42 deletions(-)
diff --git a/Xext/sync.c b/Xext/sync.c
index 7791ab6..6767b05 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -88,8 +88,7 @@ static RESTYPE RTAwait;
static RESTYPE RTAlarm;
static RESTYPE RTAlarmClient;
static RESTYPE RTFence;
-static int SyncNumSystemCounters = 0;
-static SyncCounter **SysCounterList = NULL;
+static struct xorg_list SysCounterList;
static int SyncNumInvalidCounterWarnings = 0;
#define MAX_INVALID_COUNTER_WARNINGS 5
@@ -981,11 +980,6 @@ SyncCreateSystemCounter(
{
SyncCounter *pCounter;
- SysCounterList = realloc(SysCounterList,
- (SyncNumSystemCounters+1)*sizeof(SyncCounter *));
- if (!SysCounterList)
- return NULL;
-
/* this function may be called before SYNC has been initialized, so we
* have to make sure RTCounter is created.
*/
@@ -1011,6 +1005,7 @@ SyncCreateSystemCounter(
return pCounter;
}
pCounter->pSysCounterInfo = psci;
+ psci->pCounter = pCounter;
psci->name = name;
psci->resolution = resolution;
psci->counterType = counterType;
@@ -1018,7 +1013,7 @@ SyncCreateSystemCounter(
psci->BracketValues = BracketValues;
XSyncMaxValue(&psci->bracket_greater);
XSyncMinValue(&psci->bracket_less);
- SysCounterList[SyncNumSystemCounters++] = pCounter;
+ xorg_list_add(&psci->entry, &SysCounterList);
}
return pCounter;
}
@@ -1173,31 +1168,8 @@ FreeCounter(void *env, XID id)
}
if (IsSystemCounter(pCounter))
{
- int i, found = 0;
-
+ xorg_list_del(&pCounter->pSysCounterInfo->entry);
free(pCounter->pSysCounterInfo);
-
- /* find the counter in the list of system counters and remove it */
-
- if (SysCounterList)
- {
- for (i = 0; i < SyncNumSystemCounters; i++)
- {
- if (SysCounterList[i] == pCounter)
- {
- found = i;
- break;
- }
- }
- if (found < (SyncNumSystemCounters-1))
- {
- for (i = found; i < SyncNumSystemCounters-1; i++)
- {
- SysCounterList[i] = SysCounterList[i+1];
- }
- }
- }
- SyncNumSystemCounters--;
}
free(pCounter);
return Success;
@@ -1294,20 +1266,21 @@ static int
ProcSyncListSystemCounters(ClientPtr client)
{
xSyncListSystemCountersReply rep;
- int i, len;
+ SysCounterInfo *psci;
+ int len = 0;
xSyncSystemCounter *list = NULL, *walklist = NULL;
REQUEST_SIZE_MATCH(xSyncListSystemCountersReq);
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
- rep.nCounters = SyncNumSystemCounters;
+ rep.nCounters = 0;
- for (i = len = 0; i < SyncNumSystemCounters; i++)
+ xorg_list_for_each_entry(psci, &SysCounterList, entry)
{
- const char *name = SysCounterList[i]->pSysCounterInfo->name;
/* pad to 4 byte boundary */
- len += pad_to_int32(sz_xSyncSystemCounter + strlen(name));
+ len += pad_to_int32(sz_xSyncSystemCounter + strlen(psci->name));
+ ++rep.nCounters;
}
if (len)
@@ -1326,13 +1299,12 @@ ProcSyncListSystemCounters(ClientPtr client)
swapl(&rep.nCounters);
}
- for (i = 0; i < SyncNumSystemCounters; i++)
+ xorg_list_for_each_entry(psci, &SysCounterList, entry)
{
int namelen;
char *pname_in_reply;
- SysCounterInfo *psci = SysCounterList[i]->pSysCounterInfo;
- walklist->counter = SysCounterList[i]->sync.id;
+ walklist->counter = psci->pCounter->sync.id;
walklist->resolution_hi = XSyncValueHigh32(psci->resolution);
walklist->resolution_lo = XSyncValueLow32(psci->resolution);
namelen = strlen(psci->name);
@@ -2550,8 +2522,6 @@ SAlarmNotifyEvent(xSyncAlarmNotifyEvent *from, xSyncAlarmNotifyEvent *to)
static void
SyncResetProc(ExtensionEntry *extEntry)
{
- free(SysCounterList);
- SysCounterList = NULL;
RTCounter = 0;
}
@@ -2564,6 +2534,8 @@ SyncExtensionInit(void)
ExtensionEntry *extEntry;
int s;
+ xorg_list_init(&SysCounterList);
+
for (s = 0; s < screenInfo.numScreens; s++)
miSyncSetup(screenInfo.screens[s]);
diff --git a/Xext/syncsrv.h b/Xext/syncsrv.h
index d9ec88c..c8930a8 100644
--- a/Xext/syncsrv.h
+++ b/Xext/syncsrv.h
@@ -51,6 +51,7 @@ PERFORMANCE OF THIS SOFTWARE.
#ifndef _SYNCSRV_H_
#define _SYNCSRV_H_
+#include "list.h"
#include "misync.h"
#include "misyncstr.h"
@@ -72,6 +73,7 @@ typedef void (*SyncSystemCounterBracketValues)(pointer counter,
CARD64 *pbracket_greater);
typedef struct _SysCounterInfo {
+ SyncCounter *pCounter;
const char *name;
CARD64 resolution;
CARD64 bracket_greater;
@@ -79,6 +81,7 @@ typedef struct _SysCounterInfo {
SyncCounterType counterType; /* how can this counter change */
SyncSystemCounterQueryValue QueryValue;
SyncSystemCounterBracketValues BracketValues;
+ struct xorg_list entry;
} SysCounterInfo;
--
1.7.7.6
More information about the xorg-devel
mailing list