/[lwip]/lwip/src/core/sys.c
ViewVC logotype

Diff of /lwip/src/core/sys.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by kieranm, Tue Jun 10 10:45:29 2003 UTC revision 1.15 by likewise, Wed Jun 11 22:34:51 2003 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2001-2003 Swedish Institute of Computer Science.   * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
3   * All rights reserved.   * All rights reserved.
4   *   *
5   * Redistribution and use in source and binary forms, with or without modification,   * Redistribution and use in source and binary forms, with or without modification,
6   * are permitted provided that the following conditions are met:   * are permitted provided that the following conditions are met:
7   *   *
8   * 1. Redistributions of source code must retain the above copyright notice,   * 1. Redistributions of source code must retain the above copyright notice,
# Line 11  Line 11 
11   *    this list of conditions and the following disclaimer in the documentation   *    this list of conditions and the following disclaimer in the documentation
12   *    and/or other materials provided with the distribution.   *    and/or other materials provided with the distribution.
13   * 3. The name of the author may not be used to endorse or promote products   * 3. The name of the author may not be used to endorse or promote products
14   *    derived from this software without specific prior written permission.   *    derived from this software without specific prior written permission.
15   *   *
16   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18   * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT   * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19   * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,   * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21   * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS   * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25   * OF SUCH DAMAGE.   * OF SUCH DAMAGE.
26   *   *
27   * This file is part of the lwIP TCP/IP stack.   * This file is part of the lwIP TCP/IP stack.
28   *   *
29   * Author: Adam Dunkels <adam@sics.se>   * Author: Adam Dunkels <adam@sics.se>
30   *   *
31   */   */
# Line 54  sys_mbox_fetch(sys_mbox_t mbox, void **m Line 54  sys_mbox_fetch(sys_mbox_t mbox, void **m
54    sys_timeout_handler h;    sys_timeout_handler h;
55    void *arg;    void *arg;
56    
57        
58   again:   again:
59    timeouts = sys_arch_timeouts();    timeouts = sys_arch_timeouts();
60        
61    if (!timeouts || !timeouts->next) {    if (!timeouts || !timeouts->next) {
62      sys_arch_mbox_fetch(mbox, msg, 0);      sys_arch_mbox_fetch(mbox, msg, 0);
63    } else {    } else {
# Line 80  sys_mbox_fetch(sys_mbox_t mbox, void **m Line 80  sys_mbox_fetch(sys_mbox_t mbox, void **m
80          LWIP_DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void *)h, (void *)arg));          LWIP_DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void *)h, (void *)arg));
81          h(arg);          h(arg);
82        }        }
83          
84        /* We try again to fetch a message from the mbox. */        /* We try again to fetch a message from the mbox. */
85        goto again;        goto again;
86      } else {      } else {
# Line 93  sys_mbox_fetch(sys_mbox_t mbox, void **m Line 93  sys_mbox_fetch(sys_mbox_t mbox, void **m
93    timeouts->next->time = 0;    timeouts->next->time = 0;
94        }        }
95      }      }
96        
97    }    }
98  }  }
99  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
# Line 105  sys_sem_wait(sys_sem_t sem) Line 105  sys_sem_wait(sys_sem_t sem)
105    struct sys_timeout *tmptimeout;    struct sys_timeout *tmptimeout;
106    sys_timeout_handler h;    sys_timeout_handler h;
107    void *arg;    void *arg;
108      
109    /*  while (sys_arch_sem_wait(sem, 1000) == 0);    /*  while (sys_arch_sem_wait(sem, 1000) == 0);
110        return;*/        return;*/
111    
112   again:   again:
113      
114    timeouts = sys_arch_timeouts();    timeouts = sys_arch_timeouts();
115      
116    if (!timeouts || !timeouts->next) {    if (!timeouts || !timeouts->next) {
117      sys_arch_sem_wait(sem, 0);      sys_arch_sem_wait(sem, 0);
118    } else {    } else {
# Line 135  sys_sem_wait(sys_sem_t sem) Line 135  sys_sem_wait(sys_sem_t sem)
135          LWIP_DEBUGF(SYS_DEBUG, ("ssw h=%p(%p)\n", (void *)h, (void *)arg));          LWIP_DEBUGF(SYS_DEBUG, ("ssw h=%p(%p)\n", (void *)h, (void *)arg));
136          h(arg);          h(arg);
137        }        }
138          
139          
140        /* We try again to fetch a message from the mbox. */        /* We try again to fetch a message from the mbox. */
141        goto again;        goto again;
142      } else {      } else {
# Line 149  sys_sem_wait(sys_sem_t sem) Line 149  sys_sem_wait(sys_sem_t sem)
149    timeouts->next->time = 0;    timeouts->next->time = 0;
150        }        }
151      }      }
152        
153    }    }
154  }  }
155  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
# Line 167  sys_timeout(u32_t msecs, sys_timeout_han Line 167  sys_timeout(u32_t msecs, sys_timeout_han
167    timeout->h = h;    timeout->h = h;
168    timeout->arg = arg;    timeout->arg = arg;
169    timeout->time = msecs;    timeout->time = msecs;
170      
171    timeouts = sys_arch_timeouts();    timeouts = sys_arch_timeouts();
172      
173    LWIP_DEBUGF(SYS_DEBUG, ("sys_timeout: %p msecs=%lu h=%p arg=%p\n", (void *)timeout, msecs, (void *)h, (void *)arg));    LWIP_DEBUGF(SYS_DEBUG, ("sys_timeout: %p msecs=%lu h=%p arg=%p\n",
174        (void *)timeout, msecs, (void *)h, (void *)arg));
175    
176    LWIP_ASSERT("sys_timeout: timeouts != NULL", timeouts != NULL);    LWIP_ASSERT("sys_timeout: timeouts != NULL", timeouts != NULL);
177    if (timeouts->next == NULL) {    if (timeouts->next == NULL) {
178      timeouts->next = timeout;      timeouts->next = timeout;
179      return;      return;
180    }      }
181      
182    if (timeouts->next->time > msecs) {    if (timeouts->next->time > msecs) {
183      timeouts->next->time -= msecs;      timeouts->next->time -= msecs;
184      timeout->next = timeouts->next;      timeout->next = timeouts->next;
# Line 196  sys_timeout(u32_t msecs, sys_timeout_han Line 197  sys_timeout(u32_t msecs, sys_timeout_han
197        }        }
198      }      }
199    }    }
200      
201  }  }
202    
203  /* Go through timeout list (for this task only) and remove the first matching entry,  /* Go through timeout list (for this task only) and remove the first matching entry,
# Line 210  sys_untimeout(sys_timeout_handler h, voi Line 211  sys_untimeout(sys_timeout_handler h, voi
211      struct sys_timeout *prev_t, *t;      struct sys_timeout *prev_t, *t;
212    
213      timeouts = sys_arch_timeouts();      timeouts = sys_arch_timeouts();
214        
215      if (timeouts->next == NULL)      if (timeouts->next == NULL)
216          return;          return;
217    
# Line 234  sys_untimeout(sys_timeout_handler h, voi Line 235  sys_untimeout(sys_timeout_handler h, voi
235      return;      return;
236  }  }
237    
238                
239                    
240        
241  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/
242  static void  static void
243  sswt_handler(void *arg)  sswt_handler(void *arg)
244  {  {
245      struct sswt_cb *sswt_cb = (struct sswt_cb *) arg;      struct sswt_cb *sswt_cb = (struct sswt_cb *) arg;
246        
247      /* Timeout. Set flag to TRUE and signal semaphore */      /* Timeout. Set flag to TRUE and signal semaphore */
248      sswt_cb->timeflag = 1;      sswt_cb->timeflag = 1;
249      sys_sem_signal(*(sswt_cb->psem));      sys_sem_signal(*(sswt_cb->psem));
# Line 259  sys_sem_wait_timeout(sys_sem_t sem, u32_ Line 260  sys_sem_wait_timeout(sys_sem_t sem, u32_
260    
261      sswt_cb.psem = &sem;      sswt_cb.psem = &sem;
262      sswt_cb.timeflag = 0;      sswt_cb.timeflag = 0;
263        
264      /* If timeout is zero, then just wait forever */      /* If timeout is zero, then just wait forever */
265      if (timeout > 0)      if (timeout > 0)
266          /* Create a timer and pass it the address of our flag */          /* Create a timer and pass it the address of our flag */
# Line 275  sys_sem_wait_timeout(sys_sem_t sem, u32_ Line 276  sys_sem_wait_timeout(sys_sem_t sem, u32_
276          sys_untimeout(sswt_handler, &sswt_cb);          sys_untimeout(sswt_handler, &sswt_cb);
277          return 1;          return 1;
278      }      }
279        
280  }  }
281    
282  /*-----------------------------------------------------------------------------------*/  /*-----------------------------------------------------------------------------------*/

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26