Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
pqueue.h
00001 #ifndef _PQUEUE_H_ 00002 #define _PQUEUE_H_ 00003 00004 typedef struct prioQueueEle { 00005 timeval t; 00006 void (*foo)(void); 00007 int sched; 00008 struct prioQueueEle *next; 00009 }qEle; 00010 typedef struct prioQueue { 00011 int numEle; 00012 qEle *head; 00013 00014 }pQueue; 00015 00016 00017 00018 int enqueue(pQueue *xP, timeval t, void (*schedFunc)(void)) { 00019 if (xP->numEle == QUEUE_MAX) 00020 return 0; //ERROR reached max . 00021 00022 xP->numEle++; 00023 qEle *newEle = (qEle*)malloc(sizeof(qEle)); 00024 newEle->t.tv_sec = t.tv_sec; 00025 newEle->t.tv_usec = t.tv_usec; 00026 newEle->foo = schedFunc; 00027 newEle->sched = 0; 00028 newEle->next = NULL; 00029 if (xP->head == NULL) { //first ele; 00030 xP->head = newEle; 00031 return 1; 00032 } else { 00033 if ((xP->head->t.tv_sec > t.tv_sec) || 00034 ((xP->head->t.tv_sec == t.tv_sec ) && (xP->head->t.tv_usec > t.tv_usec)) ) { 00035 newEle->next = xP->head; 00036 xP->head = newEle; 00037 00038 return 1; 00039 } else if (xP->head->next == NULL) { 00040 xP->head->next = newEle; 00041 return 1; 00042 } 00043 } 00044 qEle *e = xP->head; 00045 while (e->next->next !=NULL) { 00046 if ((e->next->t.tv_sec > t.tv_sec) || 00047 ((e->next->t.tv_sec == t.tv_sec) && (e->next->t.tv_usec > t.tv_usec)) ) { 00048 newEle->next = e->next; 00049 e->next = newEle; 00050 return 1; 00051 } 00052 e= e->next; 00053 } 00054 e->next->next = newEle; 00055 return 1; 00056 } 00057 00058 00059 00060 00061 qEle* pop(pQueue *xP) { 00062 qEle *p = xP->head; 00063 xP->head = p->next; 00064 xP->numEle--; 00065 return p; 00066 // free(p); 00067 } 00068 00069 #endif
Generated on Mon Jul 25 2022 07:15:09 by
1.7.2