~ubuntu-branches/ubuntu/wily/openvswitch/wily

« back to all changes in this revision

Viewing changes to lib/seq.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-08-10 11:35:15 UTC
  • mfrom: (1.1.30)
  • Revision ID: package-import@ubuntu.com-20150810113515-575vj06oq29emxsn
Tags: 2.4.0~git20150810.97bab95-0ubuntu1
* New upstream snapshot from 2.4 branch:
  - d/*: Align any relevant packaging changes with upstream.
* d/*: wrap-and-sort.
* d/openvswitch-{common,vswitch}.install: Correct install location for
  bash completion files.
* d/tests/openflow.py: Explicitly use ovs-testcontroller as provided
  by 2.4.0 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2013 Nicira, Inc.
 
2
 * Copyright (c) 2013, 2014 Nicira, Inc.
3
3
 *
4
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
5
 * you may not use this file except in compliance with the License.
39
39
    struct hmap_node hmap_node OVS_GUARDED; /* In 'seq->waiters'. */
40
40
    unsigned int ovsthread_id OVS_GUARDED;  /* Key in 'waiters' hmap. */
41
41
 
42
 
    struct seq_thread *thread OVS_GUARDED; /* Thread preparing to wait. */
43
 
    struct list list_node OVS_GUARDED;     /* In 'thread->waiters'. */
 
42
    struct seq_thread *thread OVS_GUARDED;  /* Thread preparing to wait. */
 
43
    struct ovs_list list_node OVS_GUARDED;  /* In 'thread->waiters'. */
44
44
 
45
45
    uint64_t value OVS_GUARDED; /* seq->value we're waiting to change. */
46
46
};
47
47
 
48
48
/* A thread that might be waiting on one or more seqs. */
49
49
struct seq_thread {
50
 
    struct list waiters OVS_GUARDED; /* Contains 'struct seq_waiter's. */
 
50
    struct ovs_list waiters OVS_GUARDED; /* Contains 'struct seq_waiter's. */
51
51
    struct latch latch OVS_GUARDED;  /* Wakeup latch for this thread. */
52
52
    bool waiting OVS_GUARDED;        /* True if latch_wait() already called. */
53
53
};
125
125
}
126
126
 
127
127
static void
128
 
seq_wait__(struct seq *seq, uint64_t value)
 
128
seq_wait__(struct seq *seq, uint64_t value, const char *where)
129
129
    OVS_REQUIRES(seq_mutex)
130
130
{
131
131
    unsigned int id = ovsthread_id_self();
137
137
            if (waiter->value != value) {
138
138
                /* The current value is different from the value we've already
139
139
                 * waited for, */
140
 
                poll_immediate_wake();
 
140
                poll_immediate_wake_at(where);
141
141
            } else {
142
142
                /* Already waiting on 'value', nothing more to do. */
143
143
            }
154
154
    list_push_back(&waiter->thread->waiters, &waiter->list_node);
155
155
 
156
156
    if (!waiter->thread->waiting) {
157
 
        latch_wait(&waiter->thread->latch);
 
157
        latch_wait_at(&waiter->thread->latch, where);
158
158
        waiter->thread->waiting = true;
159
159
    }
160
160
}
165
165
 *
166
166
 * seq_read() and seq_wait() can be used together to yield a race-free wakeup
167
167
 * when an object changes, even without an ability to lock the object.  See
168
 
 * Usage in seq.h for details. */
 
168
 * Usage in seq.h for details.
 
169
 *
 
170
 * ('where' is used in debug logging.  Commonly one would use seq_wait() to
 
171
 * automatically provide the caller's source file and line number for
 
172
 * 'where'.) */
169
173
void
170
 
seq_wait(const struct seq *seq_, uint64_t value)
 
174
seq_wait_at(const struct seq *seq_, uint64_t value, const char *where)
171
175
    OVS_EXCLUDED(seq_mutex)
172
176
{
173
177
    struct seq *seq = CONST_CAST(struct seq *, seq_);
174
178
 
175
179
    ovs_mutex_lock(&seq_mutex);
176
180
    if (value == seq->value) {
177
 
        seq_wait__(seq, value);
 
181
        seq_wait__(seq, value, where);
178
182
    } else {
179
 
        poll_immediate_wake();
 
183
        poll_immediate_wake_at(where);
180
184
    }
181
185
    ovs_mutex_unlock(&seq_mutex);
182
186
}