about summary refs log tree commit diff stats
path: root/linux/308allocate-array.subx
blob: 5cc0fe1bdf1c7b4135f4424a4b2b11066e31e9f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 2-arg version of allocate-array.
# Really only intended to be called from code generated by mu.subx.

== code

allocate-array2:  # ad: (addr allocation-descriptor), array-len: int, elem-size: int, out: (addr handle array _)
    # . prologue
    55/push-ebp
    89/<- %ebp 4/r32/esp
    # . save registers
    50/push-eax
    52/push-edx
    #
    8b/-> *(ebp+0xc) 0/r32/eax
    f7 4/subop/multiply-into-edx-eax *(ebp+0x10)
    # TODO: check edx for overflow
    (allocate-array *(ebp+8) %eax *(ebp+0x14))
$allocate-array2:end:
    # . restore registers
    5a/pop-to-edx
    58/pop-to-eax
    # . epilogue
    89/<- %esp 5/r32/ebp
    5d/pop-to-ebp
    c3/return
0400 committer Ben Morrison <ben@gbmor.dev> 2019-06-06 01:23:44 -0400 moved initDatabase() to db.go' href='/gbmor/getwtxt/commit/svc/db.go?h=v0.4.11&id=439695f5521924833153852dc84040554e835f11'>439695f ^
439695f ^
1a15258 ^
439695f ^

1a15258 ^
c8fddff ^








1a15258 ^
c8fddff ^
e9d4a6b ^
c8fddff ^

e9d4a6b ^
c8fddff ^

1a15258 ^
c8fddff ^
c8fddff ^
e9d4a6b ^
c8fddff ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
                                                      

        

              


                                             




                      


                                         
                          


                                


                               
                                                         
                                 


                                      
                                 
 
         
 
                    
                

 
                     








                                                                   
                     
                      
                        

                    
                  

 
               
                      
                 
                    
 
package svc // import "github.com/getwtxt/getwtxt/svc"

import (
	"time"

	"github.com/syndtr/goleveldb/leveldb"
)

type dbase interface {
	push() error
	pull()
}

// Pull DB data into cache, if available.
func initDatabase() {
	var db dbase
	confObj.Mu.RLock()
	dbpath := confObj.DBPath
	confObj.Mu.RUnlock()

	switch confObj.DBType {

	case "leveldb":
		lvl, err := leveldb.OpenFile(dbpath, nil)
		errFatal("", err)
		db = &dbLevel{db: lvl}

	case "sqlite":
		db = initSqlite()

	}

	dbChan <- db
	pullDB()
}

func dbTimer() bool {
	confObj.Mu.RLock()
	answer := time.Since(confObj.LastPush) > confObj.DBInterval
	confObj.Mu.RUnlock()

	return answer
}

// Pushes the registry's cache data to a local
// database for safe keeping.
func pushDB() error {
	db := <-dbChan
	err := db.push()
	dbChan <- db

	return err
}

func pullDB() {
	db := <-dbChan
	db.pull()
	dbChan <- db
}