forked from forgejo/forgejo
Integrate public as bindata optionally (#293)
* Dropped unused codekit config * Integrated dynamic and static bindata for public * Ignore public bindata * Add a general generate make task * Integrated flexible public assets into web command * Updated vendoring, added all missiong govendor deps * Made the linter happy with the bindata and dynamic code * Moved public bindata definition to modules directory * Ignoring the new bindata path now * Updated to the new public modules import path * Updated public bindata command and drop the new prefix
This commit is contained in:
parent
4680c349dd
commit
b6a95a8cb3
691 changed files with 305318 additions and 1272 deletions
114
vendor/github.com/ngaut/sync2/atomic.go
generated
vendored
Normal file
114
vendor/github.com/ngaut/sync2/atomic.go
generated
vendored
Normal file
|
@ -0,0 +1,114 @@
|
|||
// Copyright 2013, Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package sync2
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
type AtomicInt32 int32
|
||||
|
||||
func (i *AtomicInt32) Add(n int32) int32 {
|
||||
return atomic.AddInt32((*int32)(i), n)
|
||||
}
|
||||
|
||||
func (i *AtomicInt32) Set(n int32) {
|
||||
atomic.StoreInt32((*int32)(i), n)
|
||||
}
|
||||
|
||||
func (i *AtomicInt32) Get() int32 {
|
||||
return atomic.LoadInt32((*int32)(i))
|
||||
}
|
||||
|
||||
func (i *AtomicInt32) CompareAndSwap(oldval, newval int32) (swapped bool) {
|
||||
return atomic.CompareAndSwapInt32((*int32)(i), oldval, newval)
|
||||
}
|
||||
|
||||
type AtomicUint32 uint32
|
||||
|
||||
func (i *AtomicUint32) Add(n uint32) uint32 {
|
||||
return atomic.AddUint32((*uint32)(i), n)
|
||||
}
|
||||
|
||||
func (i *AtomicUint32) Set(n uint32) {
|
||||
atomic.StoreUint32((*uint32)(i), n)
|
||||
}
|
||||
|
||||
func (i *AtomicUint32) Get() uint32 {
|
||||
return atomic.LoadUint32((*uint32)(i))
|
||||
}
|
||||
|
||||
func (i *AtomicUint32) CompareAndSwap(oldval, newval uint32) (swapped bool) {
|
||||
return atomic.CompareAndSwapUint32((*uint32)(i), oldval, newval)
|
||||
}
|
||||
|
||||
type AtomicInt64 int64
|
||||
|
||||
func (i *AtomicInt64) Add(n int64) int64 {
|
||||
return atomic.AddInt64((*int64)(i), n)
|
||||
}
|
||||
|
||||
func (i *AtomicInt64) Set(n int64) {
|
||||
atomic.StoreInt64((*int64)(i), n)
|
||||
}
|
||||
|
||||
func (i *AtomicInt64) Get() int64 {
|
||||
return atomic.LoadInt64((*int64)(i))
|
||||
}
|
||||
|
||||
func (i *AtomicInt64) CompareAndSwap(oldval, newval int64) (swapped bool) {
|
||||
return atomic.CompareAndSwapInt64((*int64)(i), oldval, newval)
|
||||
}
|
||||
|
||||
type AtomicDuration int64
|
||||
|
||||
func (d *AtomicDuration) Add(duration time.Duration) time.Duration {
|
||||
return time.Duration(atomic.AddInt64((*int64)(d), int64(duration)))
|
||||
}
|
||||
|
||||
func (d *AtomicDuration) Set(duration time.Duration) {
|
||||
atomic.StoreInt64((*int64)(d), int64(duration))
|
||||
}
|
||||
|
||||
func (d *AtomicDuration) Get() time.Duration {
|
||||
return time.Duration(atomic.LoadInt64((*int64)(d)))
|
||||
}
|
||||
|
||||
func (d *AtomicDuration) CompareAndSwap(oldval, newval time.Duration) (swapped bool) {
|
||||
return atomic.CompareAndSwapInt64((*int64)(d), int64(oldval), int64(newval))
|
||||
}
|
||||
|
||||
// AtomicString gives you atomic-style APIs for string, but
|
||||
// it's only a convenience wrapper that uses a mutex. So, it's
|
||||
// not as efficient as the rest of the atomic types.
|
||||
type AtomicString struct {
|
||||
mu sync.Mutex
|
||||
str string
|
||||
}
|
||||
|
||||
func (s *AtomicString) Set(str string) {
|
||||
s.mu.Lock()
|
||||
s.str = str
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
func (s *AtomicString) Get() string {
|
||||
s.mu.Lock()
|
||||
str := s.str
|
||||
s.mu.Unlock()
|
||||
return str
|
||||
}
|
||||
|
||||
func (s *AtomicString) CompareAndSwap(oldval, newval string) (swqpped bool) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if s.str == oldval {
|
||||
s.str = newval
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
56
vendor/github.com/ngaut/sync2/cond.go
generated
vendored
Normal file
56
vendor/github.com/ngaut/sync2/cond.go
generated
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
// Copyright 2013, Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package sync2
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Cond is an alternate implementation of sync.Cond
|
||||
type Cond struct {
|
||||
L sync.Locker
|
||||
sema chan struct{}
|
||||
waiters AtomicInt64
|
||||
}
|
||||
|
||||
func NewCond(l sync.Locker) *Cond {
|
||||
return &Cond{L: l, sema: make(chan struct{})}
|
||||
}
|
||||
|
||||
func (c *Cond) Wait() {
|
||||
c.waiters.Add(1)
|
||||
c.L.Unlock()
|
||||
<-c.sema
|
||||
c.L.Lock()
|
||||
}
|
||||
|
||||
func (c *Cond) Signal() {
|
||||
for {
|
||||
w := c.waiters.Get()
|
||||
if w == 0 {
|
||||
return
|
||||
}
|
||||
if c.waiters.CompareAndSwap(w, w-1) {
|
||||
break
|
||||
}
|
||||
}
|
||||
c.sema <- struct{}{}
|
||||
}
|
||||
|
||||
func (c *Cond) Broadcast() {
|
||||
var w int64
|
||||
for {
|
||||
w = c.waiters.Get()
|
||||
if w == 0 {
|
||||
return
|
||||
}
|
||||
if c.waiters.CompareAndSwap(w, 0) {
|
||||
break
|
||||
}
|
||||
}
|
||||
for i := int64(0); i < w; i++ {
|
||||
c.sema <- struct{}{}
|
||||
}
|
||||
}
|
55
vendor/github.com/ngaut/sync2/semaphore.go
generated
vendored
Normal file
55
vendor/github.com/ngaut/sync2/semaphore.go
generated
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
// Copyright 2012, Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package sync2
|
||||
|
||||
// What's in a name? Channels have all you need to emulate a counting
|
||||
// semaphore with a boatload of extra functionality. However, in some
|
||||
// cases, you just want a familiar API.
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Semaphore is a counting semaphore with the option to
|
||||
// specify a timeout.
|
||||
type Semaphore struct {
|
||||
slots chan struct{}
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
// NewSemaphore creates a Semaphore. The count parameter must be a positive
|
||||
// number. A timeout of zero means that there is no timeout.
|
||||
func NewSemaphore(count int, timeout time.Duration) *Semaphore {
|
||||
sem := &Semaphore{
|
||||
slots: make(chan struct{}, count),
|
||||
timeout: timeout,
|
||||
}
|
||||
for i := 0; i < count; i++ {
|
||||
sem.slots <- struct{}{}
|
||||
}
|
||||
return sem
|
||||
}
|
||||
|
||||
// Acquire returns true on successful acquisition, and
|
||||
// false on a timeout.
|
||||
func (sem *Semaphore) Acquire() bool {
|
||||
if sem.timeout == 0 {
|
||||
<-sem.slots
|
||||
return true
|
||||
}
|
||||
select {
|
||||
case <-sem.slots:
|
||||
return true
|
||||
case <-time.After(sem.timeout):
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Release releases the acquired semaphore. You must
|
||||
// not release more than the number of semaphores you've
|
||||
// acquired.
|
||||
func (sem *Semaphore) Release() {
|
||||
sem.slots <- struct{}{}
|
||||
}
|
121
vendor/github.com/ngaut/sync2/service_manager.go
generated
vendored
Normal file
121
vendor/github.com/ngaut/sync2/service_manager.go
generated
vendored
Normal file
|
@ -0,0 +1,121 @@
|
|||
// Copyright 2013, Google Inc. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package sync2
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// These are the three predefined states of a service.
|
||||
const (
|
||||
SERVICE_STOPPED = iota
|
||||
SERVICE_RUNNING
|
||||
SERVICE_SHUTTING_DOWN
|
||||
)
|
||||
|
||||
var stateNames = []string{
|
||||
"Stopped",
|
||||
"Running",
|
||||
"ShuttingDown",
|
||||
}
|
||||
|
||||
// ServiceManager manages the state of a service through its lifecycle.
|
||||
type ServiceManager struct {
|
||||
mu sync.Mutex
|
||||
wg sync.WaitGroup
|
||||
err error // err is the error returned from the service function.
|
||||
state AtomicInt64
|
||||
// shutdown is created when the service starts and is closed when the service
|
||||
// enters the SERVICE_SHUTTING_DOWN state.
|
||||
shutdown chan struct{}
|
||||
}
|
||||
|
||||
// Go tries to change the state from SERVICE_STOPPED to SERVICE_RUNNING.
|
||||
//
|
||||
// If the current state is not SERVICE_STOPPED (already running), it returns
|
||||
// false immediately.
|
||||
//
|
||||
// On successful transition, it launches the service as a goroutine and returns
|
||||
// true. The service function is responsible for returning on its own when
|
||||
// requested, either by regularly checking svc.IsRunning(), or by waiting for
|
||||
// the svc.ShuttingDown channel to be closed.
|
||||
//
|
||||
// When the service func returns, the state is reverted to SERVICE_STOPPED.
|
||||
func (svm *ServiceManager) Go(service func(svc *ServiceContext) error) bool {
|
||||
svm.mu.Lock()
|
||||
defer svm.mu.Unlock()
|
||||
if !svm.state.CompareAndSwap(SERVICE_STOPPED, SERVICE_RUNNING) {
|
||||
return false
|
||||
}
|
||||
svm.wg.Add(1)
|
||||
svm.err = nil
|
||||
svm.shutdown = make(chan struct{})
|
||||
go func() {
|
||||
svm.err = service(&ServiceContext{ShuttingDown: svm.shutdown})
|
||||
svm.state.Set(SERVICE_STOPPED)
|
||||
svm.wg.Done()
|
||||
}()
|
||||
return true
|
||||
}
|
||||
|
||||
// Stop tries to change the state from SERVICE_RUNNING to SERVICE_SHUTTING_DOWN.
|
||||
// If the current state is not SERVICE_RUNNING, it returns false immediately.
|
||||
// On successul transition, it waits for the service to finish, and returns true.
|
||||
// You are allowed to Go() again after a Stop().
|
||||
func (svm *ServiceManager) Stop() bool {
|
||||
svm.mu.Lock()
|
||||
defer svm.mu.Unlock()
|
||||
if !svm.state.CompareAndSwap(SERVICE_RUNNING, SERVICE_SHUTTING_DOWN) {
|
||||
return false
|
||||
}
|
||||
// Signal the service that we've transitioned to SERVICE_SHUTTING_DOWN.
|
||||
close(svm.shutdown)
|
||||
svm.shutdown = nil
|
||||
svm.wg.Wait()
|
||||
return true
|
||||
}
|
||||
|
||||
// Wait waits for the service to terminate if it's currently running.
|
||||
func (svm *ServiceManager) Wait() {
|
||||
svm.wg.Wait()
|
||||
}
|
||||
|
||||
// Join waits for the service to terminate and returns the value returned by the
|
||||
// service function.
|
||||
func (svm *ServiceManager) Join() error {
|
||||
svm.wg.Wait()
|
||||
return svm.err
|
||||
}
|
||||
|
||||
// State returns the current state of the service.
|
||||
// This should only be used to report the current state.
|
||||
func (svm *ServiceManager) State() int64 {
|
||||
return svm.state.Get()
|
||||
}
|
||||
|
||||
// StateName returns the name of the current state.
|
||||
func (svm *ServiceManager) StateName() string {
|
||||
return stateNames[svm.State()]
|
||||
}
|
||||
|
||||
// ServiceContext is passed into the service function to give it access to
|
||||
// information about the running service.
|
||||
type ServiceContext struct {
|
||||
// ShuttingDown is a channel that the service can select on to be notified
|
||||
// when it should shut down. The channel is closed when the state transitions
|
||||
// from SERVICE_RUNNING to SERVICE_SHUTTING_DOWN.
|
||||
ShuttingDown chan struct{}
|
||||
}
|
||||
|
||||
// IsRunning returns true if the ServiceContext.ShuttingDown channel has not
|
||||
// been closed yet.
|
||||
func (svc *ServiceContext) IsRunning() bool {
|
||||
select {
|
||||
case <-svc.ShuttingDown:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
28
vendor/github.com/ngaut/sync2/vitess_license
generated
vendored
Normal file
28
vendor/github.com/ngaut/sync2/vitess_license
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
Copyright 2012, Google Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
Loading…
Add table
Add a link
Reference in a new issue