sync: Use a linked list instead of an array for SysCounterList.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Jamey Sharp 2012-03-14 17:22:18 -07:00 committed by Peter Hutterer
parent 61cb98da1c
commit 1f12f059ef
2 changed files with 17 additions and 39 deletions

View File

@ -87,8 +87,7 @@ static RESTYPE RTAwait;
static RESTYPE RTAlarm; static RESTYPE RTAlarm;
static RESTYPE RTAlarmClient; static RESTYPE RTAlarmClient;
static RESTYPE RTFence; static RESTYPE RTFence;
static int SyncNumSystemCounters = 0; static struct xorg_list SysCounterList;
static SyncCounter **SysCounterList = NULL;
static int SyncNumInvalidCounterWarnings = 0; static int SyncNumInvalidCounterWarnings = 0;
#define MAX_INVALID_COUNTER_WARNINGS 5 #define MAX_INVALID_COUNTER_WARNINGS 5
@ -932,12 +931,6 @@ SyncCreateSystemCounter(const char *name,
{ {
SyncCounter *pCounter; 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 /* this function may be called before SYNC has been initialized, so we
* have to make sure RTCounter is created. * have to make sure RTCounter is created.
*/ */
@ -959,6 +952,7 @@ SyncCreateSystemCounter(const char *name,
return pCounter; return pCounter;
} }
pCounter->pSysCounterInfo = psci; pCounter->pSysCounterInfo = psci;
psci->pCounter = pCounter;
psci->name = name; psci->name = name;
psci->resolution = resolution; psci->resolution = resolution;
psci->counterType = counterType; psci->counterType = counterType;
@ -966,7 +960,7 @@ SyncCreateSystemCounter(const char *name,
psci->BracketValues = BracketValues; psci->BracketValues = BracketValues;
XSyncMaxValue(&psci->bracket_greater); XSyncMaxValue(&psci->bracket_greater);
XSyncMinValue(&psci->bracket_less); XSyncMinValue(&psci->bracket_less);
SysCounterList[SyncNumSystemCounters++] = pCounter; xorg_list_add(&psci->entry, &SysCounterList);
} }
return pCounter; return pCounter;
} }
@ -1111,26 +1105,8 @@ FreeCounter(void *env, XID id)
free(ptl); /* destroy the trigger list as we go */ free(ptl); /* destroy the trigger list as we go */
} }
if (IsSystemCounter(pCounter)) { if (IsSystemCounter(pCounter)) {
int i, found = 0; xorg_list_del(&pCounter->pSysCounterInfo->entry);
free(pCounter->pSysCounterInfo); 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); free(pCounter);
return Success; return Success;
@ -1221,20 +1197,20 @@ static int
ProcSyncListSystemCounters(ClientPtr client) ProcSyncListSystemCounters(ClientPtr client)
{ {
xSyncListSystemCountersReply rep; xSyncListSystemCountersReply rep;
int i, len; SysCounterInfo *psci;
int len = 0;
xSyncSystemCounter *list = NULL, *walklist = NULL; xSyncSystemCounter *list = NULL, *walklist = NULL;
REQUEST_SIZE_MATCH(xSyncListSystemCountersReq); REQUEST_SIZE_MATCH(xSyncListSystemCountersReq);
rep.type = X_Reply; rep.type = X_Reply;
rep.sequenceNumber = client->sequence; rep.sequenceNumber = client->sequence;
rep.nCounters = SyncNumSystemCounters; rep.nCounters = 0;
for (i = len = 0; i < SyncNumSystemCounters; i++) {
const char *name = SysCounterList[i]->pSysCounterInfo->name;
xorg_list_for_each_entry(psci, &SysCounterList, entry) {
/* pad to 4 byte boundary */ /* 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) { if (len) {
@ -1251,12 +1227,11 @@ ProcSyncListSystemCounters(ClientPtr client)
swapl(&rep.nCounters); swapl(&rep.nCounters);
} }
for (i = 0; i < SyncNumSystemCounters; i++) { xorg_list_for_each_entry(psci, &SysCounterList, entry) {
int namelen; int namelen;
char *pname_in_reply; 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_hi = XSyncValueHigh32(psci->resolution);
walklist->resolution_lo = XSyncValueLow32(psci->resolution); walklist->resolution_lo = XSyncValueLow32(psci->resolution);
namelen = strlen(psci->name); namelen = strlen(psci->name);
@ -2441,8 +2416,6 @@ SAlarmNotifyEvent(xSyncAlarmNotifyEvent * from, xSyncAlarmNotifyEvent * to)
static void static void
SyncResetProc(ExtensionEntry * extEntry) SyncResetProc(ExtensionEntry * extEntry)
{ {
free(SysCounterList);
SysCounterList = NULL;
RTCounter = 0; RTCounter = 0;
} }
@ -2455,6 +2428,8 @@ SyncExtensionInit(void)
ExtensionEntry *extEntry; ExtensionEntry *extEntry;
int s; int s;
xorg_list_init(&SysCounterList);
for (s = 0; s < screenInfo.numScreens; s++) for (s = 0; s < screenInfo.numScreens; s++)
miSyncSetup(screenInfo.screens[s]); miSyncSetup(screenInfo.screens[s]);

View File

@ -51,6 +51,7 @@ PERFORMANCE OF THIS SOFTWARE.
#ifndef _SYNCSRV_H_ #ifndef _SYNCSRV_H_
#define _SYNCSRV_H_ #define _SYNCSRV_H_
#include "list.h"
#include "misync.h" #include "misync.h"
#include "misyncstr.h" #include "misyncstr.h"
@ -74,6 +75,7 @@ typedef void (*SyncSystemCounterBracketValues)(pointer counter,
); );
typedef struct _SysCounterInfo { typedef struct _SysCounterInfo {
SyncCounter *pCounter;
const char *name; const char *name;
CARD64 resolution; CARD64 resolution;
CARD64 bracket_greater; CARD64 bracket_greater;
@ -81,6 +83,7 @@ typedef struct _SysCounterInfo {
SyncCounterType counterType; /* how can this counter change */ SyncCounterType counterType; /* how can this counter change */
SyncSystemCounterQueryValue QueryValue; SyncSystemCounterQueryValue QueryValue;
SyncSystemCounterBracketValues BracketValues; SyncSystemCounterBracketValues BracketValues;
struct xorg_list entry;
} SysCounterInfo; } SysCounterInfo;
typedef struct _SyncAlarmClientList { typedef struct _SyncAlarmClientList {