2023-08-01 16:56:58 +02:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2022-05-27 13:38:45 +02:00
|
|
|
// SPDX-FileCopyrightText: 2002-2006 Marcus Geelnard
|
2023-08-03 18:11:13 +02:00
|
|
|
// SPDX-FileCopyrightText: 2006-2017 Camilla Löwy <elmindreda@glfw.org>
|
2022-05-27 13:38:45 +02:00
|
|
|
// SPDX-FileCopyrightText: 2022 The Ebitengine Authors
|
2022-04-19 17:49:43 +02:00
|
|
|
|
2023-01-21 14:09:12 +01:00
|
|
|
package goglfw
|
2022-04-19 17:49:43 +02:00
|
|
|
|
|
|
|
func (t *tls) create() error {
|
2023-02-07 19:05:46 +01:00
|
|
|
if t.platform.allocated {
|
2023-01-21 14:09:12 +01:00
|
|
|
panic("goglfw: TLS must not be allocated")
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
i, err := _TlsAlloc()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
t.platform.index = i
|
|
|
|
t.platform.allocated = true
|
2022-04-19 17:49:43 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *tls) destroy() error {
|
2023-02-07 19:05:46 +01:00
|
|
|
if t.platform.allocated {
|
|
|
|
if err := _TlsFree(t.platform.index); err != nil {
|
2022-04-19 17:49:43 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2023-02-07 19:05:46 +01:00
|
|
|
t.platform.allocated = false
|
|
|
|
t.platform.index = 0
|
2022-04-19 17:49:43 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *tls) get() (uintptr, error) {
|
2023-02-07 19:05:46 +01:00
|
|
|
if !t.platform.allocated {
|
2023-01-21 14:09:12 +01:00
|
|
|
panic("goglfw: TLS must be allocated")
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
return _TlsGetValue(t.platform.index)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *tls) set(value uintptr) error {
|
2023-02-07 19:05:46 +01:00
|
|
|
if !t.platform.allocated {
|
2023-01-21 14:09:12 +01:00
|
|
|
panic("goglfw: TLS must be allocated")
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|
|
|
|
|
2023-02-07 19:05:46 +01:00
|
|
|
return _TlsSetValue(t.platform.index, value)
|
2022-04-19 17:49:43 +02:00
|
|
|
}
|